|
|
@@ -1,5 +1,5 @@
|
|
|
import { DataTexture, RenderTarget, RepeatWrapping, Vector2, Vector3 } from 'three';
|
|
|
-import { getNormalFromDepth, getScreenPosition, getViewPosition, QuadMesh, TempNode, nodeObject, Fn, float, NodeUpdateType, uv, uniform, Loop, vec2, vec3, vec4, int, dot, max, pow, abs, If, textureSize, sin, cos, PI, texture, passTexture, mat3, add, normalize, mul, cross, div, mix, sqrt, sub, acos, clamp, NodeMaterial, PostProcessingUtils } from 'three/tsl';
|
|
|
+import { reference, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getNormalFromDepth, getScreenPosition, getViewPosition, QuadMesh, TempNode, nodeObject, Fn, float, NodeUpdateType, uv, uniform, Loop, vec2, vec3, vec4, int, dot, max, pow, abs, If, textureSize, sin, cos, PI, texture, passTexture, mat3, add, normalize, mul, cross, div, mix, sqrt, sub, acos, clamp, NodeMaterial, PostProcessingUtils } from 'three/tsl';
|
|
|
|
|
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
|
const _size = /*@__PURE__*/ new Vector2();
|
|
|
@@ -27,6 +27,9 @@ class GTAONode extends TempNode {
|
|
|
|
|
|
this.resolutionScale = 1;
|
|
|
|
|
|
+ this.cameraNear = reference( 'near', 'float', camera );
|
|
|
+ this.cameraFar = reference( 'far', 'float', camera );
|
|
|
+
|
|
|
this.radius = uniform( 0.25 );
|
|
|
this.resolution = uniform( new Vector2() );
|
|
|
this.thickness = uniform( 1 );
|
|
|
@@ -107,7 +110,22 @@ class GTAONode extends TempNode {
|
|
|
|
|
|
const uvNode = uv();
|
|
|
|
|
|
- const sampleDepth = ( uv ) => this.depthNode.uv( uv ).x;
|
|
|
+ const sampleDepth = ( uv ) => {
|
|
|
+
|
|
|
+ const depth = this.depthNode.uv( uv ).x;
|
|
|
+
|
|
|
+ if ( builder.renderer.logarithmicDepthBuffer === true ) {
|
|
|
+
|
|
|
+ const viewZ = logarithmicDepthToViewZ( depth, this.cameraNear, this.cameraFar );
|
|
|
+
|
|
|
+ return viewZToPerspectiveDepth( viewZ, this.cameraNear, this.cameraFar );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return depth;
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
const sampleNoise = ( uv ) => this._noiseNode.uv( uv );
|
|
|
const sampleNormal = ( uv ) => ( this.normalNode !== null ) ? this.normalNode.uv( uv ).rgb.normalize() : getNormalFromDepth( uv, this.depthNode.value, this._cameraProjectionMatrixInverse );
|
|
|
|