|
@@ -21,7 +21,7 @@ class ViewportDepthNode extends Node {
|
|
|
|
|
|
const { scope } = this;
|
|
|
|
|
|
- if ( scope === ViewportDepthNode.DEPTH_PIXEL ) {
|
|
|
+ if ( scope === ViewportDepthNode.DEPTH ) {
|
|
|
|
|
|
return builder.getFragDepth();
|
|
|
|
|
@@ -31,28 +31,52 @@ class ViewportDepthNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
- setup( /*builder*/ ) {
|
|
|
+ setup( { camera } ) {
|
|
|
|
|
|
const { scope } = this;
|
|
|
+ const texture = this.valueNode;
|
|
|
|
|
|
let node = null;
|
|
|
|
|
|
if ( scope === ViewportDepthNode.DEPTH ) {
|
|
|
|
|
|
- node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar );
|
|
|
+ if ( texture !== null ) {
|
|
|
+
|
|
|
+ node = depthBase().assign( texture );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if ( camera.isPerspectiveCamera ) {
|
|
|
+
|
|
|
+ node = viewZToPerspectiveDepth( positionView.z, cameraNear, cameraFar );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ( scope === ViewportDepthNode.LINEAR_DEPTH ) {
|
|
|
+
|
|
|
+ if ( texture !== null ) {
|
|
|
+
|
|
|
+ if ( camera.isPerspectiveCamera ) {
|
|
|
+
|
|
|
+ const viewZ = perspectiveDepthToViewZ( texture, cameraNear, cameraFar );
|
|
|
|
|
|
- } else if ( scope === ViewportDepthNode.DEPTH_TEXTURE ) {
|
|
|
+ node = viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );
|
|
|
|
|
|
- const texture = this.valueNode || viewportDepthTexture();
|
|
|
+ } else {
|
|
|
|
|
|
- const viewZ = perspectiveDepthToViewZ( texture, cameraNear, cameraFar );
|
|
|
- node = viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );
|
|
|
+ node = texture;
|
|
|
|
|
|
- } else if ( scope === ViewportDepthNode.DEPTH_PIXEL ) {
|
|
|
+ }
|
|
|
|
|
|
- if ( this.valueNode !== null ) {
|
|
|
+ } else {
|
|
|
|
|
|
- node = depthPixelBase().assign( this.valueNode );
|
|
|
+ node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -81,17 +105,16 @@ export const viewZToPerspectiveDepth = ( viewZ, near, far ) => near.add( viewZ )
|
|
|
export const perspectiveDepthToViewZ = ( depth, near, far ) => near.mul( far ).div( far.sub( near ).mul( depth ).sub( far ) );
|
|
|
|
|
|
ViewportDepthNode.DEPTH = 'depth';
|
|
|
-ViewportDepthNode.DEPTH_TEXTURE = 'depthTexture';
|
|
|
-ViewportDepthNode.DEPTH_PIXEL = 'depthPixel';
|
|
|
+ViewportDepthNode.LINEAR_DEPTH = 'linearDepth';
|
|
|
|
|
|
export default ViewportDepthNode;
|
|
|
|
|
|
-const depthPixelBase = nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH_PIXEL );
|
|
|
+const depthBase = nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH );
|
|
|
|
|
|
export const depth = nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH );
|
|
|
-export const depthTexture = nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH_TEXTURE );
|
|
|
-export const depthPixel = nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH_PIXEL );
|
|
|
+export const linearDepth = nodeProxy( ViewportDepthNode, ViewportDepthNode.LINEAR_DEPTH );
|
|
|
+export const viewportLinearDepth = linearDepth( viewportDepthTexture() );
|
|
|
|
|
|
-depthPixel.assign = ( value ) => depthPixelBase( value );
|
|
|
+depth.assign = ( value ) => depthBase( value );
|
|
|
|
|
|
addNodeClass( 'ViewportDepthNode', ViewportDepthNode );
|