PDA

View Full Version : how to rendering bouding box for ray casting ?



Kal Mar
11-08-2010, 10:22 AM
Hi guys,

I having a problem, I write a shader for gpu raycasting, but, I dont now how exactly how to "render the bounding box of volume", will be the 8 faces of cube rendered ?, I am confused with a image plane.

Thanks

strattonbrazil
11-08-2010, 01:55 PM
Hey Kal,

First a box or cube typically has six sides. Basically you just have to draw some geometry on the screen, which will start the ray casting on the fragment shader. One method is to just draw a quad over your screen. A more efficient method is to just draw the three closest faces of the volume. This is the preferred way for me as I can do vertex interpolation in the vertex shader and know in world-position where the ray is pointing from my camera. Then just start marching.

Kal Mar
11-08-2010, 02:56 PM
I am sorry, (cube = six faces, eight vertex and...).

And how to render if I navigating into the volume, example, virtual colonoscopy ?

strattonbrazil
11-08-2010, 05:56 PM
If you go into the cube, then you have to have to use a near clipping plane instead of the closest faces. Then if any part of the plane is outside of the box, move the ray to start at the box.

Kal Mar
11-09-2010, 10:33 AM
Hi guys, sorry all

Somebody have any example o see good tutorial ?

I must to begin to work, doesn't speech.

skynet
11-09-2010, 11:03 AM
And how to render if I navigating into the volume, example, virtual colonoscopy ?
so-called "depth clamping" might help you here; read:
http://www.opengl.org/registry/specs/ARB/depth_clamp.txt

The idea is, that instead of opening up the cube due to clipping, the cube will still produce fragments at the clipped parts of the cube. Their depth value will be clamped to 0.0 which should help you to create correct rays.

Kal Mar
11-09-2010, 12:54 PM
My basic idea was,

At CPU
1.Compute the nearest vertex of bounding box and the farthest vertex for determine the maximum distance for the ray traversal.
2.Send the Min and Man values

At GPU
1.In the shader, I am recovering the position the camera, then I calculate the ray direction as

vec3 dir= camera.xyz gl_TexCoord[0].xyz;

and advance a positon along the ray.

2.Composite the final color


My problem is how to rendering the plane of image, I doing as,

glBegin(GL_QUADS);


glTexCoord2f(0.0, 0.0 );
glVertex2f(-1.0, -1.0);

glTexCoord2f(1.0, 0.0 );
glVertex2f(1.0, -1.0);

glTexCoord2f(1.0, 1.0 );
glVertex2f(1.0, 1.0);

glTexCoord2f(0.0, 1.0, );
glVertex2f(-1.0, 1.0) ;


glEnd();


but noting see a image.