Permalink
Browse files

adding files for postprocessing

  • Loading branch information...
1 parent 9681801 commit ff2b4928a5c8f3e455debd66375217c11a140756 @jeromeetienne committed Jan 16, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,100 @@
+/**
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.BloomPass = function( strength, kernelSize, sigma, resolution ) {
+
+ strength = ( strength !== undefined ) ? strength : 1;
+ kernelSize = ( kernelSize !== undefined ) ? kernelSize : 25;
+ sigma = ( sigma !== undefined ) ? sigma : 4.0;
+ resolution = ( resolution !== undefined ) ? resolution : 256;
+
+ // render targets
+
+ var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat };
+
+ this.renderTargetX = new THREE.WebGLRenderTarget( resolution, resolution, pars );
+ this.renderTargetY = new THREE.WebGLRenderTarget( resolution, resolution, pars );
+
+ // screen material
+
+ var screenShader = THREE.ShaderExtras[ "screen" ];
+
+ this.screenUniforms = THREE.UniformsUtils.clone( screenShader.uniforms );
+
+ this.screenUniforms[ "opacity" ].value = strength;
+
+ this.materialScreen = new THREE.ShaderMaterial( {
+
+ uniforms: this.screenUniforms,
+ vertexShader: screenShader.vertexShader,
+ fragmentShader: screenShader.fragmentShader,
+ blending: THREE.AdditiveBlending,
+ transparent: true
+
+ } );
+
+ // convolution material
+
+ var convolutionShader = THREE.ShaderExtras[ "convolution" ];
+
+ this.convolutionUniforms = THREE.UniformsUtils.clone( convolutionShader.uniforms );
+
+ this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurx;
+ this.convolutionUniforms[ "cKernel" ].value = THREE.ShaderExtras.buildKernel( sigma );
+
+ this.materialConvolution = new THREE.ShaderMaterial( {
+
+ uniforms: this.convolutionUniforms,
+ vertexShader: "#define KERNEL_SIZE " + kernelSize + ".0\n" + convolutionShader.vertexShader,
+ fragmentShader: "#define KERNEL_SIZE " + kernelSize + "\n" + convolutionShader.fragmentShader
+
+ } );
+
+ this.enabled = true;
+ this.needsSwap = false;
+ this.clear = false;
+
+};
+
+THREE.BloomPass.prototype = {
+
+ render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
+
+ if ( maskActive ) renderer.context.disable( renderer.context.STENCIL_TEST );
+
+ // Render quad with blured scene into texture (convolution pass 1)
+
+ THREE.EffectComposer.quad.material = this.materialConvolution;
+
+ this.convolutionUniforms[ "tDiffuse" ].texture = readBuffer;
+ this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurX;
+
+ renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, this.renderTargetX, true );
+
+
+ // Render quad with blured scene into texture (convolution pass 2)
+
+ this.convolutionUniforms[ "tDiffuse" ].texture = this.renderTargetX;
+ this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurY;
+
+ renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, this.renderTargetY, true );
+
+ // Render original scene with superimposed blur to texture
+
+ THREE.EffectComposer.quad.material = this.materialScreen;
+
+ this.screenUniforms[ "tDiffuse" ].texture = this.renderTargetY;
+
+ if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST );
+
+ renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, readBuffer, this.clear );
+
+ }
+
+};
+
+THREE.BloomPass.blurX = new THREE.Vector2( 0.001953125, 0.0 );
+THREE.BloomPass.blurY = new THREE.Vector2( 0.0, 0.001953125 );
+
+
@@ -0,0 +1,52 @@
+/**
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.DotScreenPass = function( center, angle, scale ) {
+
+ var shader = THREE.ShaderExtras[ "dotscreen" ];
+
+ this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
+
+ if ( center !== undefined )
+ this.uniforms[ "center" ].value.copy( center );
+
+ if ( angle !== undefined ) this.uniforms[ "angle"].value = angle;
+ if ( scale !== undefined ) this.uniforms[ "scale"].value = scale;
+
+ this.material = new THREE.ShaderMaterial( {
+
+ uniforms: this.uniforms,
+ vertexShader: shader.vertexShader,
+ fragmentShader: shader.fragmentShader
+
+ } );
+
+ this.enabled = true;
+ this.renderToScreen = false;
+ this.needsSwap = true;
+
+};
+
+THREE.DotScreenPass.prototype = {
+
+ render: function ( renderer, writeBuffer, readBuffer, delta ) {
+
+ this.uniforms[ "tDiffuse" ].texture = readBuffer;
+ this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height );
+
+ THREE.EffectComposer.quad.material = this.material;
+
+ if ( this.renderToScreen ) {
+
+ renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera );
+
+ } else {
+
+ renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, false );
+
+ }
+
+ }
+
+};
@@ -0,0 +1,136 @@
+/**
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.EffectComposer = function( renderer, renderTarget ) {
+
+ this.renderer = renderer;
+
+ this.renderTarget1 = renderTarget;
+
+ if ( this.renderTarget1 === undefined ) {
+
+ this.renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBufer: false };
+ this.renderTarget1 = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, this.renderTargetParameters );
+
+ }
+
+ this.renderTarget2 = this.renderTarget1.clone();
+
+ this.writeBuffer = this.renderTarget1;
+ this.readBuffer = this.renderTarget2;
+
+ this.passes = [];
+
+ this.copyPass = new THREE.ShaderPass( THREE.ShaderExtras[ "screen" ] );
+
+};
+
+THREE.EffectComposer.prototype = {
+
+ swapBuffers: function() {
+
+ var tmp = this.readBuffer;
+ this.readBuffer = this.writeBuffer;
+ this.writeBuffer = tmp;
+
+ },
+
+ addPass: function ( pass ) {
+
+ this.passes.push( pass );
+
+ },
+
+ render: function ( delta ) {
+
+ this.writeBuffer = this.renderTarget1;
+ this.readBuffer = this.renderTarget2;
+
+ var maskActive = false;
+
+ var pass, i, il = this.passes.length;
+
+ for ( i = 0; i < il; i ++ ) {
+
+ pass = this.passes[ i ];
+
+ if ( !pass.enabled ) continue;
+
+ pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive );
+
+ if ( pass.needsSwap ) {
+
+ if ( maskActive ) {
+
+ var context = this.renderer.context;
+
+ context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
+
+ this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, delta );
+
+ context.stencilFunc( context.EQUAL, 1, 0xffffffff );
+
+ }
+
+ this.swapBuffers();
+
+ }
+
+ if ( pass instanceof THREE.MaskPass ) {
+
+ maskActive = true;
+
+ } else if ( pass instanceof THREE.ClearMaskPass ) {
+
+ maskActive = false;
+
+ }
+
+ }
+
+ },
+
+ reset: function ( renderTarget ) {
+
+ this.renderTarget1 = renderTarget;
+
+ if ( this.renderTarget1 === undefined ) {
+
+ this.renderTarget1 = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, this.renderTargetParameters );
+
+ }
+
+ this.renderTarget2 = this.renderTarget1.clone();
+
+ this.writeBuffer = this.renderTarget1;
+ this.readBuffer = this.renderTarget2;
+
+ THREE.EffectComposer.quad.scale.set( window.innerWidth, window.innerHeight, 1 );
+
+ THREE.EffectComposer.camera.left = window.innerWidth / - 2;
+ THREE.EffectComposer.camera.right = window.innerWidth / 2;
+ THREE.EffectComposer.camera.top = window.innerHeight / 2;
+ THREE.EffectComposer.camera.bottom = window.innerHeight / - 2;
+
+ THREE.EffectComposer.camera.updateProjectionMatrix();
+
+ }
+
+};
+
+// shared ortho camera
+
+THREE.EffectComposer.camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -10000, 10000 );
+
+// shared fullscreen quad scene
+
+THREE.EffectComposer.geometry = new THREE.PlaneGeometry( 1, 1 );
+
+THREE.EffectComposer.quad = new THREE.Mesh( THREE.EffectComposer.geometry, null );
+THREE.EffectComposer.quad.position.z = -100;
+THREE.EffectComposer.quad.scale.set( window.innerWidth, window.innerHeight, 1 );
+
+THREE.EffectComposer.scene = new THREE.Scene();
+THREE.EffectComposer.scene.add( THREE.EffectComposer.quad );
+THREE.EffectComposer.scene.add( THREE.EffectComposer.camera );
@@ -0,0 +1,51 @@
+/**
+ * @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.ShaderMaterial( {
+
+ 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.enabled = true;
+ 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.material = this.material;
+
+ if ( this.renderToScreen ) {
+
+ renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera );
+
+ } else {
+
+ renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, false );
+
+ }
+
+ }
+
+};
Oops, something went wrong.

0 comments on commit ff2b492

Please sign in to comment.