@gnsx/three 0.185.11 → 0.185.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataTexture, RenderTarget, RepeatWrapping, Vector2, Vector3, TempNode, QuadMesh, NodeMaterial, RendererUtils, RedFormat } from '@gnsx/three/webgpu';
|
|
2
|
-
import { reference, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getNormalFromDepth, getScreenPosition, getViewPosition, 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, acos, clamp } from '@gnsx/three/tsl';
|
|
2
|
+
import { reference, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getNormalFromDepth, getScreenPosition, getViewPosition, nodeObject, Fn, float, NodeUpdateType, uv, uniform, Loop, vec2, vec3, vec4, int, dot, max, min, pow, abs, If, textureSize, sin, cos, PI, texture, passTexture, mat3, add, normalize, mul, cross, div, mix, acos, clamp } from '@gnsx/three/tsl';
|
|
3
3
|
|
|
4
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
5
|
const _size = /*@__PURE__*/ new Vector2();
|
|
@@ -70,6 +70,18 @@ class GTAONode extends TempNode {
|
|
|
70
70
|
*/
|
|
71
71
|
this.normalNode = normalNode;
|
|
72
72
|
|
|
73
|
+
// WITH_GENESYS
|
|
74
|
+
/**
|
|
75
|
+
* Optional node that marks pixels where GTAO should run. This is sampled only
|
|
76
|
+
* for the center pixel, allowing neighbor depth taps to use the raw depth
|
|
77
|
+
* texture without repeating an auxiliary validity texture fetch.
|
|
78
|
+
*
|
|
79
|
+
* @type {?Node<float>}
|
|
80
|
+
* @default null
|
|
81
|
+
*/
|
|
82
|
+
this.validityNode = null;
|
|
83
|
+
// !WITH_GENESYS
|
|
84
|
+
|
|
73
85
|
/**
|
|
74
86
|
* The resolution scale. By default the effect is rendered in full resolution
|
|
75
87
|
* for best quality but a value of `0.5` should be sufficient for most scenes.
|
|
@@ -106,6 +118,18 @@ class GTAONode extends TempNode {
|
|
|
106
118
|
*/
|
|
107
119
|
this.radius = uniform( 0.25 );
|
|
108
120
|
|
|
121
|
+
// WITH_GENESYS
|
|
122
|
+
/**
|
|
123
|
+
* Maximum screen-space radius in pixels. Clamps the projected world-space
|
|
124
|
+
* radius when the camera is close to surfaces so sample UVs stay local and
|
|
125
|
+
* avoid texture-cache thrashing (Activision GTAO guidance).
|
|
126
|
+
*
|
|
127
|
+
* @type {UniformNode<float>}
|
|
128
|
+
* @default 64
|
|
129
|
+
*/
|
|
130
|
+
this.maxScreenRadius = uniform( 64 );
|
|
131
|
+
// !WITH_GENESYS
|
|
132
|
+
|
|
109
133
|
/**
|
|
110
134
|
* The resolution of the effect. Can be scaled via
|
|
111
135
|
* `resolutionScale`.
|
|
@@ -343,12 +367,30 @@ class GTAONode extends TempNode {
|
|
|
343
367
|
|
|
344
368
|
const depth = sampleDepth( uvNode ).toVar();
|
|
345
369
|
|
|
370
|
+
// WITH_GENESYS
|
|
371
|
+
if ( this.validityNode !== null ) {
|
|
372
|
+
|
|
373
|
+
this.validityNode.sample( uvNode ).lessThan( 0.5 ).discard();
|
|
374
|
+
|
|
375
|
+
}
|
|
376
|
+
// !WITH_GENESYS
|
|
377
|
+
|
|
346
378
|
depth.greaterThanEqual( 1.0 ).discard();
|
|
347
379
|
|
|
348
380
|
const viewPosition = getViewPosition( uvNode, depth, this._cameraProjectionMatrixInverse ).toVar();
|
|
349
381
|
const viewNormal = sampleNormal( uvNode ).toVar();
|
|
350
382
|
|
|
351
|
-
|
|
383
|
+
// WITH_GENESYS
|
|
384
|
+
// Clamp world radius so its screen footprint never exceeds maxScreenRadius
|
|
385
|
+
// pixels. Without this, near-camera surfaces project a huge UV stride and
|
|
386
|
+
// the depth/normal taps thrash the texture cache.
|
|
387
|
+
const probeScreen = getScreenPosition( viewPosition.add( vec3( this.radius, 0.0, 0.0 ) ), this._cameraProjectionMatrix );
|
|
388
|
+
const centerScreen = getScreenPosition( viewPosition, this._cameraProjectionMatrix );
|
|
389
|
+
const screenRadiusPx = abs( probeScreen.x.sub( centerScreen.x ) ).mul( this.resolution.x );
|
|
390
|
+
const radiusScale = min( float( 1.0 ), this.maxScreenRadius.div( max( screenRadiusPx, float( 1e-4 ) ) ) );
|
|
391
|
+
const radiusToUse = this.radius.mul( radiusScale );
|
|
392
|
+
// !WITH_GENESYS
|
|
393
|
+
// const radiusToUse = this.radius;
|
|
352
394
|
|
|
353
395
|
const noiseResolution = textureSize( this._noiseNode, 0 );
|
|
354
396
|
let noiseUv = vec2( uvNode.x, uvNode.y.oneMinus() );
|
|
@@ -360,8 +402,16 @@ class GTAONode extends TempNode {
|
|
|
360
402
|
const bitangent = vec3( tangent.y.mul( - 1.0 ), tangent.x, 0.0 );
|
|
361
403
|
const kernelMatrix = mat3( tangent, bitangent, vec3( 0.0, 0.0, 1.0 ) );
|
|
362
404
|
|
|
363
|
-
|
|
364
|
-
|
|
405
|
+
// WITH_GENESYS
|
|
406
|
+
// A clamped radius covers less screen space, so proportionally reduce the
|
|
407
|
+
// sample budget as well. Keeping all samples only changes tap locality and
|
|
408
|
+
// does not address the near-camera shader cost.
|
|
409
|
+
const samplesToUse = min( this.samples, max( float( 6 ), this.samples.mul( radiusScale ) ) ).toVar();
|
|
410
|
+
const DIRECTIONS = samplesToUse.lessThan( 30 ).select( 3, 5 ).toVar();
|
|
411
|
+
const STEPS = add( samplesToUse, DIRECTIONS.sub( 1 ) ).div( DIRECTIONS ).toVar();
|
|
412
|
+
// !WITH_GENESYS
|
|
413
|
+
// const DIRECTIONS = this.samples.lessThan( 30 ).select( 3, 5 ).toVar();
|
|
414
|
+
// const STEPS = add( this.samples, DIRECTIONS.sub( 1 ) ).div( DIRECTIONS ).toVar();
|
|
365
415
|
|
|
366
416
|
const ao = float( 0 ).toVar();
|
|
367
417
|
|