|
|
@@ -1,5 +1,5 @@
|
|
|
import Node from '../core/Node.js';
|
|
|
-import { float, log, log2, nodeImmutable, nodeProxy } from '../tsl/TSLBase.js';
|
|
|
+import { float, Fn, log, log2, nodeImmutable, nodeProxy } from '../tsl/TSLBase.js';
|
|
|
import { cameraNear, cameraFar } from '../accessors/Camera.js';
|
|
|
import { positionView } from '../accessors/Position.js';
|
|
|
import { viewportDepthTexture } from './ViewportDepthTextureNode.js';
|
|
|
@@ -86,7 +86,7 @@ class ViewportDepthNode extends Node {
|
|
|
|
|
|
if ( value !== null ) {
|
|
|
|
|
|
- node = depthBase().assign( value );
|
|
|
+ node = depthBase().assign( value );
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -152,6 +152,18 @@ export default ViewportDepthNode;
|
|
|
*/
|
|
|
export const viewZToOrthographicDepth = ( viewZ, near, far ) => viewZ.add( near ).div( near.sub( far ) );
|
|
|
|
|
|
+/**
|
|
|
+ * TSL function for converting a viewZ value to a reversed orthographic depth value.
|
|
|
+ *
|
|
|
+ * @tsl
|
|
|
+ * @function
|
|
|
+ * @param {Node<float>} viewZ - The viewZ node.
|
|
|
+ * @param {Node<float>} near - The camera's near value.
|
|
|
+ * @param {Node<float>} far - The camera's far value.
|
|
|
+ * @returns {Node<float>}
|
|
|
+ */
|
|
|
+export const viewZToReversedOrthographicDepth = ( viewZ, near, far ) => viewZ.add( far ).div( far.sub( near ) );
|
|
|
+
|
|
|
/**
|
|
|
* TSL function for converting an orthographic depth value to a viewZ value.
|
|
|
*
|
|
|
@@ -162,7 +174,19 @@ export const viewZToOrthographicDepth = ( viewZ, near, far ) => viewZ.add( near
|
|
|
* @param {Node<float>} far - The camera's far value.
|
|
|
* @returns {Node<float>}
|
|
|
*/
|
|
|
-export const orthographicDepthToViewZ = ( depth, near, far ) => near.sub( far ).mul( depth ).sub( near );
|
|
|
+export const orthographicDepthToViewZ = /*@__PURE__*/ Fn( ( [ depth, near, far ], builder ) => {
|
|
|
+
|
|
|
+ if ( builder.renderer.reversedDepthBuffer === true ) {
|
|
|
+
|
|
|
+ return far.sub( near ).mul( depth ).sub( far );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return near.sub( far ).mul( depth ).sub( near );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+} );
|
|
|
|
|
|
/**
|
|
|
* TSL function for converting a viewZ value to a perspective depth value.
|
|
|
@@ -200,7 +224,19 @@ export const viewZToReversedPerspectiveDepth = ( viewZ, near, far ) => near.mul(
|
|
|
* @param {Node<float>} far - The camera's far value.
|
|
|
* @returns {Node<float>}
|
|
|
*/
|
|
|
-export const perspectiveDepthToViewZ = ( depth, near, far ) => near.mul( far ).div( far.sub( near ).mul( depth ).sub( far ) );
|
|
|
+export const perspectiveDepthToViewZ = /*@__PURE__*/ Fn( ( [ depth, near, far ], builder ) => {
|
|
|
+
|
|
|
+ if ( builder.renderer.reversedDepthBuffer === true ) {
|
|
|
+
|
|
|
+ return near.mul( far ).div( near.sub( far ).mul( depth ).sub( near ) );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return near.mul( far ).div( far.sub( near ).mul( depth ).sub( far ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+} );
|
|
|
|
|
|
/**
|
|
|
* TSL function for converting a viewZ value to a logarithmic depth value.
|