|
|
@@ -10,7 +10,7 @@ import { normalLocal } from '../../nodes/accessors/Normal.js';
|
|
|
import { instance } from '../../nodes/accessors/InstanceNode.js';
|
|
|
import { batch } from '../../nodes/accessors/BatchNode.js';
|
|
|
import { materialReference } from '../../nodes/accessors/MaterialReferenceNode.js';
|
|
|
-import { positionLocal } from '../../nodes/accessors/Position.js';
|
|
|
+import { positionLocal, positionView } from '../../nodes/accessors/Position.js';
|
|
|
import { skinningReference } from '../../nodes/accessors/SkinningNode.js';
|
|
|
import { morphReference } from '../../nodes/accessors/MorphNode.js';
|
|
|
import { lights } from '../../nodes/lighting/LightsNode.js';
|
|
|
@@ -19,8 +19,8 @@ import { float, vec3, vec4 } from '../../nodes/tsl/TSLBase.js';
|
|
|
import AONode from '../../nodes/lighting/AONode.js';
|
|
|
import { lightingContext } from '../../nodes/lighting/LightingContextNode.js';
|
|
|
import IrradianceNode from '../../nodes/lighting/IrradianceNode.js';
|
|
|
-import { depth } from '../../nodes/display/ViewportDepthNode.js';
|
|
|
-import { cameraLogDepth } from '../../nodes/accessors/Camera.js';
|
|
|
+import { depth, perspectiveDepthToLogarithmicDepth, viewZToOrthographicDepth } from '../../nodes/display/ViewportDepthNode.js';
|
|
|
+import { cameraFar, cameraNear } from '../../nodes/accessors/Camera.js';
|
|
|
import { clipping, clippingAlpha } from '../../nodes/accessors/ClippingNode.js';
|
|
|
import NodeMaterialObserver from './manager/NodeMaterialObserver.js';
|
|
|
|
|
|
@@ -215,7 +215,7 @@ class NodeMaterial extends Material {
|
|
|
|
|
|
setupDepth( builder ) {
|
|
|
|
|
|
- const { renderer } = builder;
|
|
|
+ const { renderer, camera } = builder;
|
|
|
|
|
|
// Depth
|
|
|
|
|
|
@@ -231,9 +231,21 @@ class NodeMaterial extends Material {
|
|
|
|
|
|
} else if ( renderer.logarithmicDepthBuffer === true ) {
|
|
|
|
|
|
- const fragDepth = modelViewProjection().w.add( 1 );
|
|
|
+ if ( camera.isPerspectiveCamera ) {
|
|
|
|
|
|
- depthNode = fragDepth.log2().mul( cameraLogDepth ).mul( 0.5 );
|
|
|
+ // Note: normally we could use "float( camera.near )" and "float( camera.far )" for the near/far arguments, but
|
|
|
+ // there is currently a bug with TSL/Three Shading Language whereby a "float()" expression using a huge value
|
|
|
+ // in scientific notation like "float( 1e27 )" will output "1e+27.0" to the shader code, which is causing problems.
|
|
|
+ // Since it's possible that camera.near/camera.far values may be using huge values like this (such as the logarithmic
|
|
|
+ // depth buffer examples on threejs.org), we must use the cameraNear/cameraFar nodes for now.
|
|
|
+ // TODO: can the float() node be fixed to allow for expressions like "float( 1e27 )"?
|
|
|
+ depthNode = perspectiveDepthToLogarithmicDepth( modelViewProjection().w, cameraNear, cameraFar );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ depthNode = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|