forked from donmccurdy/postprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShaderPass.js
More file actions
106 lines (73 loc) · 2.6 KB
/
ShaderPass.js
File metadata and controls
106 lines (73 loc) · 2.6 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { UnsignedByteType } from "three";
import { Pass } from "./Pass";
/**
* A shader pass.
*
* Renders any shader material as a fullscreen effect. This pass should not be used to create multiple chained effects.
* For a more efficient solution, please refer to the {@link EffectPass}.
*/
export class ShaderPass extends Pass {
/**
* Constructs a new shader pass.
*
* @param {ShaderMaterial} material - A shader material.
* @param {String} [input="inputBuffer"] - The name of the input buffer uniform.
*/
constructor(material, input = "inputBuffer") {
super("ShaderPass");
this.fullscreenMaterial = material;
/**
* The input buffer uniform.
*
* @type {String}
* @private
*/
this.inputBufferUniform = null;
this.setInput(input);
}
/**
* Sets the name of the input buffer uniform.
*
* Most fullscreen materials modify texels from an input texture. This pass automatically assigns the main input
* buffer to the uniform identified by the given name.
*
* @param {String} input - The name of the input buffer uniform.
*/
setInput(input) {
this.inputBufferUniform = null;
if(this.fullscreenMaterial !== null) {
const uniforms = this.fullscreenMaterial.uniforms;
if(uniforms !== undefined && uniforms[input] !== undefined) {
this.inputBufferUniform = uniforms[input];
}
}
}
/**
* Renders the effect.
*
* @param {WebGLRenderer} renderer - The renderer.
* @param {WebGLRenderTarget} inputBuffer - A frame buffer that contains the result of the previous pass.
* @param {WebGLRenderTarget} outputBuffer - A frame buffer that serves as the output render target unless this pass renders to screen.
* @param {Number} [deltaTime] - The time between the last frame and the current one in seconds.
* @param {Boolean} [stencilTest] - Indicates whether a stencil mask is active.
*/
render(renderer, inputBuffer, outputBuffer, deltaTime, stencilTest) {
if(this.inputBufferUniform !== null && inputBuffer !== null) {
this.inputBufferUniform.value = inputBuffer.texture;
}
renderer.setRenderTarget(this.renderToScreen ? null : outputBuffer);
renderer.render(this.scene, this.camera);
}
/**
* Performs initialization tasks.
*
* @param {WebGLRenderer} renderer - A renderer.
* @param {Boolean} alpha - Whether the renderer uses the alpha channel.
* @param {Number} frameBufferType - The type of the main frame buffers.
*/
initialize(renderer, alpha, frameBufferType) {
if(frameBufferType !== undefined && frameBufferType !== UnsignedByteType) {
this.fullscreenMaterial.defines.FRAMEBUFFER_PRECISION_HIGH = "1";
}
}
}