ShaderPass.js 1.1 KB
Newer Older
A
alteredq 已提交
1 2 3 4
/**
 * @author alteredq / http://alteredqualia.com/
 */

M
Mr.doob 已提交
5
THREE.ShaderPass = function ( shader, textureID ) {
A
alteredq 已提交
6

7
	this.textureID = ( textureID !== undefined ) ? textureID : "tDiffuse";
A
alteredq 已提交
8 9 10

	this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );

11
	this.material = new THREE.ShaderMaterial( {
A
alteredq 已提交
12 13 14 15 16 17 18 19

		uniforms: this.uniforms,
		vertexShader: shader.vertexShader,
		fragmentShader: shader.fragmentShader

	} );

	this.renderToScreen = false;
20 21

	this.enabled = true;
22
	this.needsSwap = true;
23
	this.clear = false;
A
alteredq 已提交
24

25 26 27 28 29 30 31

	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
	this.scene  = new THREE.Scene();

	this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
	this.scene.add( this.quad );

A
alteredq 已提交
32 33
};

34
THREE.ShaderPass.prototype = {
A
alteredq 已提交
35

36
	render: function ( renderer, writeBuffer, readBuffer, delta ) {
A
alteredq 已提交
37

38 39
		if ( this.uniforms[ this.textureID ] ) {

40
			this.uniforms[ this.textureID ].value = readBuffer;
41 42

		}
A
alteredq 已提交
43

44
		this.quad.material = this.material;
A
alteredq 已提交
45 46 47

		if ( this.renderToScreen ) {

48
			renderer.render( this.scene, this.camera );
A
alteredq 已提交
49 50 51

		} else {

52
			renderer.render( this.scene, this.camera, writeBuffer, this.clear );
A
alteredq 已提交
53 54 55 56 57 58

		}

	}

};