forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathFilmPass.js
54 lines (33 loc) · 1.38 KB
/
FilmPass.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @author alteredq / http://alteredqualia.com/
*/
THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
if ( THREE.FilmShader === undefined )
console.error( "THREE.FilmPass relies on THREE.FilmShader" );
var shader = THREE.FilmShader;
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" ].value = 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 );
}
}
};