Kaynağa Gözat

add back 32 sample level, simplify TAARenderPass via reusing shader from ManualMSAAREnderPAss.

Ben Houston 9 yıl önce
ebeveyn
işleme
345ff94536

+ 11 - 1
examples/js/postprocessing/ManualMSAARenderPass.js

@@ -82,7 +82,7 @@ THREE.ManualMSAARenderPass.prototype = {
 	render: function ( renderer, writeBuffer, readBuffer, delta ) {
 
 		var camera = ( this.camera || this.scene.camera );
-		var jitterOffsets = THREE.ManualMSAARenderPass.JitterVectors[ Math.max( 0, Math.min( this.sampleLevel, 4 ) ) ];
+		var jitterOffsets = THREE.ManualMSAARenderPass.JitterVectors[ Math.max( 0, Math.min( this.sampleLevel, 5 ) ) ];
 
 		if( jitterOffsets.length === 1 ) {
 
@@ -152,5 +152,15 @@ THREE.ManualMSAARenderPass.JitterVectors = [
 		[ - 5, - 2 ], [ 2, 5 ], [ 5, 3 ], [ 3, - 5 ],
 		[ - 2, 6 ], [ 0, - 7 ], [ - 4, - 6 ], [ - 6, 4 ],
 		[ - 8, 0 ], [ 7, - 4 ], [ 6, 7 ], [ - 7, - 8 ]
+	],
+	[
+		[ - 4, - 7 ], [ - 7, - 5 ], [ - 3, - 5 ], [ - 5, - 4 ],
+		[ - 1, - 4 ], [ - 2, - 2 ], [ - 6, - 1 ], [ - 4, 0 ],
+		[ - 7, 1 ], [ - 1, 2 ], [ - 6, 3 ], [ - 3, 3 ],
+		[ - 7, 6 ], [ - 3, 6 ], [ - 5, 7 ], [ - 1, 7 ],
+		[ 5, - 7 ], [ 1, - 6 ], [ 6, - 5 ], [ 4, - 4 ],
+		[ 2, - 3 ], [ 7, - 2 ], [ 1, - 1 ], [ 4, - 1 ],
+		[ 2, 1 ], [ 6, 2 ], [ 0, 4 ], [ 4, 4 ],
+		[ 2, 5 ], [ 7, 5 ], [ 5, 6 ], [ 3, 7 ]
 	]
 ];

+ 12 - 42
examples/js/postprocessing/TAARenderPass.js

@@ -21,39 +21,9 @@ THREE.TAARenderPass = function ( scene, camera, params ) {
 	}
 	THREE.ManualMSAARenderPass.call( this, scene, camera, params );
 
-	this.sampleLevel = 1;
+	this.sampleLevel = 0;
 	this.accumulate = false;
-
-	if ( THREE.CompositeShader === undefined ) {
-
-		console.error( "THREE.TAARenderPass relies on THREE.CompositeShader" );
-
-	}
-
-	var accumulateShader = THREE.CompositeShader;
-	this.accumulateUniforms = THREE.UniformsUtils.clone( accumulateShader.uniforms );
-
-	this.materialAccumulate = new THREE.ShaderMaterial(	{
-
-		uniforms: this.accumulateUniforms,
-		vertexShader: accumulateShader.vertexShader,
-		fragmentShader: accumulateShader.fragmentShader,
-		transparent: true,
-		blending: THREE.CustomBlending,
-		blendSrc: THREE.OneFactor,
-		blendDst: THREE.OneFactor,
-		blendSrcAlpha: THREE.OneFactor,
-		blendDstAlpha: THREE.OneFactor,
-		blendEquation: THREE.AddEquation,
-		depthTest: false,
-		depthWrite: false
-
-	} );
-
-	this.scene3	= new THREE.Scene();
-	this.quad3 = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), this.materialAccumulate );
-	this.scene3.add( this.quad3 );
-
+	
 };
 
 THREE.TAARenderPass.prototype = Object.create( THREE.ManualMSAARenderPass.prototype );
