Ray-tracing, casting a ray per pixel

Hello, I’m currently building a ray-tracer and I’ve managed to put together intersection code, and the basic ray creation/camera but I’ve hit somewhat of a wall while trying to correctly cast a ray for each pixel on screen. My current code casts rays and it’ll detect all of the collisions but its also casting rays outside the visible (frustum?) Scene; Can someone point me in the right direction? I’ve not been able to find any real guides or suggestions on how to correctly set my ray directions per pixel on screen. thanks for any advice

This isn’t really an OpenGL question, unless you’re implementing this in OpenGL. Better to post this type of thing in the Math and Algorithms section in the future.

For each eye-ray, you need an origin point and a direction vector. The origin point is the eyepoint. The direction vector is a vector from the eye to (though) a specific point on the screen.

So define where your screen is relative to the eye in real-world units (e.g. N units down the -Z axis, from -A,A in X and -B,B in Y). Then figure how many pixels you’re stretching across that (-A,-B)->(A,B) region. With that, you know where the centers of your pixels are in real-world units. Shoot your rays through those.

[QUOTE=Dark Photon;1256628]This isn’t really an OpenGL question, unless you’re implementing this in OpenGL. Better to post this type of thing in the Math and Algorithms section in the future.

For each eye-ray, you need an origin point and a direction vector. The origin point is the eyepoint. The direction vector is a vector from the eye to (though) a specific point on the screen.

So define where your screen is relative to the eye in real-world units (e.g. N units down the -Z axis, from -A,A in X and -B,B in Y). Then figure how many pixels you’re stretching across that (-A,-B)->(A,B) region. With that, you know where the centers of your pixels are in real-world units. Shoot your rays through those.[/QUOTE]

Thanks for your reply, I am indeed implementing this in OpenGL, I’m attempting to make a real-time raytracer using OpenGL.