Skip to content

Commit 7603c0b

Browse files
authored
Merge pull request #20451 from Mugen87/dev51
SSAOPass: Exclude point clouds and lines.
2 parents eccad97 + 94339bc commit 7603c0b

File tree

2 files changed

+84
-20
lines changed

2 files changed

+84
-20
lines changed

examples/js/postprocessing/SSAOPass.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
console.warn( "THREE.SSAOPass: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
22

3+
var _cache = new Map();
4+
35
THREE.SSAOPass = function ( scene, camera, width, height ) {
46

57
THREE.Pass.call( this );
@@ -26,7 +28,7 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
2628
this.generateSampleKernel();
2729
this.generateRandomKernelRotations();
2830

29-
// beauty render target with depth buffer
31+
// beauty render target
3032

3133
var depthTexture = new THREE.DepthTexture();
3234
depthTexture.type = THREE.UnsignedShortType;
@@ -36,17 +38,16 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
3638
this.beautyRenderTarget = new THREE.WebGLRenderTarget( this.width, this.height, {
3739
minFilter: THREE.LinearFilter,
3840
magFilter: THREE.LinearFilter,
39-
format: THREE.RGBAFormat,
40-
depthTexture: depthTexture,
41-
depthBuffer: true
41+
format: THREE.RGBAFormat
4242
} );
4343

44-
// normal render target
44+
// normal render target with depth buffer
4545

4646
this.normalRenderTarget = new THREE.WebGLRenderTarget( this.width, this.height, {
4747
minFilter: THREE.NearestFilter,
4848
magFilter: THREE.NearestFilter,
49-
format: THREE.RGBAFormat
49+
format: THREE.RGBAFormat,
50+
depthTexture: depthTexture
5051
} );
5152

5253
// ssao render target
@@ -77,7 +78,7 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
7778

7879
this.ssaoMaterial.uniforms[ 'tDiffuse' ].value = this.beautyRenderTarget.texture;
7980
this.ssaoMaterial.uniforms[ 'tNormal' ].value = this.normalRenderTarget.texture;
80-
this.ssaoMaterial.uniforms[ 'tDepth' ].value = this.beautyRenderTarget.depthTexture;
81+
this.ssaoMaterial.uniforms[ 'tDepth' ].value = this.normalRenderTarget.depthTexture;
8182
this.ssaoMaterial.uniforms[ 'tNoise' ].value = this.noiseTexture;
8283
this.ssaoMaterial.uniforms[ 'kernel' ].value = this.kernel;
8384
this.ssaoMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
@@ -111,7 +112,7 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
111112
fragmentShader: THREE.SSAODepthShader.fragmentShader,
112113
blending: THREE.NoBlending
113114
} );
114-
this.depthRenderMaterial.uniforms[ 'tDepth' ].value = this.beautyRenderTarget.depthTexture;
115+
this.depthRenderMaterial.uniforms[ 'tDepth' ].value = this.normalRenderTarget.depthTexture;
115116
this.depthRenderMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
116117
this.depthRenderMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
117118

@@ -166,15 +167,17 @@ THREE.SSAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
166167

167168
render: function ( renderer, writeBuffer /*, readBuffer, deltaTime, maskActive */ ) {
168169

169-
// render beauty and depth
170+
// render beauty
170171

171172
renderer.setRenderTarget( this.beautyRenderTarget );
172173
renderer.clear();
173174
renderer.render( this.scene, this.camera );
174175

175-
// render normals
176+
// render normals and depth (honor only meshes, points and lines do not contribute to SSAO)
176177

178+
this.overrideVisibility();
177179
this.renderOverride( renderer, this.normalMaterial, this.normalRenderTarget, 0x7777ff, 1.0 );
180+
this.restoreVisibility();
178181

179182
// render SSAO
180183

@@ -387,6 +390,35 @@ THREE.SSAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
387390
this.noiseTexture.wrapS = THREE.RepeatWrapping;
388391
this.noiseTexture.wrapT = THREE.RepeatWrapping;
389392

393+
},
394+
395+
overrideVisibility: function () {
396+
397+
var scene = this.scene;
398+
399+
scene.traverse( function ( object ) {
400+
401+
_cache.set( object, object.visible );
402+
403+
if ( object.isPoints || object.isLine ) object.visible = false;
404+
405+
} );
406+
407+
},
408+
409+
restoreVisibility: function () {
410+
411+
var scene = this.scene;
412+
413+
scene.traverse( function ( object ) {
414+
415+
var visible = _cache.get( object );
416+
object.visible = visible;
417+
418+
} );
419+
420+
_cache.clear();
421+
390422
}
391423

392424
} );

