Skip to content

Commit 724117d

Browse files
committed
Temporary commit for debugging.
1 parent 956b4f6 commit 724117d

File tree

4 files changed

+16
-153
lines changed

4 files changed

+16
-153
lines changed

examples/jsm/postprocessing/GTAOPass.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ class GTAOPass extends Pass {
358358

359359
// render poisson denoise
360360

361-
this.pdMaterial.uniforms.cameraProjectionMatrixInverse.value.copy( this.camera.projectionMatrixInverse );
362-
this.renderPass( renderer, this.pdMaterial, this.pdRenderTarget, 0xffffff, 1.0 );
361+
//this.pdMaterial.uniforms.cameraProjectionMatrixInverse.value.copy( this.camera.projectionMatrixInverse );
362+
//this.renderPass( renderer, this.pdMaterial, this.pdRenderTarget, 0xffffff, 1.0 );
363363

364364
// output result to screen
365365

@@ -386,7 +386,7 @@ class GTAOPass extends Pass {
386386

387387
case GTAOPass.OUTPUT.Denoise:
388388

389-
this.copyMaterial.uniforms.tDiffuse.value = this.pdRenderTarget.texture;
389+
this.copyMaterial.uniforms.tDiffuse.value = this.gtaoRenderTarget.texture;
390390
this.copyMaterial.blending = NoBlending;
391391
this.renderPass( renderer, this.copyMaterial, this.renderToScreen ? null : writeBuffer );
392392

examples/jsm/shaders/GTAOShader.js

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -173,87 +173,17 @@ const GTAOShader = {
173173
discard;
174174
return;
175175
}
176-
vec3 viewPos = getViewPosition(vUv, depth);
177-
vec3 viewNormal = getViewNormal(vUv);
178-
179-
float radiusToUse = radius;
180-
float distanceFalloffToUse = thickness;
181-
#if SCREEN_SPACE_RADIUS == 1
182-
float radiusScale = getViewPosition(vec2(0.5 + float(SCREEN_SPACE_RADIUS_SCALE) / resolution.x, 0.0), depth).x;
183-
radiusToUse *= radiusScale;
184-
distanceFalloffToUse *= radiusScale;
185-
#endif
186-
187-
#if SCENE_CLIP_BOX == 1
188-
vec3 worldPos = (cameraWorldMatrix * vec4(viewPos, 1.0)).xyz;
189-
float boxDistance = length(max(vec3(0.0), max(sceneBoxMin - worldPos, worldPos - sceneBoxMax)));
190-
if (boxDistance > radiusToUse) {
191-
discard;
192-
return;
193-
}
194-
#endif
195-
196-
vec2 noiseResolution = vec2(textureSize(tNoise, 0));
197-
vec2 noiseUv = vUv * resolution / noiseResolution;
198-
vec4 noiseTexel = textureLod(tNoise, noiseUv, 0.0);
199-
vec3 randomVec = noiseTexel.xyz * 2.0 - 1.0;
200-
vec3 tangent = normalize(vec3(randomVec.xy, 0.));
201-
vec3 bitangent = vec3(-tangent.y, tangent.x, 0.);
202-
mat3 kernelMatrix = mat3(tangent, bitangent, vec3(0., 0., 1.));
203-
204-
const int DIRECTIONS = SAMPLES < 30 ? 3 : 5;
205-
const int STEPS = (SAMPLES + DIRECTIONS - 1) / DIRECTIONS;
206-
float ao = 0.0, totalWeight = 0.0;
207-
for (int i = 0; i < DIRECTIONS; ++i) {
208-
209-
float angle = float(i) / float(DIRECTIONS) * PI;
210-
vec4 sampleDir = vec4(cos(angle), sin(angle), 0., 0.5 + 0.5 * noiseTexel.w);
211-
sampleDir.xyz = normalize(kernelMatrix * sampleDir.xyz);
212-
213-
vec3 viewDir = normalize(-viewPos.xyz);
214-
vec3 sliceBitangent = normalize(cross(sampleDir.xyz, viewDir));
215-
vec3 sliceTangent = cross(sliceBitangent, viewDir);
216-
vec3 normalInSlice = normalize(viewNormal - sliceBitangent * dot(viewNormal, sliceBitangent));
217-
218-
vec3 tangentToNormalInSlice = cross(normalInSlice, sliceBitangent);
219-
vec2 cosHorizons = vec2(dot(viewDir, tangentToNormalInSlice), dot(viewDir, -tangentToNormalInSlice));
176+
177+
float ao = 0.0;
178+
for (int i = 0; i < 3; ++i) {
220179
221-
for (int j = 0; j < STEPS; ++j) {
222-
vec3 sampleViewOffset = sampleDir.xyz * radiusToUse * sampleDir.w * pow(float(j + 1) / float(STEPS), distanceExponent);
223-
224-
vec3 sampleSceneUvDepth = getSceneUvAndDepth(viewPos + sampleViewOffset);
225-
vec3 sampleSceneViewPos = getViewPosition(sampleSceneUvDepth.xy, sampleSceneUvDepth.z);
226-
vec3 viewDelta = sampleSceneViewPos - viewPos;
227-
if (abs(viewDelta.z) < thickness) {
228-
float sampleCosHorizon = dot(viewDir, normalize(viewDelta));
229-
cosHorizons.x += max(0., (sampleCosHorizon - cosHorizons.x) * mix(1., 2. / float(j + 2), distanceFallOff));
230-
}
231-
232-
sampleSceneUvDepth = getSceneUvAndDepth(viewPos - sampleViewOffset);
233-
sampleSceneViewPos = getViewPosition(sampleSceneUvDepth.xy, sampleSceneUvDepth.z);
234-
viewDelta = sampleSceneViewPos - viewPos;
235-
if (abs(viewDelta.z) < thickness) {
236-
float sampleCosHorizon = dot(viewDir, normalize(viewDelta));
237-
cosHorizons.y += max(0., (sampleCosHorizon - cosHorizons.y) * mix(1., 2. / float(j + 2), distanceFallOff));
238-
}
239-
}
240-
241-
vec2 sinHorizons = sqrt(1. - cosHorizons * cosHorizons);
242-
float nx = dot(normalInSlice, sliceTangent);
243-
float ny = dot(normalInSlice, viewDir);
244-
float nxb = 1. / 2. * (acos(cosHorizons.y) - acos(cosHorizons.x) + sinHorizons.x * cosHorizons.x - sinHorizons.y * cosHorizons.y);
245-
float nyb = 1. / 2. * (2. - cosHorizons.x * cosHorizons.x - cosHorizons.y * cosHorizons.y);
246-
float occlusion = nx * nxb + ny * nyb;
247-
ao += occlusion;
180+
float angle = float(i) / float(3) * PI;
181+
ao += cos(angle);
248182
}
249183
250-
ao = clamp(ao / float(DIRECTIONS), 0., 1.);
251-
#if SCENE_CLIP_BOX == 1
252-
ao = mix(ao, 1., smoothstep(0., radiusToUse, boxDistance));
253-
#endif
254-
ao = pow(ao, scale);
184+
ao = clamp(ao / float(3), 0., 1.);
255185
256-
gl_FragColor = FRAGMENT_OUTPUT;
186+
gl_FragColor = vec4(vec3(ao), 1.0);
257187
}`
258188

259189
};

examples/webgl_postprocessing_gtao.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
composer.addPass( gtaoPass );
9797

9898
const outputPass = new OutputPass();
99-
composer.addPass( outputPass );
99+
//composer.addPass( outputPass );
100100

101101
//
102102

@@ -111,7 +111,7 @@
111111
mixer.clipAction( gltf.animations[ 0 ] ).play();
112112

113113
const box = new THREE.Box3().setFromObject( scene );
114-
gtaoPass.setSceneClipBox( box );
114+
//gtaoPass.setSceneClipBox( box );
115115

116116
}, undefined, ( e ) => console.error( e ) );
117117

src/nodes/display/GTAONode.js

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -145,83 +145,16 @@ class GTAONode extends TempNode {
145145

146146
depth.greaterThanEqual( 1.0 ).discard();
147147

148-
const viewPosition = getViewPosition( uvNode, depth );
149-
const viewNormal = this.normalNode.rgb.normalize();
150-
151-
const radiusToUse = this.radius;
152-
153-
const noiseResolution = textureSize( this.noiseNode, 0 );
154-
let noiseUv = vec2( uvNode.x, uvNode.y.oneMinus() );
155-
noiseUv = noiseUv.mul( this.resolution.div( noiseResolution ) );
156-
const noiseTexel = sampleNoise( noiseUv );
157-
const randomVec = noiseTexel.xyz.mul( 2.0 ).sub( 1.0 );
158-
const tangent = vec3( randomVec.xy, 0.0 ).normalize();
159-
const bitangent = vec3( tangent.y.mul( - 1.0 ), tangent.x, 0.0 );
160-
const kernelMatrix = mat3( tangent, bitangent, vec3( 0.0, 0.0, 1.0 ) );
161-
162-
const DIRECTIONS = this.SAMPLES.lessThan( 30 ).cond( 3, 5 );
163-
const STEPS = add( this.SAMPLES, DIRECTIONS.sub( 1 ) ).div( DIRECTIONS );
164-
165148
let ao = float( 0 ).toVar();
166149

167-
loop( { start: int( 0 ), end: DIRECTIONS, type: 'int', condition: '<' }, ( { i } ) => {
168-
169-
const angle = float( i ).div( float( DIRECTIONS ) ).mul( PI );
170-
const sampleDir = vec4( cos( angle ), sin( angle ), 0., add( 0.5, mul( 0.5, noiseTexel.w ) ) );
171-
sampleDir.xyz = normalize( kernelMatrix.mul( sampleDir.xyz ) );
172-
173-
const viewDir = normalize( viewPosition.xyz.negate() );
174-
const sliceBitangent = normalize( cross( sampleDir.xyz, viewDir ) );
175-
const sliceTangent = cross( sliceBitangent, viewDir );
176-
const normalInSlice = normalize( viewNormal.sub( sliceBitangent.mul( dot( viewNormal, sliceBitangent ) ) ) );
177-
178-
const tangentToNormalInSlice = cross( normalInSlice, sliceBitangent );
179-
const cosHorizons = vec2( dot( viewDir, tangentToNormalInSlice ), dot( viewDir, tangentToNormalInSlice.negate() ) ).toVar();
180-
181-
loop( { end: STEPS, type: 'int', name: 'j', condition: '<' }, ( { j } ) => {
182-
183-
const sampleViewOffset = sampleDir.xyz.mul( radiusToUse ).mul( sampleDir.w ).mul( pow( div( float( j ).add( 1.0 ), float( STEPS ) ), this.distanceExponent ) );
184-
185-
// x
186-
187-
let sampleSceneUvDepth = getSceneUvAndDepth( viewPosition.add( sampleViewOffset ) );
188-
let sampleSceneViewPosition = getViewPosition( sampleSceneUvDepth.xy, sampleSceneUvDepth.z );
189-
let viewDelta = sampleSceneViewPosition.sub( viewPosition );
190-
191-
If( abs( viewDelta.z ).lessThan( this.thickness ), () => {
192-
193-
const sampleCosHorizon = viewDir.dot( viewDelta.normalize() );
194-
cosHorizons.x.addAssign( max( 0, mul( sampleCosHorizon.sub( cosHorizons.x ), mix( 1.0, float( 2.0 ).div( float( j ).add( 2 ) ), this.distanceFallOff ) ) ) );
195-
196-
} );
197-
198-
// y
199-
200-
sampleSceneUvDepth = getSceneUvAndDepth( viewPosition.sub( sampleViewOffset ) );
201-
sampleSceneViewPosition = getViewPosition( sampleSceneUvDepth.xy, sampleSceneUvDepth.z );
202-
viewDelta = sampleSceneViewPosition.sub( viewPosition );
203-
204-
If( abs( viewDelta.z ).lessThan( this.thickness ), () => {
205-
206-
const sampleCosHorizon = viewDir.dot( viewDelta.normalize() );
207-
cosHorizons.y.addAssign( max( 0, mul( sampleCosHorizon.sub( cosHorizons.y ), mix( 1.0, float( 2.0 ).div( float( j ).add( 2 ) ), this.distanceFallOff ) ) ) );
208-
209-
} );
210-
211-
} );
150+
loop( { start: int( 0 ), end: int( 3 ), type: 'int', condition: '<' }, ( { i } ) => {
212151

213-
const sinHorizons = sqrt( sub( 1.0, cosHorizons.mul( cosHorizons ) ) );
214-
const nx = dot( normalInSlice, sliceTangent );
215-
const ny = dot( normalInSlice, viewDir );
216-
const nxb = mul( 0.5, acos( cosHorizons.y ).sub( acos( cosHorizons.x ) ).add( sinHorizons.x.mul( cosHorizons.x ).sub( sinHorizons.y.mul( cosHorizons.y ) ) ) );
217-
const nyb = mul( 0.5, sub( 2.0, cosHorizons.x.mul( cosHorizons.x ) ).sub( cosHorizons.y.mul( cosHorizons.y ) ) );
218-
const occlusion = nx.mul( nxb ).add( ny.mul( nyb ) );
219-
ao.addAssign( occlusion );
152+
const angle = float( i ).div( float( 3 ) ).mul( PI );
153+
ao.addAssign( cos( angle ) );
220154

221155
} );
222156

223-
ao = clamp( ao.div( DIRECTIONS ), 0, 1 );
224-
ao = pow( ao, this.scale );
157+
ao = clamp( ao.div( 3 ), 0, 1 );
225158

226159
return vec4( vec3( ao ), 1.0 );
227160

0 commit comments

Comments
 (0)