Skip to content

Commit

Permalink
Make EffectComposer plugins use their own camera/scene/quad
Browse files Browse the repository at this point in the history
This fixes # 2951.
  • Loading branch information
wereHamster authored and crobi committed Oct 30, 2013
1 parent f396baf commit 2a5c541
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 28 deletions.
17 changes: 12 additions & 5 deletions examples/js/postprocessing/BloomPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ THREE.BloomPass = function ( strength, kernelSize, sigma, resolution ) {
this.needsSwap = false;
this.clear = false;


this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
this.scene.add( this.quad );

};

THREE.BloomPass.prototype = {
Expand All @@ -75,30 +82,30 @@ THREE.BloomPass.prototype = {

// Render quad with blured scene into texture (convolution pass 1)

THREE.EffectComposer.quad.material = this.materialConvolution;
this.quad.material = this.materialConvolution;

this.convolutionUniforms[ "tDiffuse" ].value = readBuffer;
this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurX;

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, this.renderTargetX, true );
renderer.render( this.scene, this.camera, this.renderTargetX, true );


// Render quad with blured scene into texture (convolution pass 2)

this.convolutionUniforms[ "tDiffuse" ].value = this.renderTargetX;
this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurY;

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, this.renderTargetY, true );
renderer.render( this.scene, this.camera, this.renderTargetY, true );

// Render original scene with superimposed blur to texture

THREE.EffectComposer.quad.material = this.materialCopy;
this.quad.material = this.materialCopy;

this.copyUniforms[ "tDiffuse" ].value = this.renderTargetY;

if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST );

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, readBuffer, this.clear );
renderer.render( this.scene, this.camera, readBuffer, this.clear );

}

Expand Down
13 changes: 10 additions & 3 deletions examples/js/postprocessing/DotScreenPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ THREE.DotScreenPass = function ( center, angle, scale ) {
this.renderToScreen = false;
this.needsSwap = true;


this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
this.scene.add( this.quad );

};

THREE.DotScreenPass.prototype = {
Expand All @@ -36,15 +43,15 @@ THREE.DotScreenPass.prototype = {
this.uniforms[ "tDiffuse" ].value = readBuffer;
this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height );

THREE.EffectComposer.quad.material = this.material;
this.quad.material = this.material;

if ( this.renderToScreen ) {

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera );
renderer.render( this.scene, this.camera );

} else {

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, false );
renderer.render( this.scene, this.camera, writeBuffer, false );

}

Expand Down
9 changes: 0 additions & 9 deletions examples/js/postprocessing/EffectComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,3 @@ THREE.EffectComposer.prototype = {
}

};

// shared ortho camera

THREE.EffectComposer.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );

THREE.EffectComposer.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );

THREE.EffectComposer.scene = new THREE.Scene();
THREE.EffectComposer.scene.add( THREE.EffectComposer.quad );
13 changes: 10 additions & 3 deletions examples/js/postprocessing/FilmPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount,
this.renderToScreen = false;
this.needsSwap = true;


this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
this.scene.add( this.quad );

};

THREE.FilmPass.prototype = {
Expand All @@ -37,15 +44,15 @@ THREE.FilmPass.prototype = {
this.uniforms[ "tDiffuse" ].value = readBuffer;
this.uniforms[ "time" ].value += delta;

THREE.EffectComposer.quad.material = this.material;
this.quad.material = this.material;

if ( this.renderToScreen ) {

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera );
renderer.render( this.scene, this.camera );

} else {

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, false );
renderer.render( this.scene, this.camera, writeBuffer, false );

}

Expand Down
11 changes: 9 additions & 2 deletions examples/js/postprocessing/SavePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ THREE.SavePass = function ( renderTarget ) {
this.needsSwap = false;
this.clear = false;


this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
this.scene.add( this.quad );

};

THREE.SavePass.prototype = {
Expand All @@ -46,9 +53,9 @@ THREE.SavePass.prototype = {

}

THREE.EffectComposer.quad.material = this.material;
this.quad.material = this.material;

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, this.renderTarget, this.clear );
renderer.render( this.scene, this.camera, this.renderTarget, this.clear );

}

Expand Down
13 changes: 10 additions & 3 deletions examples/js/postprocessing/ShaderPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ THREE.ShaderPass = function ( shader, textureID ) {
this.needsSwap = true;
this.clear = false;


this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
this.scene.add( this.quad );

};

THREE.ShaderPass.prototype = {
Expand All @@ -34,15 +41,15 @@ THREE.ShaderPass.prototype = {

}

THREE.EffectComposer.quad.material = this.material;
this.quad.material = this.material;

if ( this.renderToScreen ) {

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera );
renderer.render( this.scene, this.camera );

} else {

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, this.clear );
renderer.render( this.scene, this.camera, writeBuffer, this.clear );

}

Expand Down
11 changes: 9 additions & 2 deletions examples/js/postprocessing/TexturePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ THREE.TexturePass = function ( texture, opacity ) {
this.enabled = true;
this.needsSwap = false;


this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
this.scene.add( this.quad );

};

THREE.TexturePass.prototype = {

render: function ( renderer, writeBuffer, readBuffer, delta ) {

THREE.EffectComposer.quad.material = this.material;
this.quad.material = this.material;

renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, readBuffer );
renderer.render( this.scene, this.camera, readBuffer );

}

Expand Down
2 changes: 1 addition & 1 deletion examples/js/renderers/WebGLDeferredRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
passColor.camera = currentCamera;
passNormalDepth.camera = currentCamera;
passLightProxy.camera = currentCamera;
passLightFullscreen.camera = THREE.EffectComposer.camera;
passLightFullscreen.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );

passColor.scene = scene;
passNormalDepth.scene = scene;
Expand Down

0 comments on commit 2a5c541

Please sign in to comment.