examples/jsm/postprocessing/SSAOPass.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { SSAOBlurShader } from "../shaders/SSAOShader.js";
2828
import { SSAODepthShader } from "../shaders/SSAOShader.js";
2929
import { CopyShader } from "../shaders/CopyShader.js";
3030

31+
var _cache = new Map();
32+
3133
var SSAOPass = function ( scene, camera, width, height ) {
3234

3335
Pass.call( this );
@@ -54,7 +56,7 @@ var SSAOPass = function ( scene, camera, width, height ) {
5456
this.generateSampleKernel();
5557
this.generateRandomKernelRotations();
5658

57-
// beauty render target with depth buffer
59+
// beauty render target
5860

5961
var depthTexture = new DepthTexture();
6062
depthTexture.type = UnsignedShortType;
@@ -64,17 +66,16 @@ var SSAOPass = function ( scene, camera, width, height ) {
6466
this.beautyRenderTarget = new WebGLRenderTarget( this.width, this.height, {
6567
minFilter: LinearFilter,
6668
magFilter: LinearFilter,
67-
format: RGBAFormat,
68-
depthTexture: depthTexture,
69-
depthBuffer: true
69+
format: RGBAFormat
7070
} );
7171

72-
// normal render target
72+
// normal render target with depth buffer
7373

7474
this.normalRenderTarget = new WebGLRenderTarget( this.width, this.height, {
7575
minFilter: NearestFilter,
7676
magFilter: NearestFilter,
77-
format: RGBAFormat
77+
format: RGBAFormat,
78+
depthTexture: depthTexture
7879
} );
7980

8081
// ssao render target
@@ -105,7 +106,7 @@ var SSAOPass = function ( scene, camera, width, height ) {
105106

106107
this.ssaoMaterial.uniforms[ 'tDiffuse' ].value = this.beautyRenderTarget.texture;
107108
this.ssaoMaterial.uniforms[ 'tNormal' ].value = this.normalRenderTarget.texture;
108-
this.ssaoMaterial.uniforms[ 'tDepth' ].value = this.beautyRenderTarget.depthTexture;
109+
this.ssaoMaterial.uniforms[ 'tDepth' ].value = this.normalRenderTarget.depthTexture;
109110
this.ssaoMaterial.uniforms[ 'tNoise' ].value = this.noiseTexture;
110111
this.ssaoMaterial.uniforms[ 'kernel' ].value = this.kernel;
111112
this.ssaoMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
@@ -139,7 +140,7 @@ var SSAOPass = function ( scene, camera, width, height ) {
139140
fragmentShader: SSAODepthShader.fragmentShader,
140141
blending: NoBlending
141142
} );
142-
this.depthRenderMaterial.uniforms[ 'tDepth' ].value = this.beautyRenderTarget.depthTexture;
143+
this.depthRenderMaterial.uniforms[ 'tDepth' ].value = this.normalRenderTarget.depthTexture;
143144
this.depthRenderMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
144145
this.depthRenderMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
145146

@@ -194,15 +195,17 @@ SSAOPass.prototype = Object.assign( Object.create( Pass.prototype ), {
194195

195196
render: function ( renderer, writeBuffer /*, readBuffer, deltaTime, maskActive */ ) {
196197

197-
// render beauty and depth
198+
// render beauty
198199

199200
renderer.setRenderTarget( this.beautyRenderTarget );
200201
renderer.clear();
201202
renderer.render( this.scene, this.camera );
202203

203-
// render normals
204+
// render normals and depth (honor only meshes, points and lines do not contribute to SSAO)
204205

206+
this.overrideVisibility();
205207
this.renderOverride( renderer, this.normalMaterial, this.normalRenderTarget, 0x7777ff, 1.0 );
208+
this.restoreVisibility();
206209

207210
// render SSAO
208211

@@ -415,6 +418,35 @@ SSAOPass.prototype = Object.assign( Object.create( Pass.prototype ), {
415418
this.noiseTexture.wrapS = RepeatWrapping;
416419
this.noiseTexture.wrapT = RepeatWrapping;
417420

421+
},
422+
423+
overrideVisibility: function () {
424+
425+
var scene = this.scene;
426+
427+
scene.traverse( function ( object ) {
428+
429+
_cache.set( object, object.visible );
430+
431+
if ( object.isPoints || object.isLine ) object.visible = false;
432+
433+
} );
434+
435+
},
436+
437+
restoreVisibility: function () {
438+
439+
var scene = this.scene;
440+
441+
scene.traverse( function ( object ) {
442+
443+
var visible = _cache.get( object );
444+
object.visible = visible;
445+
446+
} );
447+
448+
_cache.clear();
449+
418450
}
419451

420452
} );

0 commit comments

Comments
 (0)