2

I'm considering exploiting ray coherence in my software per-pixel realtime raycaster.

AFAICT, using a uniform grid, if I assign ray coherence to patches of say 4x4 pixels (where at present I have one raycast per pixel), given 16 parallel rays with different start (and end) point, how does this work out to a coherent scene? What I foresee is:

  1. There is a distance within which the ray march would be exactly the same for adjacent/similar rays. Within that distance, I am saving on processing. (How do I know what that distance is?)
  2. I will end up with a slightly to seriously incorrect image, due to the fact that some rays didn't diverge at the right times.

Given that my rays are cast from a single point rather than a plane, I guess I will need some sort of splitting function according to distance traversed, such that the set of all rays forms a tree as it move outward. My concern here is that finer detail will be lost when closer to the viewer.

I guess I'm just not grasping how this is meant to be used.

Engineer
  • 8,529
  • 7
  • 65
  • 105

1 Answers1

2

If done correctly, ray coherence shouldn't affect the final image. Because the rays are very close together, there's a good change that they'll all take similar paths when traversing the acceleration structure (kd-tree, aabb tree, etc). You have to go down each branch that any of the rays could hit, but hopefully this doesn't increase the number of branches much, and it saves on memory access.

The other advantage is that you can use SIMD (e.g. SSE) to accelerate some of your tests, both in the acceleration structure and against the triangles.

celion
  • 3,864
  • 25
  • 19
  • Is branching a given in ray-packet tracing, then, in order to alleviate the diversion of the rays at larger distances? A picture would paint a thousand words here. I wish I could find one. – Engineer Nov 09 '11 at 17:36
  • 1
    Can't find a picture, but Ingo Wald's PhD thesis (http://www.sci.utah.edu/~wald/Publications/2004///WaldPhD/download//phd.pdf) describes this in 7.2.3 SIMD Packet Traversal for kd-Trees. – celion Nov 09 '11 at 18:26
  • Yeah, Wald's paper's helped out some. What I get is that you cast the coherent rays in packets using SIMD via either SSE or the GPU. What I don't get is what happens when one of the rays hits. Does something branch? Or do the rest of the parallel rays just keep travelling till they stop too, at which point the whole SIMD operation terminates? And what's more -- if that's the case, why not just do SIMD on diverging rays -- the ray data being the "MD". – Engineer Nov 09 '11 at 21:41
  • The way I've done it in the past is to keep track of which rays are "active" by a bitfield; if a ray doesn't traverse the branch in the tree, clear its bit. You can stop traversing the current branch when none of the rays are active. When you reach a leaf, you can cast all of the rays, or just the active ones, whichever you think is faster (since the inactive ones shouldn't hit). The more coherent your rays are, the more likely they'll all pass through the same nodes in the tree and hit the same triangles, avoid extra data fetching. – celion Nov 09 '11 at 23:05