Skip to main content
GameDev.net gamedev.net
🔒 Locked

Raymarcher perspective correction

Started by subi211 Sep 2, 2011 at 11:15 AM 4 replies 2.1k views
Original Post
subi211
subi211
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:


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?
subi211
subi211
I went back and re-read up on projection again and experimented a little, and it turns out the main reason that the problem has very little discussion is that the problem doesn't really exist. Although using an FoV of around 75 degrees rather than 90 helps a lot. See? Told you I was being stupid.
latent
latent

I went back and re-read up on projection again and experimented a little, and it turns out the main reason that the problem has very little discussion is that the problem doesn't really exist. Although using an FoV of around 75 degrees rather than 90 helps a lot. See? Told you I was being stupid.


You could always keep it at 90 degrees and call it a 'feature'
subi211
subi211
You could always keep it at 90 degrees and call it a 'feature'

Valve already offer you the choice between 75 and 90 and do just that.

undead
undead
Excuse me but I don't get the problem. Can somebody explain me?

In a standard raymarcher the FOV is just the camera FOV. Since you calulate a ray from the eye to each pixel in the near plane there is only one possble ray solving the equation. So the FOV is determined by your camera matrix.

Am I missing something?
subi211
subi211

Excuse me but I don't get the problem. Can somebody explain me?

There isn't a problem, I was just being an idiot. I was getting distortion near the edge of the screen, but that was because I had an FoV equivalent to my head being six inches from the monitor.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.