Original Post
This is going to make me look like a total idiot, for which I apologise. I should know this, but it's driving me crazy, so if this post does nothing more than fulfilling the universe's requirement for making me look stupid before having me realise the right answer, it'll have done its job.
I have a simple raymarcher implemented as a GLSL fragment shader. Currently the rays for each pixel are calculated thus:
That gives me a basic 90 degree FOV. What it also obviously does is distort the object the further from the centre it gets, and that is what I want to correct. In the fullness of time I need the raymarcher to use the same matrices as my geometry, but for now I'm just trying to understand the principles. I was surprised that most of the raymarcher/tracing tutorials I've found on Google make no mention of this problem, and if they do acknowledge it they just say "put up with it."
As the usual method of projection uses the z, I'm assuming that to get a similar effect I'm going to need to bend the rays as they're marching, which might end up a bit expensive if that's a mat mul per step (but presumably only the z will be affected, so that shouldn't happen).
So, firstly, how can I correct the above method (if it's possible), and secondly, how would I match the raymarcher to the actual worldviewproj?
I have a simple raymarcher implemented as a GLSL fragment shader. Currently the rays for each pixel are calculated thus:
vec2 position = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
position.y *= resolution.y / resolution.x;
vec3 target = vec3(position, 0.0);
vec3 eye = vec3(0., 0., -1.0);
vec3 ray = normalize(target - eye);That gives me a basic 90 degree FOV. What it also obviously does is distort the object the further from the centre it gets, and that is what I want to correct. In the fullness of time I need the raymarcher to use the same matrices as my geometry, but for now I'm just trying to understand the principles. I was surprised that most of the raymarcher/tracing tutorials I've found on Google make no mention of this problem, and if they do acknowledge it they just say "put up with it."
As the usual method of projection uses the z, I'm assuming that to get a similar effect I'm going to need to bend the rays as they're marching, which might end up a bit expensive if that's a mat mul per step (but presumably only the z will be affected, so that shouldn't happen).
So, firstly, how can I correct the above method (if it's possible), and secondly, how would I match the raymarcher to the actual worldviewproj?