Josh Posted July 18, 2015 Share Posted July 18, 2015 This took a very long time to figure out. I finally found a formula in Igor's SSLR shader that helped, then I added the camera position to finish it off. This returns the position in world (global) space of the current pixel being rendered in a fragment shader: vec4 ScreenPositionToWorldPosition() { vec2 icoord = vec2(gl_FragCoord.xy/buffersize); if (isbackbuffer) icoord.y = 1.0f - icoord.y; float x = icoord.s * 2.0f - 1.0f; float y = icoord.t * 2.0f - 1.0f; float z = gl_FragCoord.z; vec4 posProj = vec4(x,y,z,1.0); vec4 posView = inverse(projectioncameramatrix) * posProj; posView /= posView.w; posView.xyz+=cameraposition; return posView; } 4 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
shadmar Posted July 19, 2015 Share Posted July 19, 2015 Yeah we worked hard on that one, but Igor cracked in the end Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Josh Posted July 19, 2015 Author Share Posted July 19, 2015 The division by the w coordinate is beyond my understanding, although I have seen that in a few other algorithms like this. I think that has to do with the projection matrix not using (0,0,0,1) for the right-hand column, which introduces shearing into the equation. I don't know enough about sheared matrices to be able to visualize it like I can an orthogonal matrix. Not just shearing, but the increasing scale of the volume as you move along the z axis...aughhhh! Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.