Browse Source

Added ability to disable render passes to EffectComposer. Added simple blend shader to ShaderExtras.

alteredq 14 years ago
parent
commit
9e39966076

+ 53 - 2
examples/js/ShaderExtras.js

@@ -16,8 +16,9 @@
  *  dofmipmap
  *  focus
  *  triangleBlur
- *  horizontalBlur
- *  verticalBlur
+ *  horizontalBlur + verticalBlur
+ *  horizontalTiltShift + verticalTiltShift
+ *  blend
  */
 
 THREE.ShaderExtras = {
@@ -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 ) {

+ 1 - 0
examples/js/postprocessing/BloomPass.js

@@ -51,6 +51,7 @@ THREE.BloomPass = function( strength, kernelSize, sigma, resolution ) {
 
 	} );
 
+	this.enabled = true;
 	this.needsSwap = false;
 	this.clear = false;
 

+ 1 - 0
examples/js/postprocessing/DotScreenPass.js

@@ -22,6 +22,7 @@ THREE.DotScreenPass = function( center, angle, scale ) {
 
 	} );
 
+	this.enabled = true;
 	this.renderToScreen = false;
 	this.needsSwap = true;
 

+ 9 - 7
examples/js/postprocessing/EffectComposer.js

@@ -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 ) {
 
@@ -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;
 

+ 1 - 0
examples/js/postprocessing/FilmPass.js

@@ -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;
 

+ 3 - 0
examples/js/postprocessing/MaskPass.js

@@ -7,6 +7,7 @@ THREE.MaskPass = function ( scene, camera ) {
 	this.scene = scene;
 	this.camera = camera;
 
+	this.enabled = true;
 	this.clear = true;
 	this.needsSwap = false;
 
@@ -51,6 +52,8 @@ THREE.MaskPass.prototype = {
 
 THREE.ClearMaskPass = function () {
 
+	this.enabled = true;
+
 };
 
 THREE.ClearMaskPass.prototype = {

+ 4 - 3
examples/js/postprocessing/RenderPass.js

@@ -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 = {

+ 2 - 0
examples/js/postprocessing/ShaderPass.js

@@ -17,6 +17,8 @@ THREE.ShaderPass = function( shader, textureID ) {
 	} );
 
 	this.renderToScreen = false;
+
+	this.enabled = true;
 	this.needsSwap = true;
 	this.clear = false;
 

+ 1 - 0
examples/js/postprocessing/TexturePass.js

@@ -19,6 +19,7 @@ THREE.TexturePass = function( texture, opacity ) {
 
 	} );
 
+	this.enabled = true;
 	this.needsSwap = false;
 
 };