Skip to content

Commit 9e39966

Browse files
committed
Added ability to disable render passes to EffectComposer. Added simple blend shader to ShaderExtras.
1 parent 00b8d06 commit 9e39966

File tree

9 files changed

+75
-12
lines changed

9 files changed

+75
-12
lines changed

examples/js/ShaderExtras.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
* dofmipmap
1717
* focus
1818
* triangleBlur
19-
* horizontalBlur
20-
* verticalBlur
19+
* horizontalBlur + verticalBlur
20+
* horizontalTiltShift + verticalTiltShift
21+
* blend
2122
*/
2223

2324
THREE.ShaderExtras = {
@@ -1083,6 +1084,56 @@ THREE.ShaderExtras = {
10831084

10841085
},
10851086

1087+
/* -------------------------------------------------------------------------
1088+
// Blend two textures
1089+
------------------------------------------------------------------------- */
1090+
1091+
'blend': {
1092+
1093+
uniforms: {
1094+
1095+
tDiffuse1: { type: "t", value: 0, texture: null },
1096+
tDiffuse2: { type: "t", value: 1, texture: null },
1097+
mixRatio: { type: "f", value: 0.5 },
1098+
opacity: { type: "f", value: 1.0 }
1099+
1100+
},
1101+
1102+
vertexShader: [
1103+
1104+
"varying vec2 vUv;",
1105+
1106+
"void main() {",
1107+
1108+
"vUv = vec2( uv.x, 1.0 - uv.y );",
1109+
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
1110+
1111+
"}"
1112+
1113+
].join("\n"),
1114+
1115+
fragmentShader: [
1116+
1117+
"uniform float opacity;",
1118+
"uniform float mixRatio;",
1119+
1120+
"uniform sampler2D tDiffuse1;",
1121+
"uniform sampler2D tDiffuse2;",
1122+
1123+
"varying vec2 vUv;",
1124+
1125+
"void main() {",
1126+
1127+
"vec4 texel1 = texture2D( tDiffuse1, vUv );",
1128+
"vec4 texel2 = texture2D( tDiffuse2, vUv );",
1129+
"gl_FragColor = opacity * mix( texel1, texel2, mixRatio );",
1130+
1131+
"}"
1132+
1133+
].join("\n")
1134+
1135+
},
1136+
10861137
// METHODS
10871138

10881139
buildKernel: function( sigma ) {

examples/js/postprocessing/BloomPass.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ THREE.BloomPass = function( strength, kernelSize, sigma, resolution ) {
5151

5252
} );
5353

54+
this.enabled = true;
5455
this.needsSwap = false;
5556
this.clear = false;
5657

examples/js/postprocessing/DotScreenPass.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ THREE.DotScreenPass = function( center, angle, scale ) {
2222

2323
} );
2424

25+
this.enabled = true;
2526
this.renderToScreen = false;
2627
this.needsSwap = true;
2728

examples/js/postprocessing/EffectComposer.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ THREE.EffectComposer.prototype = {
4949

5050
var maskActive = false;
5151

52-
var i, il = this.passes.length;
52+
var pass, i, il = this.passes.length;
5353

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

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

58-
if ( this.passes[ i ].needsSwap ) {
58+
if ( !pass.enabled ) continue;
59+
60+
pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive );
61+
62+
if ( pass.needsSwap ) {
5963

6064
if ( maskActive ) {
6165

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

7478
}
7579

76-
if ( this.passes[ i ] instanceof THREE.MaskPass ) {
80+
if ( pass instanceof THREE.MaskPass ) {
7781

7882
maskActive = true;
7983

80-
}
81-
82-
if ( this.passes[ i ] instanceof THREE.ClearMaskPass ) {
84+
} else if ( pass instanceof THREE.ClearMaskPass ) {
8385

8486
maskActive = false;
8587

examples/js/postprocessing/FilmPass.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ THREE.FilmPass = function( noiseIntensity, scanlinesIntensity, scanlinesCount, g
2121
if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
2222
if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
2323

24+
this.enabled = true;
2425
this.renderToScreen = false;
2526
this.needsSwap = true;
2627

examples/js/postprocessing/MaskPass.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ THREE.MaskPass = function ( scene, camera ) {
77
this.scene = scene;
88
this.camera = camera;
99

10+
this.enabled = true;
1011
this.clear = true;
1112
this.needsSwap = false;
1213

@@ -51,6 +52,8 @@ THREE.MaskPass.prototype = {
5152

5253
THREE.ClearMaskPass = function () {
5354

55+
this.enabled = true;
56+
5457
};
5558

5659
THREE.ClearMaskPass.prototype = {

examples/js/postprocessing/RenderPass.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ THREE.RenderPass = function ( scene, camera, overrideMaterial, clearColor, clear
1212
this.clearColor = clearColor;
1313
this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 1;
1414

15-
this.clear = true;
16-
this.needsSwap = false;
17-
1815
this.oldClearColor = new THREE.Color();
1916
this.oldClearAlpha = 1;
2017

18+
this.enabled = true;
19+
this.clear = true;
20+
this.needsSwap = false;
21+
2122
};
2223

2324
THREE.RenderPass.prototype = {

examples/js/postprocessing/ShaderPass.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ THREE.ShaderPass = function( shader, textureID ) {
1717
} );
1818

1919
this.renderToScreen = false;
20+
21+
this.enabled = true;
2022
this.needsSwap = true;
2123
this.clear = false;
2224

examples/js/postprocessing/TexturePass.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ THREE.TexturePass = function( texture, opacity ) {
1919

2020
} );
2121

22+
this.enabled = true;
2223
this.needsSwap = false;
2324

2425
};

0 commit comments

Comments
 (0)