Files
three.js/examples/js/postprocessing/FilmPass.js
T
alteredq 20fae814e7 Refactored postprocessing to use double buffering.
Cause everywhere there are warnings about not writing to the same texture which is also being read. Curiously enough this didn't make problems so far (save for mysterious lines when doing "heat" effect in ro.me).
2011-09-01 00:19:31 +02:00

51 lines
1.3 KiB
JavaScript

/**
* @author alteredq / http://alteredqualia.com/
*/
THREE.FilmPass = function( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
var shader = THREE.ShaderExtras[ "film" ];
this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
this.material = new THREE.MeshShaderMaterial( {
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
} );
if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale;
if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity;
if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
this.renderToScreen = false;
this.needsSwap = true;
};
THREE.FilmPass.prototype = {
render: function ( renderer, writeBuffer, readBuffer, delta ) {
this.uniforms[ "tDiffuse" ].texture = readBuffer;
this.uniforms[ "time" ].value += delta;
THREE.EffectComposer.quad.materials[ 0 ] = this.material;
if ( this.renderToScreen ) {
renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera );
} else {
renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, false );
}
}
};