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 2 of 2

Thread: RayTracing beginner question

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Jan 2012
    Posts
    81

    RayTracing beginner question

    Hello All,

    i just started some primitive ray-tracing today and in order to generate the primary rays(camera rays) i tried the following:

    Code :
    for (int i = 0; i < win_width; i++) {
       for (int j = 0; j < win_height; i++) {
          const double nearPlaneDis = 1.0;
                const double fovx = 60* M_PI;
                const double fovy = 60* M_PI; 
     
                const double valXAtNearPlane = tan(fovx / 2) * nearPlaneDis;
                const double valYAtNearPlane = tan(fovy / 2) * nearPlaneDis;
     
                double xx = ((i- win_width/ 2.0) / (win_width/ 2.0)) * valXAtNearPlane;
                double yy = (((win_height- j)  / 2.0) / (win_height/ 2.0)) * valYAtNearPlane;
     
                vec3 ray = glm::normalize(vec3(xx, yy, 1.0));
       }
    }

    Is this approach correct? I also saw another approach as follows:

    Code :
    i_inc = 2.0/(double)mWidth;
    j_inc = 2.0/(double)mHeight;
    pixel_y = 0;
    j = 1.0;
     
    for (; pixel_y < mHeight; j -= j_inc, pixel_y++) {
            pixel_x = 0;
            i = -1.0;
            for (; pixel_x < mWidth; i += i_inc, pixel_x++) {           
                vec3 ray = glm::normalize(vec3(i + (i_inc), j + (j_inc), 1.0));
             }
    }

    So, this above approach looked much simpler.

    Thus,
    (a) I used the camera space near plane values to obtain ray vectors.
    (b) But the other approach seemed to use the NDC coordinates to obtain the rays.

    I'm a little confused now as to which approach is correct, since the two are not yielding the exact rays.

    Could anyone please explain this? This is the first time i'm trying my hands on RayTracing.
    Thanks!

  2. #2
    Intern Contributor
    Join Date
    Jan 2012
    Posts
    81
    Anyone? should i post it in a separate section maybe? the Math/Algorithms section?

    Thanks!

Posting Permissions

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