@takram/three-geospatial-effects 0.0.1-alpha.5 → 0.0.1-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/r3f.cjs +18 -18
- package/build/r3f.cjs.map +1 -1
- package/build/r3f.js +67 -65
- package/build/r3f.js.map +1 -1
- package/build/shared.cjs +70 -72
- package/build/shared.cjs.map +1 -1
- package/build/shared.js +227 -221
- package/build/shared.js.map +1 -1
- package/package.json +2 -2
- package/src/DepthEffect.ts +22 -18
- package/src/DitheringEffect.ts +1 -5
- package/src/DownsampleThresholdMaterial.ts +10 -11
- package/src/GeometryEffect.ts +19 -15
- package/src/LensFlareEffect.ts +34 -27
- package/src/LensFlareFeaturesMaterial.ts +12 -14
- package/src/NormalEffect.ts +30 -26
- package/src/setupMaterialsForGeometryPass.ts +4 -6
- package/src/shaders/depthEffect.frag +4 -11
- package/src/shaders/downsampleThreshold.frag +14 -16
- package/src/shaders/geometryEffect.frag +4 -2
- package/src/shaders/lensFlareEffect.frag +3 -6
- package/src/shaders/lensFlareFeatures.frag +4 -4
- package/src/shaders/normalEffect.frag +8 -4
- package/types/DepthEffect.d.ts +7 -0
- package/types/GeometryEffect.d.ts +6 -1
- package/types/LensFlareEffect.d.ts +9 -2
- package/types/NormalEffect.d.ts +8 -1
package/build/shared.js
CHANGED
@@ -1,19 +1,16 @@
|
|
1
|
-
var
|
2
|
-
var
|
3
|
-
var
|
4
|
-
import { BlendFunction as f, Effect as h, EffectAttribute as p, RenderPass as
|
5
|
-
import { Uniform as
|
6
|
-
import {
|
7
|
-
|
1
|
+
var D = Object.defineProperty;
|
2
|
+
var y = (r, e, t) => e in r ? D(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
3
|
+
var u = (r, e, t) => y(r, typeof e != "symbol" ? e + "" : e, t);
|
4
|
+
import { BlendFunction as f, Effect as h, EffectAttribute as p, RenderPass as M, Resolution as d, ShaderPass as g, MipmapBlurPass as P, KawaseBlurPass as A, KernelSize as z } from "postprocessing";
|
5
|
+
import { Uniform as s, ShaderLib as c, HalfFloatType as m, ShaderMaterial as U, NoBlending as T, Vector2 as S, WebGLRenderTarget as w, Matrix4 as x } from "three";
|
6
|
+
import { resolveIncludes as b } from "@takram/three-geospatial";
|
7
|
+
import { turbo as F, depth as B, packing as C, transform as O } from "@takram/three-geospatial/shaders";
|
8
|
+
const N = `#include "core/depth"
|
9
|
+
#include "core/turbo"
|
10
|
+
|
11
|
+
uniform float near;
|
8
12
|
uniform float far;
|
9
13
|
|
10
|
-
vec3 turbo(const float x) {
|
11
|
-
float r = 0.1357 + x * (4.5974 - x * (42.3277 - x * (130.5887 - x * (150.5666 - x * 58.1375))));
|
12
|
-
float g = 0.0914 + x * (2.1856 + x * (4.8052 - x * (14.0195 - x * (4.2109 + x * 2.7747))));
|
13
|
-
float b = 0.1067 + x * (12.5925 - x * (60.1097 - x * (109.0745 - x * (88.5066 - x * 26.8183))));
|
14
|
-
return vec3(r, g, b);
|
15
|
-
}
|
16
|
-
|
17
14
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
18
15
|
float depth = readDepth(uv);
|
19
16
|
depth = reverseLogDepth(depth, cameraNear, cameraFar);
|
@@ -21,40 +18,40 @@ void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
|
21
18
|
|
22
19
|
#ifdef USE_TURBO
|
23
20
|
vec3 color = turbo(1.0 - depth);
|
24
|
-
#else
|
21
|
+
#else // USE_TURBO
|
25
22
|
vec3 color = vec3(depth);
|
26
|
-
#endif
|
23
|
+
#endif // USE_TURBO
|
27
24
|
|
28
25
|
outputColor = vec4(color, inputColor.a);
|
29
|
-
}
|
30
|
-
|
26
|
+
}
|
27
|
+
`, L = {
|
31
28
|
blendFunction: f.SRC,
|
32
29
|
useTurbo: !1,
|
33
30
|
near: 1,
|
34
31
|
far: 1e3
|
35
32
|
};
|
36
|
-
class
|
33
|
+
class se extends h {
|
37
34
|
constructor(e) {
|
38
|
-
const { blendFunction: t, useTurbo:
|
35
|
+
const { blendFunction: t, useTurbo: n, near: o, far: i } = {
|
39
36
|
...L,
|
40
37
|
...e
|
41
38
|
};
|
42
39
|
super(
|
43
40
|
"DepthEffect",
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
${A}
|
48
|
-
`,
|
41
|
+
b(N, {
|
42
|
+
core: { depth: B, turbo: F }
|
43
|
+
}),
|
49
44
|
{
|
50
45
|
blendFunction: t,
|
51
46
|
attributes: p.DEPTH,
|
52
|
-
uniforms:
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
uniforms: new Map(
|
48
|
+
Object.entries({
|
49
|
+
near: new s(o),
|
50
|
+
far: new s(i)
|
51
|
+
})
|
52
|
+
)
|
56
53
|
}
|
57
|
-
), this.useTurbo =
|
54
|
+
), this.useTurbo = n;
|
58
55
|
}
|
59
56
|
get useTurbo() {
|
60
57
|
return this.defines.has("USE_TURBO");
|
@@ -75,30 +72,30 @@ class re extends h {
|
|
75
72
|
this.uniforms.get("far").value = e;
|
76
73
|
}
|
77
74
|
}
|
78
|
-
|
75
|
+
const G = `#define DITHERING
|
79
76
|
|
80
77
|
#include <dithering_pars_fragment>
|
81
78
|
|
82
79
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
83
80
|
outputColor = vec4(saturate(dithering(inputColor.rgb)), inputColor.a);
|
84
|
-
}
|
85
|
-
|
81
|
+
}
|
82
|
+
`, j = {
|
86
83
|
blendFunction: f.NORMAL
|
87
84
|
};
|
88
|
-
class
|
85
|
+
class ae extends h {
|
89
86
|
constructor(e) {
|
90
87
|
const { blendFunction: t } = {
|
91
|
-
...
|
88
|
+
...j,
|
92
89
|
...e
|
93
90
|
};
|
94
|
-
super("DitheringEffect",
|
91
|
+
super("DitheringEffect", G, {
|
95
92
|
blendFunction: t
|
96
93
|
});
|
97
94
|
}
|
98
95
|
}
|
99
96
|
const R = Symbol("SETUP");
|
100
|
-
function
|
101
|
-
const e =
|
97
|
+
function H(r) {
|
98
|
+
const e = r.vertexShader.replace(
|
102
99
|
/* glsl */
|
103
100
|
"#include <fog_pars_vertex>",
|
104
101
|
/* glsl */
|
@@ -128,13 +125,13 @@ function G(o) {
|
|
128
125
|
vViewPosition = - mvPosition.xyz;
|
129
126
|
`
|
130
127
|
);
|
131
|
-
|
128
|
+
r.vertexShader = /* glsl */
|
132
129
|
`
|
133
130
|
#undef FLAT_SHADED
|
134
131
|
varying vec3 vViewPosition;
|
135
132
|
${e}
|
136
133
|
`;
|
137
|
-
const t =
|
134
|
+
const t = r.fragmentShader.replace(
|
138
135
|
/#ifndef FLAT_SHADED\s+varying vec3 vNormal;\s+#endif/m,
|
139
136
|
/* glsl */
|
140
137
|
"#include <normal_pars_fragment>"
|
@@ -156,17 +153,17 @@ function G(o) {
|
|
156
153
|
#include <normal_fragment_maps>
|
157
154
|
`
|
158
155
|
);
|
159
|
-
return
|
156
|
+
return r.fragmentShader = /* glsl */
|
160
157
|
`
|
161
158
|
#undef FLAT_SHADED
|
162
159
|
varying vec3 vViewPosition;
|
163
160
|
${t}
|
164
|
-
`,
|
161
|
+
`, r;
|
165
162
|
}
|
166
|
-
function v(
|
167
|
-
if (
|
168
|
-
return
|
169
|
-
e === "basic" &&
|
163
|
+
function v(r, { type: e } = {}) {
|
164
|
+
if (r[R] === !0)
|
165
|
+
return r;
|
166
|
+
e === "basic" && H(r);
|
170
167
|
const t = e === "physical" ? (
|
171
168
|
/* glsl */
|
172
169
|
`
|
@@ -186,16 +183,16 @@ function v(o, { type: e } = {}) {
|
|
186
183
|
);
|
187
184
|
`
|
188
185
|
);
|
189
|
-
return
|
186
|
+
return r.fragmentShader = /* glsl */
|
190
187
|
`
|
191
188
|
layout(location = 1) out vec4 outputBuffer1;
|
192
189
|
|
193
|
-
#
|
190
|
+
#if !defined(USE_ENVMAP)
|
194
191
|
uniform float reflectivity;
|
195
|
-
#endif
|
192
|
+
#endif // !defined(USE_ENVMAP)
|
196
193
|
|
197
|
-
${
|
198
|
-
${
|
194
|
+
${C}
|
195
|
+
${r.fragmentShader.replace(
|
199
196
|
/}\s*$/m,
|
200
197
|
// Assume the last curly brace is of main()
|
201
198
|
/* glsl */
|
@@ -204,25 +201,25 @@ function v(o, { type: e } = {}) {
|
|
204
201
|
}
|
205
202
|
`
|
206
203
|
)}
|
207
|
-
`,
|
204
|
+
`, r[R] = !0, r;
|
208
205
|
}
|
209
|
-
function
|
206
|
+
function I() {
|
210
207
|
v(c.lambert), v(c.phong), v(c.basic, { type: "basic" }), v(c.standard, { type: "physical" }), v(c.physical, { type: "physical" });
|
211
208
|
}
|
212
|
-
class
|
213
|
-
constructor(t,
|
214
|
-
super(
|
215
|
-
|
216
|
-
this.geometryTexture = t.texture.clone(), this.geometryTexture.isRenderTargetTexture = !0, this.geometryTexture.type = m,
|
209
|
+
class ue extends M {
|
210
|
+
constructor(t, n, o, i) {
|
211
|
+
super(n, o, i);
|
212
|
+
u(this, "geometryTexture");
|
213
|
+
this.geometryTexture = t.texture.clone(), this.geometryTexture.isRenderTargetTexture = !0, this.geometryTexture.type = m, I();
|
217
214
|
}
|
218
|
-
render(t,
|
219
|
-
|
215
|
+
render(t, n, o, i, a) {
|
216
|
+
n != null && (n.textures[1] = this.geometryTexture), super.render(t, n, null), n != null && (n.textures.length = 1);
|
220
217
|
}
|
221
|
-
setSize(t,
|
222
|
-
this.geometryTexture.image.width = t, this.geometryTexture.image.height =
|
218
|
+
setSize(t, n) {
|
219
|
+
this.geometryTexture.image.width = t, this.geometryTexture.image.height = n;
|
223
220
|
}
|
224
221
|
}
|
225
|
-
|
222
|
+
const V = `#include <common>
|
226
223
|
|
227
224
|
uniform sampler2D inputBuffer;
|
228
225
|
|
@@ -247,8 +244,9 @@ float clampToBorder(const vec2 uv) {
|
|
247
244
|
return float(uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0);
|
248
245
|
}
|
249
246
|
|
247
|
+
// Reference: https://learnopengl.com/Guest-Articles/2022/Phys.-Based-Bloom
|
250
248
|
void main() {
|
251
|
-
vec3 color = 0.125 *
|
249
|
+
vec3 color = 0.125 * texture(inputBuffer, vec2(vRowUv5)).rgb;
|
252
250
|
vec4 weight =
|
253
251
|
0.03125 *
|
254
252
|
vec4(
|
@@ -257,10 +255,10 @@ void main() {
|
|
257
255
|
clampToBorder(vRowUv7),
|
258
256
|
clampToBorder(vRowUv9)
|
259
257
|
);
|
260
|
-
color += weight.x *
|
261
|
-
color += weight.y *
|
262
|
-
color += weight.z *
|
263
|
-
color += weight.w *
|
258
|
+
color += weight.x * texture(inputBuffer, vec2(vRowUv1)).rgb;
|
259
|
+
color += weight.y * texture(inputBuffer, vec2(vRowUv3)).rgb;
|
260
|
+
color += weight.z * texture(inputBuffer, vec2(vRowUv7)).rgb;
|
261
|
+
color += weight.w * texture(inputBuffer, vec2(vRowUv9)).rgb;
|
264
262
|
|
265
263
|
weight =
|
266
264
|
0.0625 *
|
@@ -270,10 +268,10 @@ void main() {
|
|
270
268
|
clampToBorder(vRowUv6),
|
271
269
|
clampToBorder(vRowUv8)
|
272
270
|
);
|
273
|
-
color += weight.x *
|
274
|
-
color += weight.y *
|
275
|
-
color += weight.z *
|
276
|
-
color += weight.w *
|
271
|
+
color += weight.x * texture(inputBuffer, vec2(vRowUv2)).rgb;
|
272
|
+
color += weight.y * texture(inputBuffer, vec2(vRowUv4)).rgb;
|
273
|
+
color += weight.z * texture(inputBuffer, vec2(vRowUv6)).rgb;
|
274
|
+
color += weight.w * texture(inputBuffer, vec2(vRowUv8)).rgb;
|
277
275
|
|
278
276
|
weight =
|
279
277
|
0.125 *
|
@@ -283,24 +281,23 @@ void main() {
|
|
283
281
|
clampToBorder(vRowUv6),
|
284
282
|
clampToBorder(vRowUv8)
|
285
283
|
);
|
286
|
-
color += weight.x *
|
287
|
-
color += weight.y *
|
288
|
-
color += weight.z *
|
289
|
-
color += weight.w *
|
284
|
+
color += weight.x * texture(inputBuffer, vec2(vCenterUv1)).rgb;
|
285
|
+
color += weight.y * texture(inputBuffer, vec2(vCenterUv2)).rgb;
|
286
|
+
color += weight.z * texture(inputBuffer, vec2(vCenterUv3)).rgb;
|
287
|
+
color += weight.w * texture(inputBuffer, vec2(vCenterUv4)).rgb;
|
290
288
|
|
291
|
-
|
292
|
-
|
289
|
+
// WORKAROUND: Avoid screen flashes if the input buffer contains NaN texels.
|
290
|
+
// See: https://github.com/takram-design-engineering/three-geospatial/issues/7
|
293
291
|
if (any(isnan(color))) {
|
294
292
|
gl_FragColor = vec4(vec3(0.0), 1.0);
|
295
293
|
return;
|
296
294
|
}
|
297
295
|
|
298
296
|
float l = luminance(color);
|
299
|
-
float scale = saturate(
|
300
|
-
smoothstep(thresholdLevel, thresholdLevel + thresholdRange, l)
|
301
|
-
);
|
297
|
+
float scale = saturate(smoothstep(thresholdLevel, thresholdLevel + thresholdRange, l));
|
302
298
|
gl_FragColor = vec4(color * scale, 1.0);
|
303
|
-
}
|
299
|
+
}
|
300
|
+
`, k = `uniform vec2 texelSize;
|
304
301
|
|
305
302
|
out vec2 vCenterUv1;
|
306
303
|
out vec2 vCenterUv2;
|
@@ -333,37 +330,38 @@ void main() {
|
|
333
330
|
vRowUv9 = uv + texelSize * vec2(2.0, -2.0);
|
334
331
|
|
335
332
|
gl_Position = vec4(position.xy, 1.0, 1.0);
|
336
|
-
}
|
337
|
-
|
333
|
+
}
|
334
|
+
`, $ = {
|
338
335
|
thresholdLevel: 10,
|
339
336
|
thresholdRange: 1
|
340
337
|
};
|
341
|
-
class
|
338
|
+
class W extends U {
|
342
339
|
constructor(e) {
|
343
340
|
const {
|
344
341
|
inputBuffer: t = null,
|
345
|
-
thresholdLevel:
|
346
|
-
thresholdRange:
|
347
|
-
...
|
342
|
+
thresholdLevel: n,
|
343
|
+
thresholdRange: o,
|
344
|
+
...i
|
348
345
|
} = {
|
349
|
-
|
346
|
+
...$,
|
350
347
|
...e
|
351
348
|
};
|
352
349
|
super({
|
353
350
|
name: "DownsampleThresholdMaterial",
|
354
|
-
fragmentShader:
|
355
|
-
vertexShader:
|
356
|
-
|
357
|
-
inputBuffer: new i(t),
|
358
|
-
texelSize: new i(new T()),
|
359
|
-
thresholdLevel: new i(r),
|
360
|
-
thresholdRange: new i(n)
|
361
|
-
},
|
362
|
-
blending: S,
|
351
|
+
fragmentShader: V,
|
352
|
+
vertexShader: k,
|
353
|
+
blending: T,
|
363
354
|
toneMapped: !1,
|
364
355
|
depthWrite: !1,
|
365
356
|
depthTest: !1,
|
366
|
-
...
|
357
|
+
...i,
|
358
|
+
uniforms: {
|
359
|
+
inputBuffer: new s(t),
|
360
|
+
texelSize: new s(new S()),
|
361
|
+
thresholdLevel: new s(n),
|
362
|
+
thresholdRange: new s(o),
|
363
|
+
...i.uniforms
|
364
|
+
}
|
367
365
|
});
|
368
366
|
}
|
369
367
|
setSize(e, t) {
|
@@ -388,7 +386,7 @@ class V extends U {
|
|
388
386
|
this.uniforms.thresholdRange.value = e;
|
389
387
|
}
|
390
388
|
}
|
391
|
-
|
389
|
+
const K = `#include <common>
|
392
390
|
|
393
391
|
#define SQRT_2 (0.7071067811865476)
|
394
392
|
|
@@ -404,9 +402,9 @@ in vec2 vAspectRatio;
|
|
404
402
|
|
405
403
|
vec3 sampleGhost(const vec2 direction, const vec3 color, const float offset) {
|
406
404
|
vec2 suv = clamp(1.0 - vUv + direction * offset, 0.0, 1.0);
|
407
|
-
vec3 result =
|
405
|
+
vec3 result = texture(inputBuffer, suv).rgb * color;
|
408
406
|
|
409
|
-
|
407
|
+
// Falloff at the perimeter.
|
410
408
|
float d = clamp(length(0.5 - suv) / (0.5 * SQRT_2), 0.0, 1.0);
|
411
409
|
result *= pow(1.0 - d, 3.0);
|
412
410
|
return result;
|
@@ -427,6 +425,7 @@ vec4 sampleGhosts(float amount) {
|
|
427
425
|
return vec4(color * amount, 1.0);
|
428
426
|
}
|
429
427
|
|
428
|
+
// Reference: https://john-chapman.github.io/2017/11/05/pseudo-lens-flare.html
|
430
429
|
float cubicRingMask(const float x, const float radius, const float thickness) {
|
431
430
|
float v = min(abs(x - radius) / thickness, 1.0);
|
432
431
|
return 1.0 - v * v * (3.0 - 2.0 * v);
|
@@ -437,12 +436,12 @@ vec3 sampleHalo(const float radius) {
|
|
437
436
|
vec3 offset = vec3(texelSize.x * chromaticAberration) * vec3(-1.0, 0.0, 1.0);
|
438
437
|
vec2 suv = fract(1.0 - vUv + direction * radius);
|
439
438
|
vec3 result = vec3(
|
440
|
-
|
441
|
-
|
442
|
-
|
439
|
+
texture(inputBuffer, suv + direction * offset.r).r,
|
440
|
+
texture(inputBuffer, suv + direction * offset.g).g,
|
441
|
+
texture(inputBuffer, suv + direction * offset.b).b
|
443
442
|
);
|
444
443
|
|
445
|
-
|
444
|
+
// Falloff at the center and perimeter.
|
446
445
|
vec2 wuv = (vUv - vec2(0.5, 0.0)) / vAspectRatio + vec2(0.5, 0.0);
|
447
446
|
float d = saturate(distance(wuv, vec2(0.5)));
|
448
447
|
result *= cubicRingMask(d, 0.45, 0.25);
|
@@ -458,7 +457,9 @@ vec4 sampleHalos(const float amount) {
|
|
458
457
|
void main() {
|
459
458
|
gl_FragColor += sampleGhosts(ghostAmount);
|
460
459
|
gl_FragColor += sampleHalos(haloAmount);
|
461
|
-
}
|
460
|
+
}
|
461
|
+
|
462
|
+
`, Z = `uniform vec2 texelSize;
|
462
463
|
|
463
464
|
out vec2 vUv;
|
464
465
|
out vec2 vAspectRatio;
|
@@ -467,43 +468,44 @@ void main() {
|
|
467
468
|
vUv = position.xy * 0.5 + 0.5;
|
468
469
|
vAspectRatio = vec2(texelSize.x / texelSize.y, 1.0);
|
469
470
|
gl_Position = vec4(position.xy, 1.0, 1.0);
|
470
|
-
}
|
471
|
-
|
471
|
+
}
|
472
|
+
`, Q = {
|
472
473
|
ghostAmount: 1e-3,
|
473
474
|
haloAmount: 1e-3,
|
474
475
|
chromaticAberration: 10
|
475
476
|
};
|
476
|
-
class
|
477
|
+
class X extends U {
|
477
478
|
constructor(e) {
|
478
479
|
const {
|
479
480
|
inputBuffer: t = null,
|
480
|
-
ghostAmount:
|
481
|
-
haloAmount:
|
482
|
-
chromaticAberration:
|
481
|
+
ghostAmount: n,
|
482
|
+
haloAmount: o,
|
483
|
+
chromaticAberration: i,
|
484
|
+
...a
|
483
485
|
} = {
|
484
|
-
...
|
486
|
+
...Q,
|
485
487
|
...e
|
486
488
|
};
|
487
489
|
super({
|
488
490
|
name: "LensFlareFeaturesMaterial",
|
489
|
-
fragmentShader:
|
490
|
-
vertexShader:
|
491
|
-
|
492
|
-
inputBuffer: new i(t),
|
493
|
-
texelSize: new i(new T()),
|
494
|
-
ghostAmount: new i(r),
|
495
|
-
haloAmount: new i(n),
|
496
|
-
chromaticAberration: new i(s)
|
497
|
-
},
|
498
|
-
blending: S,
|
491
|
+
fragmentShader: K,
|
492
|
+
vertexShader: Z,
|
493
|
+
blending: T,
|
499
494
|
toneMapped: !1,
|
500
495
|
depthWrite: !1,
|
501
|
-
depthTest: !1
|
496
|
+
depthTest: !1,
|
497
|
+
uniforms: {
|
498
|
+
inputBuffer: new s(t),
|
499
|
+
texelSize: new s(new S()),
|
500
|
+
ghostAmount: new s(n),
|
501
|
+
haloAmount: new s(o),
|
502
|
+
chromaticAberration: new s(i),
|
503
|
+
...a.uniforms
|
504
|
+
}
|
502
505
|
});
|
503
506
|
}
|
504
507
|
setSize(e, t) {
|
505
|
-
|
506
|
-
r.value.x = 1 / e, r.value.y = 1 / t;
|
508
|
+
this.uniforms.texelSize.value.set(1 / e, 1 / t);
|
507
509
|
}
|
508
510
|
get inputBuffer() {
|
509
511
|
return this.uniforms.inputBuffer.value;
|
@@ -530,89 +532,87 @@ class Z extends U {
|
|
530
532
|
this.uniforms.chromaticAberration.value = e;
|
531
533
|
}
|
532
534
|
}
|
533
|
-
|
535
|
+
const Y = `uniform sampler2D bloomBuffer;
|
534
536
|
uniform sampler2D featuresBuffer;
|
535
537
|
uniform float intensity;
|
536
538
|
|
537
539
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
538
|
-
vec3 bloom =
|
539
|
-
vec3 features =
|
540
|
-
outputColor = vec4(
|
541
|
-
|
542
|
-
|
543
|
-
);
|
544
|
-
}`;
|
545
|
-
const X = {
|
540
|
+
vec3 bloom = texture(bloomBuffer, uv).rgb;
|
541
|
+
vec3 features = texture(featuresBuffer, uv).rgb;
|
542
|
+
outputColor = vec4(inputColor.rgb + (bloom + features) * intensity, inputColor.a);
|
543
|
+
}
|
544
|
+
`, q = {
|
546
545
|
blendFunction: f.NORMAL,
|
547
546
|
resolutionScale: 0.5,
|
548
547
|
width: d.AUTO_SIZE,
|
549
548
|
height: d.AUTO_SIZE,
|
550
549
|
intensity: 5e-3
|
551
550
|
};
|
552
|
-
class
|
551
|
+
class le extends h {
|
553
552
|
constructor(t) {
|
554
553
|
const {
|
555
|
-
blendFunction:
|
556
|
-
resolutionScale:
|
557
|
-
width:
|
558
|
-
height:
|
559
|
-
resolutionX: l =
|
560
|
-
resolutionY:
|
561
|
-
intensity:
|
554
|
+
blendFunction: n,
|
555
|
+
resolutionScale: o,
|
556
|
+
width: i,
|
557
|
+
height: a,
|
558
|
+
resolutionX: l = i,
|
559
|
+
resolutionY: E = a,
|
560
|
+
intensity: _
|
562
561
|
} = {
|
563
|
-
...
|
562
|
+
...q,
|
564
563
|
...t
|
565
564
|
};
|
566
|
-
super("LensFlareEffect",
|
567
|
-
blendFunction:
|
565
|
+
super("LensFlareEffect", Y, {
|
566
|
+
blendFunction: n,
|
568
567
|
attributes: p.CONVOLUTION,
|
569
|
-
uniforms:
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
568
|
+
uniforms: new Map(
|
569
|
+
Object.entries({
|
570
|
+
bloomBuffer: new s(null),
|
571
|
+
featuresBuffer: new s(null),
|
572
|
+
intensity: new s(1)
|
573
|
+
})
|
574
|
+
)
|
574
575
|
});
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
576
|
+
u(this, "resolution");
|
577
|
+
u(this, "renderTarget1");
|
578
|
+
u(this, "renderTarget2");
|
579
|
+
u(this, "thresholdMaterial");
|
580
|
+
u(this, "thresholdPass");
|
581
|
+
u(this, "blurPass");
|
582
|
+
u(this, "preBlurPass");
|
583
|
+
u(this, "featuresMaterial");
|
584
|
+
u(this, "featuresPass");
|
585
|
+
u(this, "onResolutionChange", () => {
|
585
586
|
this.setSize(this.resolution.baseWidth, this.resolution.baseHeight);
|
586
587
|
});
|
587
|
-
this.renderTarget1 = new
|
588
|
+
this.renderTarget1 = new w(1, 1, {
|
588
589
|
depthBuffer: !1,
|
589
590
|
stencilBuffer: !1,
|
590
591
|
type: m
|
591
|
-
}), this.renderTarget1.texture.name = "LensFlare.Target1", this.renderTarget2 = new
|
592
|
+
}), this.renderTarget1.texture.name = "LensFlare.Target1", this.renderTarget2 = new w(1, 1, {
|
592
593
|
depthBuffer: !1,
|
593
594
|
stencilBuffer: !1,
|
594
595
|
type: m
|
595
|
-
}), this.renderTarget2.texture.name = "LensFlare.Target2", this.thresholdMaterial = new
|
596
|
-
kernelSize:
|
597
|
-
}), this.featuresMaterial = new
|
596
|
+
}), this.renderTarget2.texture.name = "LensFlare.Target2", this.thresholdMaterial = new W(), this.thresholdPass = new g(this.thresholdMaterial), this.blurPass = new P(), this.blurPass.levels = 8, this.preBlurPass = new A({
|
597
|
+
kernelSize: z.SMALL
|
598
|
+
}), this.featuresMaterial = new X(), this.featuresPass = new g(this.featuresMaterial), this.uniforms.get("bloomBuffer").value = this.blurPass.texture, this.uniforms.get("featuresBuffer").value = this.renderTarget1.texture, this.resolution = new d(
|
598
599
|
this,
|
599
600
|
l,
|
600
|
-
|
601
|
-
|
602
|
-
), this.resolution.addEventListener(
|
603
|
-
"change",
|
604
|
-
this.onResolutionChange
|
605
|
-
), this.intensity = C;
|
601
|
+
E,
|
602
|
+
o
|
603
|
+
), this.resolution.addEventListener("change", this.onResolutionChange), this.intensity = _;
|
606
604
|
}
|
607
|
-
initialize(t,
|
608
|
-
this.thresholdPass.initialize(t,
|
605
|
+
initialize(t, n, o) {
|
606
|
+
this.thresholdPass.initialize(t, n, o), this.blurPass.initialize(t, n, o), this.preBlurPass.initialize(t, n, o), this.featuresPass.initialize(t, n, o);
|
609
607
|
}
|
610
|
-
update(t,
|
611
|
-
this.thresholdPass.render(t,
|
608
|
+
update(t, n, o) {
|
609
|
+
this.thresholdPass.render(t, n, this.renderTarget1), this.blurPass.render(t, this.renderTarget1, null), this.preBlurPass.render(t, this.renderTarget1, this.renderTarget2), this.featuresPass.render(t, this.renderTarget2, this.renderTarget1);
|
612
610
|
}
|
613
|
-
setSize(t,
|
614
|
-
const
|
615
|
-
|
611
|
+
setSize(t, n) {
|
612
|
+
const o = this.resolution;
|
613
|
+
o.setBaseSize(t, n);
|
614
|
+
const { width: i, height: a } = o;
|
615
|
+
this.renderTarget1.setSize(i, a), this.renderTarget2.setSize(i, a), this.thresholdMaterial.setSize(i, a), this.blurPass.setSize(i, a), this.preBlurPass.setSize(i, a), this.featuresMaterial.setSize(i, a);
|
616
616
|
}
|
617
617
|
get intensity() {
|
618
618
|
return this.uniforms.get("intensity").value;
|
@@ -633,7 +633,11 @@ class se extends h {
|
|
633
633
|
this.thresholdMaterial.thresholdRange = t;
|
634
634
|
}
|
635
635
|
}
|
636
|
-
|
636
|
+
const J = `#include "core/depth"
|
637
|
+
#include "core/packing"
|
638
|
+
#include "core/transform"
|
639
|
+
|
640
|
+
uniform highp sampler2D normalBuffer;
|
637
641
|
|
638
642
|
uniform mat4 projectionMatrix;
|
639
643
|
uniform mat4 inverseProjectionMatrix;
|
@@ -655,56 +659,58 @@ vec3 reconstructNormal(const vec2 uv) {
|
|
655
659
|
|
656
660
|
vec3 readNormal(const vec2 uv) {
|
657
661
|
#ifdef OCT_ENCODED
|
658
|
-
return unpackVec2ToNormal(
|
659
|
-
#else
|
660
|
-
return 2.0 *
|
661
|
-
#endif
|
662
|
+
return unpackVec2ToNormal(texture(normalBuffer, uv).xy);
|
663
|
+
#else // OCT_ENCODED
|
664
|
+
return 2.0 * texture(normalBuffer, uv).xyz - 1.0;
|
665
|
+
#endif // OCT_ENCODED
|
662
666
|
}
|
663
667
|
|
664
668
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
665
669
|
#ifdef RECONSTRUCT_FROM_DEPTH
|
666
670
|
vec3 normal = reconstructNormal(uv);
|
667
|
-
#else
|
671
|
+
#else // RECONSTRUCT_FROM_DEPTH
|
668
672
|
vec3 normal = readNormal(uv);
|
669
|
-
#endif
|
673
|
+
#endif // RECONSTRUCT_FROM_DEPTH
|
670
674
|
|
671
675
|
outputColor = vec4(normal * 0.5 + 0.5, inputColor.a);
|
672
|
-
}
|
673
|
-
|
676
|
+
}
|
677
|
+
`, ee = {
|
674
678
|
blendFunction: f.SRC,
|
675
679
|
octEncoded: !1,
|
676
680
|
reconstructFromDepth: !1
|
677
681
|
};
|
678
|
-
class
|
682
|
+
class ce extends h {
|
679
683
|
constructor(e, t) {
|
680
684
|
const {
|
681
|
-
blendFunction:
|
682
|
-
normalBuffer:
|
683
|
-
octEncoded:
|
684
|
-
reconstructFromDepth:
|
685
|
+
blendFunction: n,
|
686
|
+
normalBuffer: o = null,
|
687
|
+
octEncoded: i,
|
688
|
+
reconstructFromDepth: a
|
685
689
|
} = {
|
686
|
-
...
|
690
|
+
...ee,
|
687
691
|
...t
|
688
692
|
};
|
689
693
|
super(
|
690
694
|
"NormalEffect",
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
695
|
+
b(J, {
|
696
|
+
core: {
|
697
|
+
depth: B,
|
698
|
+
packing: C,
|
699
|
+
transform: O
|
700
|
+
}
|
701
|
+
}),
|
698
702
|
{
|
699
|
-
blendFunction:
|
703
|
+
blendFunction: n,
|
700
704
|
attributes: p.DEPTH,
|
701
|
-
uniforms:
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
705
|
+
uniforms: new Map(
|
706
|
+
Object.entries({
|
707
|
+
normalBuffer: new s(o),
|
708
|
+
projectionMatrix: new s(new x()),
|
709
|
+
inverseProjectionMatrix: new s(new x())
|
710
|
+
})
|
711
|
+
)
|
706
712
|
}
|
707
|
-
), this.camera = e, e != null && (this.mainCamera = e), this.octEncoded =
|
713
|
+
), this.camera = e, e != null && (this.mainCamera = e), this.octEncoded = i, this.reconstructFromDepth = a;
|
708
714
|
}
|
709
715
|
get mainCamera() {
|
710
716
|
return this.camera;
|
@@ -712,9 +718,9 @@ class ae extends h {
|
|
712
718
|
set mainCamera(e) {
|
713
719
|
this.camera = e;
|
714
720
|
}
|
715
|
-
update(e, t,
|
716
|
-
const
|
717
|
-
l != null && (
|
721
|
+
update(e, t, n) {
|
722
|
+
const o = this.uniforms, i = o.get("projectionMatrix"), a = o.get("inverseProjectionMatrix"), l = this.camera;
|
723
|
+
l != null && (i.value.copy(l.projectionMatrix), a.value.copy(l.projectionMatrixInverse));
|
718
724
|
}
|
719
725
|
get normalBuffer() {
|
720
726
|
return this.uniforms.get("normalBuffer").value;
|
@@ -736,15 +742,15 @@ class ae extends h {
|
|
736
742
|
}
|
737
743
|
}
|
738
744
|
export {
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
+
se as D,
|
746
|
+
ue as G,
|
747
|
+
le as L,
|
748
|
+
ce as N,
|
749
|
+
j as a,
|
750
|
+
ae as b,
|
745
751
|
L as d,
|
746
|
-
|
747
|
-
|
748
|
-
|
752
|
+
q as l,
|
753
|
+
ee as n,
|
754
|
+
I as s
|
749
755
|
};
|
750
756
|
//# sourceMappingURL=shared.js.map
|