# Uniform grid traversal

This topic is 2040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 ?

##### Share on other sites

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.

##### Share on other sites

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

##### Share on other sites

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.

##### Share on other sites

Thanks for the link. I understand better the algorithm.

Edited by Pathering

##### Share on other sites

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 :-)

Restored post contents from history.

##### Share on other sites

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 ?

##### Share on other sites

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 ?

##### Share on other sites

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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!