When using material.useLogarithmicDepth = true;
with a PBR material, I’ve found the way depth is calculated in both the vertex shader and fragment shader.
I’m not quite sure why it’s necessary to recalculate the depth in the fragment shader, and why the calculation methods are different.
In Vertex:
vFragmentDepth=1.0+gl_Position.w;
gl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;
In Fragment:
gl_FragDepth=log2(vFragmentDepth) * logarithmicDepthConstant * 0.5;
If I use my own depth calculation method, I’m not sure how to modify it in the fragment shader.
In Vertex:
float v_depth=(1.0/log2(nearFar.y-nearFar.x+1.0))*log2((0.5 * (gl_Position.z /gl_Position.w) + 0.5) * gl_Position.w+1.0);
float tempz = (gl_Position.w+gl_Position.w)*v_depth-gl_Position.w;
gl_Position.z=tempz;
In Fragment:
I don’t konw what I can do?