Original Post
How can i get the world coordinates in a GLSL pixel shader by using the depth value?
// Vertex shadervarying vec4 worldCoord;void main(void){ worldCoord = gl_ModelViewMatrix * gl_Vertex; ...}
Quote:
Original post by biggoron
Vary the world coordinates of your vertices?// Vertex shadervarying vec4 worldCoord;void main(void){ worldCoord = gl_ModelViewMatrix * gl_Vertex; ...}
Quote:
no... i want to get the world coordinate of each pixel
Quote:
Original post by biggoron Quote:
no... i want to get the world coordinate of each pixel
Guess what varying each vertex's world coordinate between its fragments does :)
Quote:
Original post by bzroom
You are correct in thinking you can reconstruct the world coordinates from screen position and depth (i actually clicked this thread with hopes of finding out how).
vec2 screen = (vec2(gl_FragCoord.x, gl_FragCoord.y) - viewport.xy) * viewport.zw;float depth = texture2D(DepthTexture, screen).x;vec4 world = vec4(screen, depth, 1.0) * IM;world.xyz /= world.w;Quote:
Original post by Yann L Quote:
Original post by bzroom
You are correct in thinking you can reconstruct the world coordinates from screen position and depth (i actually clicked this thread with hopes of finding out how).
There are several methods to do it. The main two ones are either by reverse raycasting or by simple matrix math.
Quote:
Original post by bzroom
Just to make sure, both of your methods will work with both the actual geometry, and reconstruction during a deferred pass correct?
Quote:
As long as your input matrices and viewport dimensions are for the correct view. In deferred this would be the view used to produce the G Buffer, and for forward shading it would just be the current view.
Quote:
Original post by bzroomagi_shi, thanks also, ..but that was a tuff post to follow.
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more