123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 'use strict';
- /*
- * Screen-space ambient occlusion pass.
- *
- * Has the following parameters
- * - radius
- * - onlyAO
- * - aoClamp
- * - lumInfluence
- *
- * To output to screen set renderToScreens true
- *
- * @author alteredq / http://alteredqualia.com/
- * @author tentone
- */
- THREE.SSAOPass = function ( scene, camera, width, height ) {
- if ( THREE.SSAOShader === undefined)
- {
- console.warn('THREE.SSAOPass depends on THREE.SSAOShader');
- return new THREE.ShaderPass();
- }
- THREE.ShaderPass.call( this, THREE.SSAOShader );
- this.width = ( width !== undefined ) ? width : 512;
- this.height = ( height !== undefined ) ? height : 512;
- this.renderToScreen = false;
- this.camera2 = camera;
- this.scene2 = scene;
- //Depth material
- this.depthMaterial = new THREE.MeshDepthMaterial();
- this.depthMaterial.depthPacking = THREE.RGBADepthPacking;
- this.depthMaterial.blending = THREE.NoBlending;
- //Depth render target
- this.depthRenderTarget = new THREE.WebGLRenderTarget( this.width, this.height, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter } );
- this.depthRenderTarget.texture.name = 'SSAOShader.rt';
-
- //Shader uniforms
- this.uniforms[ 'tDepth' ].value = this.depthRenderTarget.texture;
- this.uniforms[ 'size' ].value.set( this.width, this.height );
- this.uniforms[ 'cameraNear' ].value = this.camera2.near;
- this.uniforms[ 'cameraFar' ].value = this.camera2.far;
- this.uniforms[ 'radius' ].value = 4;
- this.uniforms[ 'onlyAO' ].value = false;
- this.uniforms[ 'aoClamp' ].value = 0.25;
- this.uniforms[ 'lumInfluence' ].value = 0.7;
- //Setters and getters for uniforms
- var self = this;
- Object.defineProperties(this, {
- radius: {
- get: function() { return this.uniforms[ 'radius' ].value; },
- set: function(value) { this.uniforms[ 'radius' ].value = value; }
- },
- onlyAO: {
- get: function() { return this.uniforms[ 'onlyAO' ].value; },
- set: function(value) { this.uniforms[ 'onlyAO' ].value = value; }
- },
- aoClamp: {
- get: function() { return this.uniforms[ 'aoClamp' ].value; },
- set: function(value) { this.uniforms[ 'aoClamp' ].value = value; }
- },
- lumInfluence: {
- get: function() { return this.uniforms[ 'lumInfluence' ].value; },
- set: function(value) { this.uniforms[ 'lumInfluence' ].value = value; }
- },
- });
- }
- THREE.SSAOPass.prototype = Object.create( THREE.ShaderPass.prototype );
- THREE.SSAOPass.prototype.render = function( renderer, writeBuffer, readBuffer, delta, maskActive ) {
- //Render depth into depthRenderTarget
- this.scene2.overrideMaterial = this.depthMaterial;
- renderer.render( this.scene2, this.camera2, this.depthRenderTarget, true );
-
- //Render renderPass and SSAO shaderPass
- this.scene2.overrideMaterial = null;
- THREE.ShaderPass.prototype.render.call( this, renderer, writeBuffer, readBuffer, delta, maskActive );
- };
- THREE.SSAOPass.prototype.setSize = function( width, height ) {
- this.width = width;
- this.height = height;
- this.uniforms[ 'size' ].value.set( this.width, this.height );
- this.depthRenderTarget.setSize( this.width, this.height );
- };
|