denormalizing depth values

131 views Asked by At

I currently use the following code in my fragment shader to display depth images. The values I get from this are normalized. I read them using readpixels. But I currently need the original values without normalizing. I can take the vertex positions I have and manually multiply with MVMatrix but is there a simpler way to extract it?

if (vIsDepth > 0.5)
        {
            float z = position_1.z;
            float n = 1.0;
            float f = 20.0;
            float ndcDepth = (2.0 * z - n - f)/(f - n); 

            float clipDepth = ndcDepth /position_1.w;
            float cr = ((clipDepth*0.5)+0.5);
            gl_FragColor = vec4(cr,cr,cr,1.0);
        }   
0

There are 0 answers