Ray-Volume Intersection in OpenGL

1.3k views Asked by At

I am making a volume renderer. I have successfully read the volume and have few classes ready from my ray tracer. Now problem is how to do Ray and Volume (It's size is 256 * 256 * 256) intersection so as to find the coordinates 'intersectFront' and 'intersectBack'?

In my ray class, I am able to take origin and direction of the ray.

I tried to apply Liang Barsky Algorithm but unable to think of how to apply it for a box (cube/volume).

1

There are 1 answers

6
Jadh4v On

It appears that the algorithm that you are referring to, considers the clipping window to be axis aligned. In case of volume rendering, you may want to manipulate the orientation of the volume during visualization. This makes the cube non-axis aligned.

Also, it seems that you are doing ray casting on CPU and not in a openGL shader. In openGL shader, calculating the 'intersectFront' and intersectBack' points is very easy. You first render the bounding box of the volume two times into a texture. First rendering is for front faces and the second is for the back faces. The vertices of the bounding box are colored using the axis-aligned coordinates of the box. The two textures can then be overlapped to find the intersection ray in terms of the 3D texture coordinates. For more details, check this post: volume rendering (using glsl) with ray casting algorithm.

If you are doing this on CPU, your best bet is to transform the cube / bounding box back to make it axis-aligned along with the current ray. Then you can apply the mentioned Liang Barsky Algorithm using the extends of the box as x_min, x_max, y_min, y_max, z_min, z_max.