11console . 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+
35THREE . 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} ) ;
0 commit comments