• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Uniform grid traversal

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

### #1Pathering  Members

Posted 19 March 2014 - 09:49 AM

Hi everyone,

I wrote a simple ray tracer and I would like to improve it by creating grids. First, I want to create a uniform grid to accelerate the rendering. Right now, I have my triangles in my grid but I am stuck because I don't understand how to traverse it....

I found a tutorial which gives some code to traverse this kind of grid : http://www.clockworkcoders.com/oglsl/rt/gpurt3.htm.
I don't really understand so I am asking you some help.

I understand that I have to find the vessel where the ray is starting, but how can I know which is the next voxel ?

Posted 19 March 2014 - 10:04 AM

the ray starts to intersect a wall of a box and exists another wall of that box. Do some ray to plan intersection, determine if its the left up down etc wall, from there you know the next box this ray is going to go into.

### #3Pathering  Members

Posted 20 March 2014 - 07:35 AM

So, I have to compute an intersection of the ray with all the planes of the box ? and for all boxes the ray intersects ?

Posted 20 March 2014 - 01:50 PM

I don't know everything off the top of my head. I would assume you can get more detailed information if you search for ray tracing bsp uniform grid or something. That link doesn't look very helpful.

### #5spinningcube  Members

Posted 20 March 2014 - 02:16 PM

http://www.cse.yorku.ca/~amana/research/grid.pdf

Edited by jbadams, 13 April 2014 - 01:25 AM.
Restored post contents from history.

### #6Pathering  Members

Posted 21 March 2014 - 01:43 AM

Thanks for the link. I understand better the algorithm.

Edited by Pathering, 21 March 2014 - 01:43 AM.

### #7spinningcube  Members

Posted 21 March 2014 - 05:46 AM

Thanks for the link. I understand better the algorithm.

You're welcome. Me I think that the 3D DDA is very important but it's not that trivial to understand from a point of view of precision (when exactly to read/write into a not before visited cell) and a simple +- or rounding error wrong and your are a bit off. Sometime I wish floating point numbers were no more and we all went back to using fixed point math as floats are just so inaccurate, but that's another tangent :-)

Edited by jbadams, 15 April 2014 - 02:15 AM.
Restored post contents from history.

### #8Pathering  Members

Posted 23 March 2014 - 04:59 AM

One more question about the algorithm

In the paper it said :

Next, we determine the value of t at which the ray crosses the ﬁrst vertical voxel boundary and

store it in variable tMaxX. We perform a similar computation in y and store the result in tMaxY. The
minimum of these two values will indicate how much we can travel along the ray and still remain in the
current voxel

I think to intersect each plane of the grids (for X, Y and Z), but it seems greedy to compute. Is there a faster method ?

### #9Pathering  Members

Posted 23 March 2014 - 06:31 AM

I said anything...

I know the voxel where the ray starts. Also I know stepx, stepY and stepZ (1 if the ray coordinate is positive -1 otherwise).

Thanks to that I know the equation of my planes : for example if stepX is 1, the equation of my plane is P = minX (minX and maxX are my boundaries of the voxel for X), and if stepX is -1, the equation of my plane is P = maxX.

Same things for y and z.

Is it correct ?

### #10ProtectedMode  Members

Posted 23 March 2014 - 06:49 AM

Maybe it's an idea to write your code in such a way that you can later change it into using octrees. Because ray-tracing in sparse voxel octrees can even be done in real-time.

### #11Pathering  Members

Posted 23 March 2014 - 07:58 AM

What should I do to make my code for the uniform grid generic ?

### #12spinningcube  Members

Posted 23 March 2014 - 09:58 AM

Forget it. Future proofing code is the source of all procrastinations (trust me, I am fighting my instinct to do the "smart thing" every day :-) ). When you want to write your improved algo you will know better how to adapt and how to change it. No need to write a thesis about ray intersection abstraction or bit pattern matches. The code used in production renderers using octrees and sparse voxel octrees (whih I think are just a fad and so does John Carmack ;-) ) is so human unreadable that it hurts the eyes. It's layers of hack on hack of bit pattern shifts and masks that you won't know what is going on.

Long story short. Just implement what you have and think of speed and other data structures later.

Edited by jbadams, 15 April 2014 - 02:15 AM.
Restored post contents from history.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.