myk45

11-25-2012, 12:29 PM

Hello All,

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

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:

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!

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

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:

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!