After using the project method for world point, the z is depth value?
Vector3 p
p.project()
p.z === gl_FragCoord.z ?
After using the project method for world point, the z is depth value?
Vector3 p
p.project()
p.z === gl_FragCoord.z ?
After you have projected a vector to NDC space via Vector3.project()
, you have to do this (assuming the depth range is [0,1]):
const depthValue = ( 0.5 * p.z ) + 0.5;
I have created two fiddles that show the calculation with Vector3
and Vector4
(which is normally used in the shaders).
Vector3: https://jsfiddle.net/f2Lommf5/15950/
Vector4: https://jsfiddle.net/f2Lommf5/15949/