forked from donmccurdy/postprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuminancePass.js
More file actions
158 lines (116 loc) · 3.63 KB
/
LuminancePass.js
File metadata and controls
158 lines (116 loc) · 3.63 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { LinearFilter, UnsignedByteType, WebGLRenderTarget } from "three";
import { LuminanceMaterial } from "../materials";
import { Resolution } from "../core/Resolution";
import { Pass } from "./Pass";
/**
* A pass that renders luminance.
*/
export class LuminancePass extends Pass {
/**
* Constructs a new luminance pass.
*
* @param {Object} [options] - The options. See {@link LuminanceMaterial} for additional options.
* @param {Number} [options.width=Resolution.AUTO_SIZE] - The render width.
* @param {Number} [options.height=Resolution.AUTO_SIZE] - The render height.
* @param {WebGLRenderTarget} [options.renderTarget] - A custom render target.
*/
constructor({
width = Resolution.AUTO_SIZE,
height = Resolution.AUTO_SIZE,
renderTarget,
luminanceRange,
colorOutput
} = {}) {
super("LuminancePass");
this.fullscreenMaterial = new LuminanceMaterial(colorOutput, luminanceRange);
this.needsSwap = false;
/**
* The luminance render target.
*
* @type {WebGLRenderTarget}
* @private
*/
this.renderTarget = renderTarget;
if(this.renderTarget === undefined) {
this.renderTarget = new WebGLRenderTarget(1, 1, {
minFilter: LinearFilter,
magFilter: LinearFilter,
stencilBuffer: false,
depthBuffer: false
});
this.renderTarget.texture.name = "LuminancePass.Target";
this.renderTarget.texture.generateMipmaps = false;
}
/**
* The resolution.
*
* @type {Resolution}
*/
const resolution = this.resolution = new Resolution(this, width, height);
resolution.addEventListener("change", (e) => this.setSize(resolution.baseWidth, resolution.baseHeight));
}
/**
* The luminance texture.
*
* @type {Texture}
*/
get texture() {
return this.renderTarget.texture;
}
/**
* Returns the luminance texture.
*
* @deprecated Use texture instead.
* @return {Texture} The texture.
*/
getTexture() {
return this.renderTarget.texture;
}
/**
* Returns the resolution settings.
*
* @deprecated Use resolution instead.
* @return {Resolution} The resolution.
*/
getResolution() {
return this.resolution;
}
/**
* Renders the luminance.
*
* @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) {
const material = this.fullscreenMaterial;
material.inputBuffer = inputBuffer.texture;
renderer.setRenderTarget(this.renderToScreen ? null : this.renderTarget);
renderer.render(this.scene, this.camera);
}
/**
* Updates the size of this pass.
*
* @param {Number} width - The width.
* @param {Number} height - The height.
*/
setSize(width, height) {
const resolution = this.resolution;
resolution.setBaseSize(width, height);
this.renderTarget.setSize(resolution.width, resolution.height);
}
/**
* 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";
}
}
}