1//* 9fbef606107a605d69c0edbcd8029e5d *// 2/** 3 * @author alteredq / http://alteredqualia.com/ 4 */ 5 6THREE.EffectComposer = function ( renderer, renderTarget ) { 7 8 this.renderer = renderer; 9 10 if ( renderTarget === undefined ) { 11 12 var parameters = { 13 minFilter: THREE.LinearFilter, 14 magFilter: THREE.LinearFilter, 15 format: THREE.RGBAFormat, 16 stencilBuffer: false 17 }; 18 19 var size = renderer.getSize( new THREE.Vector2() ); 20 this._pixelRatio = renderer.getPixelRatio(); 21 this._width = size.width; 22 this._height = size.height; 23 24 renderTarget = new THREE.WebGLRenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, parameters ); 25 renderTarget.texture.name = 'EffectComposer.rt1'; 26 27 } else { 28 29 this._pixelRatio = 1; 30 this._width = renderTarget.width; 31 this._height = renderTarget.height; 32 33 } 34 35 this.renderTarget1 = renderTarget; 36 this.renderTarget2 = renderTarget.clone(); 37 this.renderTarget2.texture.name = 'EffectComposer.rt2'; 38 39 this.writeBuffer = this.renderTarget1; 40 this.readBuffer = this.renderTarget2; 41 42 this.renderToScreen = true; 43 44 this.passes = []; 45 46 // dependencies 47 48 if ( THREE.CopyShader === undefined ) { 49 50 console.error( 'THREE.EffectComposer relies on THREE.CopyShader' ); 51 52 } 53 54 if ( THREE.ShaderPass === undefined ) { 55 56 console.error( 'THREE.EffectComposer relies on THREE.ShaderPass' ); 57 58 } 59 60 this.copyPass = new THREE.ShaderPass( THREE.CopyShader ); 61 62 this.clock = new THREE.Clock(); 63 64}; 65 66Object.assign( THREE.EffectComposer.prototype, { 67 68 swapBuffers: function () { 69 70 var tmp = this.readBuffer; 71 this.readBuffer = this.writeBuffer; 72 this.writeBuffer = tmp; 73 74 }, 75 76 addPass: function ( pass ) { 77 78 this.passes.push( pass ); 79 80 var size = this.renderer.getDrawingBufferSize( new THREE.Vector2() ); 81 pass.setSize( size.width, size.height ); 82 83 }, 84 85 insertPass: function ( pass, index ) { 86 87 this.passes.splice( index, 0, pass ); 88 89 }, 90 91 isLastEnabledPass: function ( passIndex ) { 92 93 for ( var i = passIndex + 1; i < this.passes.length; i ++ ) { 94 95 if ( this.passes[ i ].enabled ) { 96 97 return false; 98 99 } 100 101 } 102 103 return true; 104 105 }, 106 107 render: function ( deltaTime ) { 108 109 // deltaTime value is in seconds 110 111 if ( deltaTime === undefined ) { 112 113 deltaTime = this.clock.getDelta(); 114 115 } 116 117 var currentRenderTarget = this.renderer.getRenderTarget(); 118 119 var maskActive = false; 120 121 var pass, i, il = this.passes.length; 122 123 for ( i = 0; i < il; i ++ ) { 124 125 pass = this.passes[ i ]; 126 127 if ( pass.enabled === false ) continue; 128 129 pass.renderToScreen = ( this.renderToScreen && this.isLastEnabledPass( i ) ); 130 pass.render( this.renderer, this.writeBuffer, this.readBuffer, deltaTime, maskActive ); 131 132 if ( pass.needsSwap ) { 133 134 if ( maskActive ) { 135 136 var context = this.renderer.context; 137 138 context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff ); 139 140 this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, deltaTime ); 141 142 context.stencilFunc( context.EQUAL, 1, 0xffffffff ); 143 144 } 145 146 this.swapBuffers(); 147 148 } 149 150 if ( THREE.MaskPass !== undefined ) { 151 152 if ( pass instanceof THREE.MaskPass ) { 153 154 maskActive = true; 155 156 } else if ( pass instanceof THREE.ClearMaskPass ) { 157 158 maskActive = false; 159 160 } 161 162 } 163 164 } 165 166 this.renderer.setRenderTarget( currentRenderTarget ); 167 168 }, 169 170 reset: function ( renderTarget ) { 171 172 if ( renderTarget === undefined ) { 173 174 var size = this.renderer.getSize( new THREE.Vector2() ); 175 this._pixelRatio = this.renderer.getPixelRatio(); 176 this._width = size.width; 177 this._height = size.height; 178 179 renderTarget = this.renderTarget1.clone(); 180 renderTarget.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio ); 181 182 } 183 184 this.renderTarget1.dispose(); 185 this.renderTarget2.dispose(); 186 this.renderTarget1 = renderTarget; 187 this.renderTarget2 = renderTarget.clone(); 188 189 this.writeBuffer = this.renderTarget1; 190 this.readBuffer = this.renderTarget2; 191 192 }, 193 194 setSize: function ( width, height ) { 195 196 this._width = width; 197 this._height = height; 198 199 var effectiveWidth = this._width * this._pixelRatio; 200 var effectiveHeight = this._height * this._pixelRatio; 201 202 this.renderTarget1.setSize( effectiveWidth, effectiveHeight ); 203 this.renderTarget2.setSize( effectiveWidth, effectiveHeight ); 204 205 for ( var i = 0; i < this.passes.length; i ++ ) { 206 207 this.passes[ i ].setSize( effectiveWidth, effectiveHeight ); 208 209 } 210 211 }, 212 213 setPixelRatio: function ( pixelRatio ) { 214 215 this._pixelRatio = pixelRatio; 216 217 this.setSize( this._width, this._height ); 218 219 } 220 221} ); 222 223 224THREE.Pass = function () { 225 226 // if set to true, the pass is processed by the composer 227 this.enabled = true; 228 229 // if set to true, the pass indicates to swap read and write buffer after rendering 230 this.needsSwap = true; 231 232 // if set to true, the pass clears its buffer before rendering 233 this.clear = false;
234 235 // if set to true, the result of the pass is rendered to screen. This is set automatically by EffectComposer. 236 this.renderToScreen = false; 237 238}; 239 240Object.assign( THREE.Pass.prototype, { 241 242 setSize: function ( /* width, height */ ) {}, 243 244 render: function ( /* renderer, writeBuffer, readBuffer, deltaTime, maskActive */ ) { 245 246 console.error( 'THREE.Pass: .render() must be implemented in derived pass.' ); 247 248 } 249 250} ); 251 252// Helper for passes that need to fill the viewport with a single quad. 253THREE.Pass.FullScreenQuad = ( function () { 254 255 var camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 256 var geometry = new THREE.PlaneBufferGeometry( 2, 2 ); 257 258 var FullScreenQuad = function ( material ) { 259 260 this._mesh = new THREE.Mesh( geometry, material ); 261 262 }; 263 264 Object.defineProperty( FullScreenQuad.prototype, 'material', { 265 266 get: function () { 267 268 return this._mesh.material; 269 270 }, 271 272 set: function ( value ) { 273 274 this._mesh.material = value; 275 276 } 277 278 } ); 279 280 Object.assign( FullScreenQuad.prototype, { 281 282 render: function ( renderer ) { 283 284 renderer.render( this._mesh, camera ); 285 286 } 287 288 } ); 289 290 return FullScreenQuad; 291 292} )();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.