forked from donmccurdy/postprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdaptiveLuminancePass.js
More file actions
158 lines (117 loc) · 3.82 KB
/
AdaptiveLuminancePass.js
File metadata and controls
158 lines (117 loc) · 3.82 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 { NearestFilter, WebGLRenderTarget } from "three";
import { AdaptiveLuminanceMaterial } from "../materials";
import { CopyPass } from "./CopyPass";
import { Pass } from "./Pass";
/**
* A pass that renders an adaptive luminance map.
*/
export class AdaptiveLuminancePass extends Pass {
/**
* Constructs a new adaptive luminance pass.
*
* @param {Texture} luminanceBuffer - A buffer that contains the current scene luminance.
* @param {Object} [options] - The options.
* @param {Number} [options.minLuminance=0.01] - The minimum luminance.
* @param {Number} [options.adaptationRate=1.0] - The luminance adaptation rate.
*/
constructor(luminanceBuffer, { minLuminance = 0.01, adaptationRate = 1.0 } = {}) {
super("AdaptiveLuminancePass");
this.fullscreenMaterial = new AdaptiveLuminanceMaterial();
this.needsSwap = false;
/**
* A 1x1 render target that stores a copy of the last adapted luminance.
*
* @type {WebGLRenderTarget}
* @private
*/
this.renderTargetPrevious = new WebGLRenderTarget(1, 1, {
minFilter: NearestFilter,
magFilter: NearestFilter,
stencilBuffer: false,
depthBuffer: false
});
this.renderTargetPrevious.texture.name = "Luminance.Previous";
const material = this.fullscreenMaterial;
material.luminanceBuffer0 = this.renderTargetPrevious.texture;
material.luminanceBuffer1 = luminanceBuffer;
material.minLuminance = minLuminance;
material.adaptationRate = adaptationRate;
/**
* A 1x1 render target that stores the adapted average luminance.
*
* @type {WebGLRenderTarget}
* @private
*/
this.renderTargetAdapted = this.renderTargetPrevious.clone();
this.renderTargetAdapted.texture.name = "Luminance.Adapted";
/**
* A save pass.
*
* @type {CopyPass}
* @private
*/
this.copyPass = new CopyPass(this.renderTargetPrevious, false);
}
/**
* The adaptive luminance texture.
*
* @type {Texture}
*/
get texture() {
return this.renderTargetAdapted.texture;
}
/**
* Returns the adaptive 1x1 luminance texture.
*
* @deprecated Use texture instead.
* @return {Texture} The texture.
*/
getTexture() {
return this.renderTargetAdapted.texture;
}
/**
* Sets the 1x1 mipmap level.
*
* This level is used to identify the smallest mipmap of the main luminance texture which contains the downsampled
* average scene luminance.
*
* @type {Number}
* @deprecated Use fullscreenMaterial.mipLevel1x1 instead.
*/
set mipLevel1x1(value) {
this.fullscreenMaterial.mipLevel1x1 = value;
}
/**
* The luminance adaptation rate.
*
* @type {Number}
* @deprecated Use fullscreenMaterial.adaptationRate instead.
*/
get adaptationRate() {
return this.fullscreenMaterial.adaptationRate;
}
/**
* @type {Number}
* @deprecated Use fullscreenMaterial.adaptationRate instead.
*/
set adaptationRate(value) {
this.fullscreenMaterial.adaptationRate = value;
}
/**
* Renders the scene normals.
*
* @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) {
// Use the frame delta time to chase after the current luminance.
this.fullscreenMaterial.deltaTime = deltaTime;
renderer.setRenderTarget(this.renderToScreen ? null : this.renderTargetAdapted);
renderer.render(this.scene, this.camera);
// Save the adapted luminance for the next frame.
this.copyPass.render(renderer, this.renderTargetAdapted);
}
}