#
luxiaotao1123
2022-03-21 4f7e5d3dc070ea46f4ca243bcbae9eda76d8c8a0
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {
    ShaderMaterial,
    UniformsUtils
} from '../../three.module.js';
import { Pass, FullScreenQuad } from '../../lib/postprocessing/Pass.js';
 
class ShaderPass extends Pass {
 
    constructor( shader, textureID ) {
 
        super();
 
        this.textureID = ( textureID !== undefined ) ? textureID : 'tDiffuse';
 
        if ( shader instanceof ShaderMaterial ) {
 
            this.uniforms = shader.uniforms;
 
            this.material = shader;
 
        } else if ( shader ) {
 
            this.uniforms = UniformsUtils.clone( shader.uniforms );
 
            this.material = new ShaderMaterial( {
 
                defines: Object.assign( {}, shader.defines ),
                uniforms: this.uniforms,
                vertexShader: shader.vertexShader,
                fragmentShader: shader.fragmentShader
 
            } );
 
        }
 
        this.fsQuad = new FullScreenQuad( this.material );
 
    }
 
    render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
 
        if ( this.uniforms[ this.textureID ] ) {
 
            this.uniforms[ this.textureID ].value = readBuffer.texture;
 
        }
 
        this.fsQuad.material = this.material;
 
        if ( this.renderToScreen ) {
 
            renderer.setRenderTarget( null );
            this.fsQuad.render( renderer );
 
        } else {
 
            renderer.setRenderTarget( writeBuffer );
            // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
            if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
            this.fsQuad.render( renderer );
 
        }
 
    }
 
}
 
export { ShaderPass };