0

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 Answers1

0

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.

Community
  • 1
  • 1
Jadh4v
  • 130
  • 3
  • Thanks for your Input. I'm doing it on CPU as of now. Now, suppose for a time being, I do not want to rotate the volume. I just wanted to see my volume (ray casted). I am not able to get how to transform it back and apply Liang Barsky. Just in my case consider everything to be static. Same size, no rotation, same position of the cube. – user3870357 Dec 30 '16 at 06:26
  • You won't need to do a reverse transformation if your cube is already axis aligned and static. Just compute the line equations and use the min and max values for each dimension to compute the intersection points. – Jadh4v Dec 30 '16 at 07:03
  • Or, to get even simpler, just use orthographic projection. i.e. your rays travel along the z-axis. But I won't generate a good perspective. Though, it would be a good starting point. – Jadh4v Dec 30 '16 at 07:06
  • I implemented the same as you said but not getting anything on the screen. Here is my code http://pastebin.com/VewEWH4Z – user3870357 Dec 31 '16 at 12:03
  • I see that you are passing the object Ray r in the intersect() function but you aren't using it. What line are you using for computing the clipping? You have to use the ray (that was calculated based on the perspective) to form two parametric equations. – Jadh4v Jan 02 '17 at 00:11
  • Say you have two the ray that is defined by two points (x_0,y_0) and (x_1, y_1). These points can be used to form two parametric equations as follows: x = x_0 + t(x_1 - x_0) y = y_0 + t(y_1 - y_0) This gives you the x_0, y_0, delta_x and delta_y values that you need for testing using the Liang-Barsky algorithm. – Jadh4v Jan 02 '17 at 00:15