Browse Source

CompositeShader not actually adding together passes. Argh.

Ben Houston 9 years ago
parent
commit
88c3f6b2d9

+ 14 - 11
examples/js/postprocessing/MSAAPass.js

@@ -2,7 +2,7 @@
  * @author bhouston / http://clara.io/
  */
 
-THREE.MSAAPass = function ( scene, camera, params, clearColor, clearAlpha ) {
+THREE.MSAAPass = function ( scene, camera, params ) {
 
   this.scene = scene;
   this.camera = camera;
@@ -12,15 +12,9 @@ THREE.MSAAPass = function ( scene, camera, params, clearColor, clearAlpha ) {
   this.params = params || { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
   this.params.minFilter = THREE.NearestFilter;
   this.params.maxFilter = THREE.NearestFilter;
-
-  this.clearColor = clearColor;
-  this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 1;
-
-  this.oldClearColor = new THREE.Color();
-  this.oldClearAlpha = 1;
-
+  console.log( 'this.params', this.params );
   this.enabled = true;
-  this.clear = false;
+
   this.needsSwap = true;
 
   if ( THREE.CompositeShader === undefined ) {
@@ -45,6 +39,8 @@ THREE.MSAAPass = function ( scene, camera, params, clearColor, clearAlpha ) {
 
 	} );
 
+  console.log( 'this.materialComposite', this.materialComposite );
+
   this.camera2 = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
   this.scene2  = new THREE.Scene();
   this.quad2 = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), this.materialComposite );
@@ -80,13 +76,15 @@ THREE.MSAAPass.prototype = {
     this.uniforms[ "tForeground" ].value = this.sampleRenderTarget;
     this.uniforms[ "scale" ].value = 1.0 / jitterOffsets.length;
 
+    //renderer.setClearColor( new THREE.Color( 0, 0, 0 ), 0.0 );
+
     for( var i = 0; i < jitterOffsets.length; i ++ ) {
 
       if( camera.setViewOffset ) camera.setViewOffset( readBuffer.width, readBuffer.height, jitterOffsets[i].x, jitterOffsets[i].y, readBuffer.width, readBuffer.height );
 
-      renderer.render( this.scene, camera, this.sampleRenderTarget, true );
+      renderer.render( this.scene, camera, this.sampleRenderTarget, false );
 
-      renderer.render( this.scene2, this.camera2, writeBuffer, i === 0 );
+      renderer.render( this.scene2, this.camera2, writeBuffer, false );
 
     }
 
@@ -97,10 +95,15 @@ THREE.MSAAPass.prototype = {
 };
 
 THREE.MSAAPass.normalizedJitterOffsets = function( jitterVectors ) {
+
   var vectors2 = [];
+
   for( var i = 0; i < jitterVectors.length; i ++ ) {
+
     vectors2.push( new THREE.Vector2( jitterVectors[i][0], jitterVectors[i][1] ).multiplyScalar( 1.0 / 16.0 ) );
+
   }
+
   return vectors2;
 },
 

+ 1 - 8
examples/js/shaders/CompositeShader.js

@@ -10,7 +10,6 @@ THREE.CompositeShader = {
 
 	uniforms: {
 
-	//	"tBackground":   { type: "t", value: null },
 		"tForeground":   { type: "t", value: null },
     "scale":   { type: "f", value: 1.0 }
 
@@ -33,20 +32,14 @@ THREE.CompositeShader = {
 
 		"varying vec2 vUv;",
 
-//		"uniform sampler2D tBackground;",
 		"uniform sampler2D tForeground;",
 		"uniform float scale;",
 
-    "vec4 composite( vec4 foreground, vec4 background ) {",
-    	"return vec4( mix( background.rgb * background.a, foreground.rgb, foreground.a ), background.a * ( 1.0 - foreground.a ) + foreground.a );",
-    "}",
-
 		"void main() {",
 
-		//	"vec4 background = texture2D( tBackground, vUv );",
       "vec4 foreground = texture2D( tForeground, vUv );",
 
-			"gl_FragColor = foreground * scale;//composite( foreground, background ) * scale;",
+			"gl_FragColor = foreground * scale;",
 
 		"}"
 

+ 2 - 2
examples/webgl_postprocessing_msaa.html

@@ -65,8 +65,8 @@
 
 				composer = new THREE.EffectComposer( renderer );
 
-				var massPass = new THREE.MSAAPass( scene, camera, new THREE.Color( 0.0, 0.0, 0.0 ), 0.0 );
-				massPass.sampleLevel = 2;
+				var massPass = new THREE.MSAAPass( scene, camera );
+				massPass.sampleLevel = 1;
 				composer.addPass( massPass );
 
 				var copyPass = new THREE.ShaderPass( THREE.CopyShader );