Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Help with ray casting - near plane

  1. #1
    Intern Newbie
    Join Date
    Sep 2010
    Posts
    36

    Help with ray casting - near plane

    Hi guys

    I implementing the ray casting algorithm but I have a great trouble.

    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 do 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();

    - My view port is 512x512

    but noting see a image, and how to rendering if the case will be a endoscopy, by ex. (the near plane) ?


    Thanks

  2. #2
    Member Regular Contributor strattonbrazil's Avatar
    Join Date
    Jun 2007
    Location
    Los Angeles, CA
    Posts
    306

    Re: Help with ray casting - near plane

    One option is not to use texture coordinates. If you just draw a quad over the entire screen, that will get you into the fragment program. There you need to have a camera position set from the CPU. You can then use the gl_FragCoord, what pixel you are at, to determine the direction of the ray. Then you just intersection the box inside your fragment shader.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Nov 2007
    Location
    London UK
    Posts
    242

    Re: Help with ray casting - near plane

    You could try this method.
    Worked for me.

    a|x

  4. #4
    Intern Newbie
    Join Date
    Sep 2010
    Posts
    36

    Re: Help with ray casting - near plane

    Hi Toneburst

    I read a Peters tutorial and tried to follow the process. I am working with glsl and create the texture2D as buffer for the final imagen rendered.
    I estimate the first sample with gl_TexCoord[0].xyz, and calculate the direction of ray as
    direction = normalize(gl_TexCoord[0].xyz-camera.xyz);
    The algorithm is similar as Real Time Volume Graphics.

    Next, calling a function
    render_buffer_to_screen(); //with square and texture2d coordinates

    for show the result, I see one square (red blurred ), when i move a camera position, it behaves as one slice.

    I would expect that the texture2D (frame buffer) behaves as image2D, such is updated by moving the camera.

    What can I do ?

    Thanks

  5. #5
    Intern Newbie
    Join Date
    Sep 2010
    Posts
    36

    Re: Help with ray casting - near plane

    Thanks all

    All is result.

    OPENGL and GLSL, the perfect combination: easy to do ray casting, without any buffer, only rendering the front faces of cube.

  6. #6
    Junior Member Regular Contributor pjcozzi's Avatar
    Join Date
    Jun 2004
    Location
    Philadelphia, PA
    Posts
    196

    Re: Help with ray casting - near plane

    Quote Originally Posted by Kal Mar
    OPENGL and GLSL, the perfect combination: easy to do ray casting, without any buffer, only rendering the front faces of cube.
    Consider rendering only the back faces of the cube. When only the front faces are rendered, no fragments (and thus no rays) are generated when the viewer enters the cube.

    Regards,
    Patrick

  7. #7
    Junior Member Regular Contributor
    Join Date
    Nov 2007
    Location
    London UK
    Posts
    242

    Re: Help with ray casting - near plane

    I found I didn't need to render front faces, either. I simple applied the raycasting shader to the front cube, passing a varying representing the interpolated screenspace coordinates from Vertex to Fragment shader, and using the previously-rendered back faces texture as ray end positions.

    a|x

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •