Jump to content
  • Advertisement
Sign in to follow this  

OpenGL ZBuffer to Worldspace Z Coordinate in the Shader GLSL

This topic is 566 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Took me a while in the past days, so to help others, I share the shader code

uniform sampler2D depthtex;
uniform float scr_x; // screen width
uniform float scr_y; // screen height
uniform float projectionmatrix_10; // projectionmatrix[10]
uniform float projectionmatrix_14; // projectionmatrix[14]
float zbuf = texture(depthtex, vec2(float(gl_FragCoord.x)/scr_x ,float(gl_FragCoord.y)/scr_y));
float a= projectionmatrix_10 ,b= projectionmatrix_14;
float realz = b / ( - (2.0*zbuf -1) - a );
a and b are as here
Edited by spacerat

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!