Skip to content

Commit

Permalink
Added ability to disable render passes to EffectComposer. Added simpl…
Browse files Browse the repository at this point in the history
…e blend shader to ShaderExtras.
  • Loading branch information
alteredq committed Sep 25, 2011
1 parent 00b8d06 commit 9e39966
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 12 deletions.
55 changes: 53 additions & 2 deletions examples/js/ShaderExtras.js
Expand Up @@ -16,8 +16,9 @@
* dofmipmap
* focus
* triangleBlur
* horizontalBlur
* verticalBlur
* horizontalBlur + verticalBlur
* horizontalTiltShift + verticalTiltShift
* blend
*/

THREE.ShaderExtras = {
Expand Down Expand Up @@ -1083,6 +1084,56 @@ THREE.ShaderExtras = {

},

/* -------------------------------------------------------------------------
// Blend two textures
------------------------------------------------------------------------- */

'blend': {

uniforms: {

tDiffuse1: { type: "t", value: 0, texture: null },
tDiffuse2: { type: "t", value: 1, texture: null },
mixRatio: { type: "f", value: 0.5 },
opacity: { type: "f", value: 1.0 }

},

vertexShader: [

"varying vec2 vUv;",

"void main() {",

"vUv = vec2( uv.x, 1.0 - uv.y );",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",

"}"

].join("\n"),

fragmentShader: [

"uniform float opacity;",
"uniform float mixRatio;",

"uniform sampler2D tDiffuse1;",
"uniform sampler2D tDiffuse2;",

"varying vec2 vUv;",

"void main() {",

"vec4 texel1 = texture2D( tDiffuse1, vUv );",
"vec4 texel2 = texture2D( tDiffuse2, vUv );",
"gl_FragColor = opacity * mix( texel1, texel2, mixRatio );",

"}"

].join("\n")

},

// METHODS

buildKernel: function( sigma ) {
Expand Down
1 change: 1 addition & 0 deletions examples/js/postprocessing/BloomPass.js
Expand Up @@ -51,6 +51,7 @@ THREE.BloomPass = function( strength, kernelSize, sigma, resolution ) {

} );

this.enabled = true;
this.needsSwap = false;
this.clear = false;

Expand Down
1 change: 1 addition & 0 deletions examples/js/postprocessing/DotScreenPass.js
Expand Up @@ -22,6 +22,7 @@ THREE.DotScreenPass = function( center, angle, scale ) {

} );

this.enabled = true;
this.renderToScreen = false;
this.needsSwap = true;

Expand Down
16 changes: 9 additions & 7 deletions examples/js/postprocessing/EffectComposer.js
Expand Up @@ -49,13 +49,17 @@ THREE.EffectComposer.prototype = {

var maskActive = false;

var i, il = this.passes.length;
var pass, i, il = this.passes.length;

for ( i = 0; i < il; i ++ ) {

this.passes[ i ].render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive );
pass = this.passes[ i ];

if ( this.passes[ i ].needsSwap ) {
if ( !pass.enabled ) continue;

pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive );

if ( pass.needsSwap ) {

if ( maskActive ) {

Expand All @@ -73,13 +77,11 @@ THREE.EffectComposer.prototype = {

}

if ( this.passes[ i ] instanceof THREE.MaskPass ) {
if ( pass instanceof THREE.MaskPass ) {

maskActive = true;

}

if ( this.passes[ i ] instanceof THREE.ClearMaskPass ) {
} else if ( pass instanceof THREE.ClearMaskPass ) {

maskActive = false;

Expand Down
1 change: 1 addition & 0 deletions examples/js/postprocessing/FilmPass.js
Expand Up @@ -21,6 +21,7 @@ THREE.FilmPass = function( noiseIntensity, scanlinesIntensity, scanlinesCount, g
if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;

this.enabled = true;
this.renderToScreen = false;
this.needsSwap = true;

Expand Down
3 changes: 3 additions & 0 deletions examples/js/postprocessing/MaskPass.js
Expand Up @@ -7,6 +7,7 @@ THREE.MaskPass = function ( scene, camera ) {
this.scene = scene;
this.camera = camera;

this.enabled = true;
this.clear = true;
this.needsSwap = false;

Expand Down Expand Up @@ -51,6 +52,8 @@ THREE.MaskPass.prototype = {

THREE.ClearMaskPass = function () {

this.enabled = true;

};

THREE.ClearMaskPass.prototype = {
Expand Down
7 changes: 4 additions & 3 deletions examples/js/postprocessing/RenderPass.js
Expand Up @@ -12,12 +12,13 @@ THREE.RenderPass = function ( scene, camera, overrideMaterial, clearColor, clear
this.clearColor = clearColor;
this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 1;

this.clear = true;
this.needsSwap = false;

this.oldClearColor = new THREE.Color();
this.oldClearAlpha = 1;

this.enabled = true;
this.clear = true;
this.needsSwap = false;

};

THREE.RenderPass.prototype = {
Expand Down
2 changes: 2 additions & 0 deletions examples/js/postprocessing/ShaderPass.js
Expand Up @@ -17,6 +17,8 @@ THREE.ShaderPass = function( shader, textureID ) {
} );

this.renderToScreen = false;

this.enabled = true;
this.needsSwap = true;
this.clear = false;

Expand Down
1 change: 1 addition & 0 deletions examples/js/postprocessing/TexturePass.js
Expand Up @@ -19,6 +19,7 @@ THREE.TexturePass = function( texture, opacity ) {

} );

this.enabled = true;
this.needsSwap = false;

};
Expand Down

0 comments on commit 9e39966

Please sign in to comment.