|
@@ -1,5 +1,7 @@
|
|
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." );
|
|
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." );
|
|
|
|
|
|
|
|
+var _cache = new Map();
|
|
|
|
+
|
|
THREE.SSAOPass = function ( scene, camera, width, height ) {
|
|
THREE.SSAOPass = function ( scene, camera, width, height ) {
|
|
|
|
|
|
THREE.Pass.call( this );
|
|
THREE.Pass.call( this );
|
|
@@ -26,7 +28,7 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
|
|
this.generateSampleKernel();
|
|
this.generateSampleKernel();
|
|
this.generateRandomKernelRotations();
|
|
this.generateRandomKernelRotations();
|
|
|
|
|
|
- // beauty render target with depth buffer
|
|
|
|
|
|
+ // beauty render target
|
|
|
|
|
|
var depthTexture = new THREE.DepthTexture();
|
|
var depthTexture = new THREE.DepthTexture();
|
|
depthTexture.type = THREE.UnsignedShortType;
|
|
depthTexture.type = THREE.UnsignedShortType;
|
|
@@ -36,17 +38,16 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
|
|
this.beautyRenderTarget = new THREE.WebGLRenderTarget( this.width, this.height, {
|
|
this.beautyRenderTarget = new THREE.WebGLRenderTarget( this.width, this.height, {
|
|
minFilter: THREE.LinearFilter,
|
|
minFilter: THREE.LinearFilter,
|
|
magFilter: THREE.LinearFilter,
|
|
magFilter: THREE.LinearFilter,
|
|
- format: THREE.RGBAFormat,
|
|
|
|
- depthTexture: depthTexture,
|
|
|
|
- depthBuffer: true
|
|
|
|
|
|
+ format: THREE.RGBAFormat
|
|
} );
|
|
} );
|
|
|
|
|
|
- // normal render target
|
|
|
|
|
|
+ // normal render target with depth buffer
|
|
|
|
|
|
this.normalRenderTarget = new THREE.WebGLRenderTarget( this.width, this.height, {
|
|
this.normalRenderTarget = new THREE.WebGLRenderTarget( this.width, this.height, {
|
|
minFilter: THREE.NearestFilter,
|
|
minFilter: THREE.NearestFilter,
|
|
magFilter: THREE.NearestFilter,
|
|
magFilter: THREE.NearestFilter,
|
|
- format: THREE.RGBAFormat
|
|
|
|
|
|
+ format: THREE.RGBAFormat,
|
|
|
|
+ depthTexture: depthTexture
|
|
} );
|
|
} );
|
|
|
|
|
|
// ssao render target
|
|
// ssao render target
|
|
@@ -77,7 +78,7 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
|
|
|
|
|
|
this.ssaoMaterial.uniforms[ 'tDiffuse' ].value = this.beautyRenderTarget.texture;
|
|
this.ssaoMaterial.uniforms[ 'tDiffuse' ].value = this.beautyRenderTarget.texture;
|
|
this.ssaoMaterial.uniforms[ 'tNormal' ].value = this.normalRenderTarget.texture;
|
|
this.ssaoMaterial.uniforms[ 'tNormal' ].value = this.normalRenderTarget.texture;
|
|
- this.ssaoMaterial.uniforms[ 'tDepth' ].value = this.beautyRenderTarget.depthTexture;
|
|
|
|
|
|
+ this.ssaoMaterial.uniforms[ 'tDepth' ].value = this.normalRenderTarget.depthTexture;
|
|
this.ssaoMaterial.uniforms[ 'tNoise' ].value = this.noiseTexture;
|
|
this.ssaoMaterial.uniforms[ 'tNoise' ].value = this.noiseTexture;
|
|
this.ssaoMaterial.uniforms[ 'kernel' ].value = this.kernel;
|
|
this.ssaoMaterial.uniforms[ 'kernel' ].value = this.kernel;
|
|
this.ssaoMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
|
|
this.ssaoMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
|
|
@@ -111,7 +112,7 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
|
|
fragmentShader: THREE.SSAODepthShader.fragmentShader,
|
|
fragmentShader: THREE.SSAODepthShader.fragmentShader,
|
|
blending: THREE.NoBlending
|
|
blending: THREE.NoBlending
|
|
} );
|
|
} );
|
|
- this.depthRenderMaterial.uniforms[ 'tDepth' ].value = this.beautyRenderTarget.depthTexture;
|
|
|
|
|
|
+ this.depthRenderMaterial.uniforms[ 'tDepth' ].value = this.normalRenderTarget.depthTexture;
|
|
this.depthRenderMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
|
|
this.depthRenderMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
|
|
this.depthRenderMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
|
|
this.depthRenderMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
|
|
|
|
|
|
@@ -166,15 +167,17 @@ THREE.SSAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
|
|
|
|
|
|
render: function ( renderer, writeBuffer /*, readBuffer, deltaTime, maskActive */ ) {
|
|
render: function ( renderer, writeBuffer /*, readBuffer, deltaTime, maskActive */ ) {
|
|
|
|
|
|
- // render beauty and depth
|
|
|
|
|
|
+ // render beauty
|
|
|
|
|
|
renderer.setRenderTarget( this.beautyRenderTarget );
|
|
renderer.setRenderTarget( this.beautyRenderTarget );
|
|
renderer.clear();
|
|
renderer.clear();
|
|
renderer.render( this.scene, this.camera );
|
|
renderer.render( this.scene, this.camera );
|
|
|
|
|
|
- // render normals
|
|
|
|
|
|
+ // render normals and depth (honor only meshes, points and lines do not contribute to SSAO)
|
|
|
|
|
|
|
|
+ this.overrideVisibility();
|
|
this.renderOverride( renderer, this.normalMaterial, this.normalRenderTarget, 0x7777ff, 1.0 );
|
|
this.renderOverride( renderer, this.normalMaterial, this.normalRenderTarget, 0x7777ff, 1.0 );
|
|
|
|
+ this.restoreVisibility();
|
|
|
|
|
|
// render SSAO
|
|
// render SSAO
|
|
|
|
|
|
@@ -387,6 +390,35 @@ THREE.SSAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
|
|
this.noiseTexture.wrapS = THREE.RepeatWrapping;
|
|
this.noiseTexture.wrapS = THREE.RepeatWrapping;
|
|
this.noiseTexture.wrapT = THREE.RepeatWrapping;
|
|
this.noiseTexture.wrapT = THREE.RepeatWrapping;
|
|
|
|
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ overrideVisibility: function () {
|
|
|
|
+
|
|
|
|
+ var scene = this.scene;
|
|
|
|
+
|
|
|
|
+ scene.traverse( function ( object ) {
|
|
|
|
+
|
|
|
|
+ _cache.set( object, object.visible );
|
|
|
|
+
|
|
|
|
+ if ( object.isPoints || object.isLine ) object.visible = false;
|
|
|
|
+
|
|
|
|
+ } );
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ restoreVisibility: function () {
|
|
|
|
+
|
|
|
|
+ var scene = this.scene;
|
|
|
|
+
|
|
|
|
+ scene.traverse( function ( object ) {
|
|
|
|
+
|
|
|
|
+ var visible = _cache.get( object );
|
|
|
|
+ object.visible = visible;
|
|
|
|
+
|
|
|
|
+ } );
|
|
|
|
+
|
|
|
|
+ _cache.clear();
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
} );
|
|
} );
|