|
@@ -1,19 +1,21 @@
|
|
/**
|
|
/**
|
|
-
|
|
|
|
|
|
+ * @author alteredq / http://alteredqualia.com/
|
|
*/
|
|
*/
|
|
|
|
|
|
THREE.GlitchPass = function ( dt_size ) {
|
|
THREE.GlitchPass = function ( dt_size ) {
|
|
|
|
|
|
|
|
+ THREE.Pass.call( this );
|
|
|
|
+
|
|
if ( THREE.DigitalGlitch === undefined ) console.error( "THREE.GlitchPass relies on THREE.DigitalGlitch" );
|
|
if ( THREE.DigitalGlitch === undefined ) console.error( "THREE.GlitchPass relies on THREE.DigitalGlitch" );
|
|
-
|
|
|
|
|
|
+
|
|
var shader = THREE.DigitalGlitch;
|
|
var shader = THREE.DigitalGlitch;
|
|
this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
|
|
this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
|
|
|
|
|
|
if ( dt_size == undefined ) dt_size = 64;
|
|
if ( dt_size == undefined ) dt_size = 64;
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
this.uniforms[ "tDisp" ].value = this.generateHeightmap( dt_size );
|
|
this.uniforms[ "tDisp" ].value = this.generateHeightmap( dt_size );
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
this.material = new THREE.ShaderMaterial( {
|
|
this.material = new THREE.ShaderMaterial( {
|
|
uniforms: this.uniforms,
|
|
uniforms: this.uniforms,
|
|
@@ -21,31 +23,30 @@ THREE.GlitchPass = function ( dt_size ) {
|
|
fragmentShader: shader.fragmentShader
|
|
fragmentShader: shader.fragmentShader
|
|
} );
|
|
} );
|
|
|
|
|
|
- this.enabled = true;
|
|
|
|
- this.renderToScreen = false;
|
|
|
|
- this.needsSwap = true;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
|
|
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
|
|
this.scene = new THREE.Scene();
|
|
this.scene = new THREE.Scene();
|
|
|
|
|
|
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
|
|
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
|
|
this.scene.add( this.quad );
|
|
this.scene.add( this.quad );
|
|
-
|
|
|
|
|
|
+
|
|
this.goWild = false;
|
|
this.goWild = false;
|
|
this.curF = 0;
|
|
this.curF = 0;
|
|
this.generateTrigger();
|
|
this.generateTrigger();
|
|
-
|
|
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+THREE.GlitchPass.prototype = Object.create( THREE.Pass.prototype );
|
|
|
|
+
|
|
THREE.GlitchPass.prototype = {
|
|
THREE.GlitchPass.prototype = {
|
|
|
|
|
|
- render: function ( renderer, writeBuffer, readBuffer, delta ) {
|
|
|
|
|
|
+ constructor: THREE.GlitchPass,
|
|
|
|
+
|
|
|
|
+ render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
|
|
|
|
|
|
this.uniforms[ "tDiffuse" ].value = readBuffer;
|
|
this.uniforms[ "tDiffuse" ].value = readBuffer;
|
|
this.uniforms[ 'seed' ].value = Math.random();//default seeding
|
|
this.uniforms[ 'seed' ].value = Math.random();//default seeding
|
|
this.uniforms[ 'byp' ].value = 0;
|
|
this.uniforms[ 'byp' ].value = 0;
|
|
-
|
|
|
|
|
|
+
|
|
if ( this.curF % this.randX == 0 || this.goWild == true ) {
|
|
if ( this.curF % this.randX == 0 || this.goWild == true ) {
|
|
|
|
|
|
this.uniforms[ 'amount' ].value = Math.random() / 30;
|
|
this.uniforms[ 'amount' ].value = Math.random() / 30;
|
|
@@ -71,30 +72,33 @@ THREE.GlitchPass.prototype = {
|
|
this.uniforms[ 'byp' ].value = 1;
|
|
this.uniforms[ 'byp' ].value = 1;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
this.curF ++;
|
|
this.curF ++;
|
|
-
|
|
|
|
this.quad.material = this.material;
|
|
this.quad.material = this.material;
|
|
|
|
+
|
|
if ( this.renderToScreen ) {
|
|
if ( this.renderToScreen ) {
|
|
|
|
|
|
renderer.render( this.scene, this.camera );
|
|
renderer.render( this.scene, this.camera );
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- renderer.render( this.scene, this.camera, writeBuffer, false );
|
|
|
|
|
|
+ renderer.render( this.scene, this.camera, writeBuffer, this.clear );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
},
|
|
},
|
|
|
|
+
|
|
generateTrigger: function() {
|
|
generateTrigger: function() {
|
|
|
|
|
|
this.randX = THREE.Math.randInt( 120, 240 );
|
|
this.randX = THREE.Math.randInt( 120, 240 );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
+
|
|
generateHeightmap: function( dt_size ) {
|
|
generateHeightmap: function( dt_size ) {
|
|
|
|
|
|
var data_arr = new Float32Array( dt_size * dt_size * 3 );
|
|
var data_arr = new Float32Array( dt_size * dt_size * 3 );
|
|
var length = dt_size * dt_size;
|
|
var length = dt_size * dt_size;
|
|
-
|
|
|
|
|
|
+
|
|
for ( var i = 0; i < length; i ++ ) {
|
|
for ( var i = 0; i < length; i ++ ) {
|
|
|
|
|
|
var val = THREE.Math.randFloat( 0, 1 );
|
|
var val = THREE.Math.randFloat( 0, 1 );
|
|
@@ -103,10 +107,11 @@ THREE.GlitchPass.prototype = {
|
|
data_arr[ i * 3 + 2 ] = val;
|
|
data_arr[ i * 3 + 2 ] = val;
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
var texture = new THREE.DataTexture( data_arr, dt_size, dt_size, THREE.RGBFormat, THREE.FloatType );
|
|
var texture = new THREE.DataTexture( data_arr, dt_size, dt_size, THREE.RGBFormat, THREE.FloatType );
|
|
texture.needsUpdate = true;
|
|
texture.needsUpdate = true;
|
|
return texture;
|
|
return texture;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
};
|
|
};
|