I am trying to implement deferred shading and have a problem with calculating vertex position(world/eye space) from depth buffer.
from the function describe in the document “Deferred rendering in leadwerk engine”
vec3 screencoord; screencoord = vec3(((gl_FragCoord.x/buffersize.x)-0.5) * 2.0,((-gl_FragCoord.y/buffersize.y)+0.5) * 2.0 / (buffersize.x/buffersize.y),DepthToZPosition( depth )); screencoord.x *= screencoord.z; screencoord.y *= -screencoord.z;
float DepthToZPosition(in float depth) { return camerarange.x / (camerarange.y - depth * (camerarange.y - camerarange.x)) * camerarange.y; }
the result of the function is vertex position in screen space.
Since i calculate lighting in world space . Is it possible to tranform the result to world space ?