Hi I was wondering: in a shader I’m writing I’m assuming that the ‘ray’ that I construct from the camera to to the fragment starts at 0,0,0 and goes trough the eyespace position of the fragment. Seems to work as I expected, but is this really correct?
I was starting to doubt when I remembered that you also can set up orthogonal projections. How does that work then? seems incorrect to assume that all rays originate at (0,0,0) then, because to me it seems the rays should be parallel to each other… or is the scene transformed in such a way that is still works? can’t seem to wrap my head around it

I hope I make myself clear, or else just ask and I’ll try to explain it more!

Right. Eyepoint is a perspective concept. With orthogonal, you still transform to eye-space as usual (an orthonormal space), but then instead of applying a projection which converges to a point in space (the eyepoint), your projection is a 3D box (more correctly, a rectangular parallelepiped). You clip to that box and smash it directly onto the screen. Your eye/camera is effectively a plane rather than a point in space.

This is the same as the difference between a point light source and a directional light source. You’re just tracing rays in the opposite direction.

[QUOTE=Dark Photon;1248242]Right. Eyepoint is a perspective concept. With orthogonal, you still transform to eye-space as usual (an orthonormal space), but then instead of applying a projection which converges to a point in space (the eyepoint), your projection is a 3D box (more correctly, a rectangular parallelepiped). You clip to that box and smash it directly onto the screen. Your eye/camera is effectively a plane rather than a point in space.

This is the same as the difference between a point light source and a directional light source. You’re just tracing rays in the opposite direction.[/QUOTE]

Thanks, this is very clear, now my next question would be, how would you find the point of origin of a camera ray in orthogonal projection? I assume you’d have to use the gl_FragCoord somehow???

From the fragment shader? You have to reverse-transform gl_FragCoord from window-space to clip-space. But since you’re using an orthographic projection, this is much easier.

The first change is don’t bother dividing by gl_FragCoord.w. That should be 1.0, so NDC space is the same as clip-space.

The second change is to modify your clip-space position before transforming it back into eye-space. Take clipPos.z and set it equal to -1.0. That should be the near-plane. Then continue on. So your shader code would look like: