Skip to main content
gamedev.net
🔒 Locked

Another ray tracing optimization

Started by phantomus Feb 21, 2005 at 12:07 PM 3 replies 1.1k views
Original Post
phantomus
phantomus
Here's another optimization idea to chew on. In a recent paper by Havran (and others) he explains a way to get a modest speedup by 'shaft culling'. In this paper he also points to an older paper, 'Ray Shooting using Longest Common Traversal Sequences'. I checked out that paper, and it's quite interesting. Basically, what he proposes is this: If you shoot two rays in the scene, and these rays both traverse the same nodes, then it is guaranteed that a ray that sits inbetween these rays is also traversing these nodes (in a kd-tree). More generally: If the first n nodes traversed by the two rays are equal, then the first n nodes can be skipped for rays between these two rays. It can be made more efficient by using a 'shaft': A pyramid shape, where you test the 4 corner rays. All nodes traversed by the four corner rays can be skipped by the interior rays. The disadvantage: detecting how many nodes are traversed by all rays is quite expensive. Besides, starting the interior rays half way is a nightmare, since they will still need the full traversal stack that the corner rays produced up to the point where they entered different nodes. Now that was 2000. It's 2005 now, and there's SIMD packet tracing. This opens interesting possibilities: Suppose we put the four corner rays in a packet. As long as the entire packet travels through the same nodes (something that is already being tested in Wald's version of the kd-tree traversal), we know that all interior rays could also start there. Nice twist compared to the 2000 paper is that we have the stack handy. So as soon as the packet is not coherent anymore (i.e., some rays are disabled while traversing), the interior rays are turned into packets, and traced from that point on. The advantage of this approach is that in general, many rays will just skip open space. They will simply start where the detail starts. And shafts consisting of 16 rays is only the beginning: Imagine that we skip the large open areas by casting 16x16 rays. As soon as this shaft is no longer coherent, it is split in 4 8x8 shafts. These are split later on in 4x4 shafts, and finally we have 2x2 rays in a single packet. This could seriously bring down the rendering times. One catch: The interior rays need near and far values. These need to be calculated once the interior rays are fired. And, the stack needs to be copied for these rays (but that's just a few bytes). I still have to try this, and I do some other potential problems, but it sure looks nice. :) - Jacco.
Eelco
Eelco
sounds interesting.

i certainly lack the insight to see if the added complexity will not somehow degrade performance, but the principle of it is pretty clever i think.

as with any method that relies on ray coherency though, its only usefull for primairy rays (area lights / soft shadows maybe? they require a lot of coherent rays), under limited circumstances. this relies even more on coherency than packets, and even worse: due to the complexity, probably even brings performance down in case there is no coherency, thereby making worst case performance only worse.
davepermen
davepermen
this would be sort of the way subsampling works, just, in this case, not with some heuristic that estimates wether or not we want to "divide and conquer", but you'd get an accurate image even. but the openspace traversal you did with only in best case 4 rays for the whole screen..

or so.. :D
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
tbp
tbp
See Jacco, i'm not the only one to see a correlation between that and sub-sampling.

Eelco
Eelco
i just read havrans paper, and he makes a good point about AA. especially scenes with high coherency benefit, and if you do high AA, coherency will go up quite a bit.

still, havran reports a worst speedup of 1.1
i wonder what would happen if he really made an effort to throw an even less compliant scene at it, since he didnt use that many in his paper. would it go below 1?

btw, i just realized a scenario where this while thing will lose its accuracy. a kd-tree that allows fast affine transformations has two layers: a dynamic one with OBB's in its leafs, containing static trees. four shaft rays could each pass trough the same leaf, but all miss the obb on another side, thus completely missing the object located there. you can probably come up with some workaround for that though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.