|
@@ -2,7 +2,7 @@
|
|
* @author bhouston / http://clara.io/ *
|
|
* @author bhouston / http://clara.io/ *
|
|
*/
|
|
*/
|
|
|
|
|
|
-THREE.MSAAPass = function ( scene, camera, params ) {
|
|
|
|
|
|
+THREE.ManualMSAARenderPass = function ( scene, camera, params ) {
|
|
|
|
|
|
this.scene = scene;
|
|
this.scene = scene;
|
|
this.camera = camera;
|
|
this.camera = camera;
|
|
@@ -12,7 +12,6 @@ THREE.MSAAPass = function ( scene, camera, params ) {
|
|
this.params = params || { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
|
|
this.params = params || { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
|
|
this.params.minFilter = THREE.NearestFilter;
|
|
this.params.minFilter = THREE.NearestFilter;
|
|
this.params.maxFilter = THREE.NearestFilter;
|
|
this.params.maxFilter = THREE.NearestFilter;
|
|
- console.log( 'this.params', this.params );
|
|
|
|
this.enabled = true;
|
|
this.enabled = true;
|
|
|
|
|
|
this.needsSwap = true;
|
|
this.needsSwap = true;
|
|
@@ -34,7 +33,7 @@ THREE.MSAAPass = function ( scene, camera, params ) {
|
|
transparent: true,
|
|
transparent: true,
|
|
blending: THREE.CustomBlending,
|
|
blending: THREE.CustomBlending,
|
|
blendSrc: THREE.OneFactor,
|
|
blendSrc: THREE.OneFactor,
|
|
- blendDst: THREE.OneMinusSrcAlphaFactor,
|
|
|
|
|
|
+ blendDst: THREE.OneFactor,
|
|
blendEquation: THREE.AddEquation,
|
|
blendEquation: THREE.AddEquation,
|
|
depthTest: false,
|
|
depthTest: false,
|
|
depthWrite: false
|
|
depthWrite: false
|
|
@@ -48,7 +47,7 @@ THREE.MSAAPass = function ( scene, camera, params ) {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
-THREE.MSAAPass.prototype = {
|
|
|
|
|
|
+THREE.ManualMSAARenderPass.prototype = {
|
|
|
|
|
|
dispose: function() {
|
|
dispose: function() {
|
|
|
|
|
|
@@ -70,43 +69,42 @@ THREE.MSAAPass.prototype = {
|
|
|
|
|
|
render: function ( renderer, writeBuffer, readBuffer, delta ) {
|
|
render: function ( renderer, writeBuffer, readBuffer, delta ) {
|
|
|
|
|
|
- if ( ! this.sampleRenderTarget ) {
|
|
|
|
|
|
+ var camera = ( this.camera || this.scene.camera );
|
|
|
|
+ var jitterOffsets = THREE.ManualMSAARenderPass.JitterVectors[ Math.max( 0, Math.min( this.sampleLevel, 4 ) ) ];
|
|
|
|
+
|
|
|
|
+ if( jitterOffsets.length === 1 ) {
|
|
|
|
|
|
- this.sampleRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params, "msaa.renderTarget0" );
|
|
|
|
|
|
+ renderer.render( this.scene, camera, writeBuffer, true );
|
|
|
|
+ return;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var camera = ( this.camera || this.scene.camera );
|
|
|
|
|
|
+ if ( ! this.sampleRenderTarget ) {
|
|
|
|
+
|
|
|
|
+ this.sampleRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
|
|
|
|
|
|
- var jitterOffsets = THREE.MSAAPass.JitterVectors[ Math.max( 0, Math.min( this.sampleLevel, 5 ) ) ];
|
|
|
|
|
|
+ }
|
|
|
|
|
|
var autoClear = renderer.autoClear;
|
|
var autoClear = renderer.autoClear;
|
|
renderer.autoClear = false;
|
|
renderer.autoClear = false;
|
|
|
|
|
|
|
|
+ // this accumulation strategy is used to prevent decimation at low bit depths with lots of samples.
|
|
|
|
+ this.uniforms[ "scale" ].value = 1.0 / ( jitterOffsets.length );
|
|
this.uniforms[ "tForeground" ].value = this.sampleRenderTarget;
|
|
this.uniforms[ "tForeground" ].value = this.sampleRenderTarget;
|
|
|
|
|
|
// render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
|
|
// render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
|
|
for ( var i = 0; i < jitterOffsets.length; i ++ ) {
|
|
for ( var i = 0; i < jitterOffsets.length; i ++ ) {
|
|
|
|
|
|
// only jitters perspective cameras. TODO: add support for jittering orthogonal cameras
|
|
// only jitters perspective cameras. TODO: add support for jittering orthogonal cameras
|
|
- if ( camera.setViewOffset ) camera.setViewOffset( readBuffer.width, readBuffer.height, jitterOffsets[ i ].x, jitterOffsets[ i ].y, readBuffer.width, readBuffer.height );
|
|
|
|
-
|
|
|
|
- // on first sample, no need to accumulate
|
|
|
|
- if ( i == 0 ) {
|
|
|
|
-
|
|
|
|
- renderer.render( this.scene, camera, writeBuffer, true );
|
|
|
|
-
|
|
|
|
|
|
+ var jitterOffset = jitterOffsets[i];
|
|
|
|
+ if ( camera.setViewOffset ) {
|
|
|
|
+ camera.setViewOffset( readBuffer.width, readBuffer.height,
|
|
|
|
+ jitterOffset[ 0 ] * 0.0625, jitterOffset[ 1 ] * 0.0625, // 0.0625 = 1 / 16
|
|
|
|
+ readBuffer.width, readBuffer.height );
|
|
}
|
|
}
|
|
- else {
|
|
|
|
-
|
|
|
|
- renderer.render( this.scene, camera, this.sampleRenderTarget, true );
|
|
|
|
-
|
|
|
|
- // this accumulation strategy is used to prevent decimation at low bit depths with lots of samples.
|
|
|
|
- this.uniforms[ "scale" ].value = 1.0 / ( i + 1 );
|
|
|
|
|
|
|
|
- renderer.render( this.scene2, this.camera2, writeBuffer, false );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ renderer.render( this.scene, this.camera, this.sampleRenderTarget, true );
|
|
|
|
+ renderer.render( this.scene2, this.camera2, writeBuffer, ( i === 0 ) );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -119,58 +117,29 @@ THREE.MSAAPass.prototype = {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
-THREE.MSAAPass.normalizedJitterOffsets = function( jitterVectors ) {
|
|
|
|
-
|
|
|
|
- var scaledJitterOffsets = [];
|
|
|
|
-
|
|
|
|
- for ( var i = 0; i < jitterVectors.length; i ++ ) {
|
|
|
|
-
|
|
|
|
- scaledJitterOffsets.push( new THREE.Vector2( jitterVectors[ i ][ 0 ], jitterVectors[ i ][ 1 ] ).multiplyScalar( 1.0 / 16.0 ) );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- scaledJitterOffsets.sort( function( a, b ) {
|
|
|
|
- return a.length() < b.length();
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return scaledJitterOffsets;
|
|
|
|
-
|
|
|
|
-},
|
|
|
|
-
|
|
|
|
// These jitter vectors are specified in integers because it is easier.
|
|
// These jitter vectors are specified in integers because it is easier.
|
|
// I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
|
|
// I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
|
|
// before being used, thus these integers need to be scaled by 1/16.
|
|
// before being used, thus these integers need to be scaled by 1/16.
|
|
//
|
|
//
|
|
// Sample patterns reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
|
|
// Sample patterns reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
|
|
-THREE.MSAAPass.JitterVectors = [
|
|
|
|
- THREE.MSAAPass.normalizedJitterOffsets( [
|
|
|
|
|
|
+THREE.ManualMSAARenderPass.JitterVectors = [
|
|
|
|
+ [
|
|
[ 0, 0 ]
|
|
[ 0, 0 ]
|
|
- ] ),
|
|
|
|
- THREE.MSAAPass.normalizedJitterOffsets( [
|
|
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
[ 4, 4 ], [ - 4, - 4 ]
|
|
[ 4, 4 ], [ - 4, - 4 ]
|
|
- ] ),
|
|
|
|
- THREE.MSAAPass.normalizedJitterOffsets( [
|
|
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
[ - 2, - 6 ], [ 6, - 2 ], [ - 6, 2 ], [ 2, 6 ]
|
|
[ - 2, - 6 ], [ 6, - 2 ], [ - 6, 2 ], [ 2, 6 ]
|
|
- ] ),
|
|
|
|
- THREE.MSAAPass.normalizedJitterOffsets( [
|
|
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
[ 1, - 3 ], [ - 1, 3 ], [ 5, 1 ], [ - 3, - 5 ],
|
|
[ 1, - 3 ], [ - 1, 3 ], [ 5, 1 ], [ - 3, - 5 ],
|
|
[ - 5, 5 ], [ - 7, - 1 ], [ 3, 7 ], [ 7, - 7 ]
|
|
[ - 5, 5 ], [ - 7, - 1 ], [ 3, 7 ], [ 7, - 7 ]
|
|
- ] ),
|
|
|
|
- THREE.MSAAPass.normalizedJitterOffsets( [
|
|
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
[ 1, 1 ], [ - 1, - 3 ], [ - 3, 2 ], [ 4, - 1 ],
|
|
[ 1, 1 ], [ - 1, - 3 ], [ - 3, 2 ], [ 4, - 1 ],
|
|
[ - 5, - 2 ], [ 2, 5 ], [ 5, 3 ], [ 3, - 5 ],
|
|
[ - 5, - 2 ], [ 2, 5 ], [ 5, 3 ], [ 3, - 5 ],
|
|
[ - 2, 6 ], [ 0, - 7 ], [ - 4, - 6 ], [ - 6, 4 ],
|
|
[ - 2, 6 ], [ 0, - 7 ], [ - 4, - 6 ], [ - 6, 4 ],
|
|
[ - 8, 0 ], [ 7, - 4 ], [ 6, 7 ], [ - 7, - 8 ]
|
|
[ - 8, 0 ], [ 7, - 4 ], [ 6, 7 ], [ - 7, - 8 ]
|
|
- ] ),
|
|
|
|
- THREE.MSAAPass.normalizedJitterOffsets( [
|
|
|
|
- [ - 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 ]
|
|
|
|
- ] )
|
|
|
|
-
|
|
|
|
|
|
+ ]
|
|
];
|
|
];
|