Newsgroups: comp.graphics.api.opengl
From: Nobody <nob...@nowhere.com>
Date: Wed, 31 Oct 2012 22:23:49 +0000
Local: Wed, Oct 31 2012 6:23 pm
Subject: Re: 3D position to transformed depth value.
On Tue, 30 Oct 2012 23:56:30 +0000, VelociChicken wrote:
It's easier to just keep an unprojected copy, i.e. as well as:
>> Also, it's not linear, it's reciprocal; specifically: a+(b/z), where a and >> b are such that the near and far planes map to -1 and +1 respectively. > So I can't get the real distance to a point without 'unprojecting' it?
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
(or similar), add:
position = gl_ModelViewMatrix * gl_Vertex;
In theory, it's possible to reconstruct the latter from gl_FragCoord,
If you do want to reconstruct it from gl_FragCoord, gl_FragCoord.w is the
So, for the standard gluPerspective() matrix:
nx = 2 * (gl_FragCoord.x - viewport_x) / viewport_width - 1;
Note that zNear and zFar aren't relevant, as we're using gl_FragCoord.w
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||