Oversized coordinate of the depth of the eye space with a fragmented shader

I'm trying to use the distance without scaling (the true distance from the foreground clipping plane) to the objects in my scene in the shader of the GLSL fragment. The value of gl_FragCoord.z ​​is less than what I expect. In my vertex shader, I just use ftransform () to set gl_Position. I see values ​​from 2 to 3 when I expect them to be between 15 and 20.

How can I get the real depth of the eye space? Thank!

+3
source share
1 answer

Pass everything you want as changing from the vertex shader.

Z, , z-near/z-far ( ) DepthRange. , . , OpenGL Z, , , , ( , ), , , .

Z, gl_ModelViewMatrix * gl_Vertex, Z , Z.

+4

Source: https://habr.com/ru/post/1742747/


All Articles