@@ -71,7 +41,7 @@ THREE.TAARenderPass.prototype.render = function ( renderer, writeBuffer, readBuf
 
 	}
 
-	var jitterOffsets = THREE.TAARenderPass.JitterVectors[ 4 ];
+	var jitterOffsets = THREE.TAARenderPass.JitterVectors[ 5 ];
 
 	var camera = ( this.camera || this.scene.camera );
 
@@ -102,8 +72,8 @@ THREE.TAARenderPass.prototype.render = function ( renderer, writeBuffer, readBuf
 
 	if( this.accumulateIndex >= 0 && this.accumulateIndex < jitterOffsets.length ) {
 
-		this.accumulateUniforms[ "scale" ].value = sampleWeight;
-		this.accumulateUniforms[ "tForeground" ].value = writeBuffer;
+		this.compositeUniforms[ "scale" ].value = sampleWeight;
+		this.compositeUniforms[ "tForeground" ].value = writeBuffer;
 
 		// render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
 		var numSamplesPerFrame = Math.pow( 2, this.sampleLevel );
@@ -120,7 +90,7 @@ THREE.TAARenderPass.prototype.render = function ( renderer, writeBuffer, readBuf
 
 			renderer.render( this.scene, this.camera, writeBuffer, true );
 
-			renderer.render( this.scene3, this.camera2, this.sampleRenderTarget, ( this.accumulateIndex == 0 ) );
+			renderer.render( this.scene2, this.camera2, this.sampleRenderTarget, ( this.accumulateIndex == 0 ) );
 
 			this.accumulateIndex ++;
 			if( this.accumulateIndex >= jitterOffsets.length ) break;
@@ -134,15 +104,15 @@ THREE.TAARenderPass.prototype.render = function ( renderer, writeBuffer, readBuf
 	var accumulationWeight = this.accumulateIndex * sampleWeight;
 
 	if( accumulationWeight > 0 ) {
-		this.accumulateUniforms[ "scale" ].value = 1.0;
-		this.accumulateUniforms[ "tForeground" ].value = this.sampleRenderTarget;
-		renderer.render( this.scene3, this.camera2, writeBuffer, true );
+		this.compositeUniforms[ "scale" ].value = 1.0;
+		this.compositeUniforms[ "tForeground" ].value = this.sampleRenderTarget;
+		renderer.render( this.scene2, this.camera2, writeBuffer, true );
 	}
 
 	if( accumulationWeight < 1.0 ) {
-		this.accumulateUniforms[ "scale" ].value = 1.0 - accumulationWeight;
-		this.accumulateUniforms[ "tForeground" ].value = this.holdRenderTarget;
-		renderer.render( this.scene3, this.camera2, writeBuffer, ( accumulationWeight === 0 ) );
+		this.compositeUniforms[ "scale" ].value = 1.0 - accumulationWeight;
+		this.compositeUniforms[ "tForeground" ].value = this.holdRenderTarget;
+		renderer.render( this.scene2, this.camera2, writeBuffer, ( accumulationWeight === 0 ) );
 	}
 
 	renderer.autoClear = autoClear;

+ 2 - 1
examples/webgl_postprocessing_msaa.html

@@ -72,7 +72,8 @@
 					'Level 1: 2 Samples': 1,
 					'Level 2: 4 Samples': 2,
 					'Level 3: 8 Samples': 3,
-					'Level 4: 16 Samples': 4
+					'Level 4: 16 Samples': 4,
+					'Level 5: 32 Samples': 5
 				} ).onFinishChange( function() {
 
 					if( msaaRenderPass ) {

+ 2 - 1
examples/webgl_postprocessing_taa.html

@@ -88,7 +88,8 @@
 					'Level 1: 2 Samples': 1,
 					'Level 2: 4 Samples': 2,
 					'Level 3: 8 Samples': 3,
-					'Level 4: 16 Samples': 4
+					'Level 4: 16 Samples': 4,
+					'Level 5: 32 Samples': 5
 				} ).onFinishChange( function() {
 
 					if( taaRenderPass ) {