|
@@ -42,21 +42,27 @@ vec2 unpackRGBATo2Half( vec4 v ) {
|
|
|
return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
|
|
|
}
|
|
|
|
|
|
-// NOTE: viewZ/eyeZ is < 0 when in front of the camera per OpenGL conventions
|
|
|
+// NOTE: viewZ, the z-coordinate in camera space, is negative for points in front of the camera
|
|
|
|
|
|
float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
|
|
|
+ // -near maps to 0; -far maps to 1
|
|
|
return ( viewZ + near ) / ( near - far );
|
|
|
}
|
|
|
-float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {
|
|
|
- return linearClipZ * ( near - far ) - near;
|
|
|
+
|
|
|
+float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
|
|
|
+ // maps orthographic depth in [ 0, 1 ] to viewZ
|
|
|
+ return depth * ( near - far ) - near;
|
|
|
}
|
|
|
|
|
|
// NOTE: https://twitter.com/gonnavis/status/1377183786949959682
|
|
|
|
|
|
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
|
|
|
+ // -near maps to 0; -far maps to 1
|
|
|
return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
|
|
|
}
|
|
|
-float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {
|
|
|
- return ( near * far ) / ( ( far - near ) * invClipZ - far );
|
|
|
+
|
|
|
+float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
|
|
|
+ // maps perspective depth in [ 0, 1 ] to viewZ
|
|
|
+ return ( near * far ) / ( ( far - near ) * depth - far );
|
|
|
}
|
|
|
`;
|