@takram/three-geospatial-effects 0.0.1-alpha.0
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/README.md +15 -0
- package/build/index.cjs +1 -0
- package/build/index.js +25 -0
- package/build/r3f.cjs +748 -0
- package/build/r3f.js +1645 -0
- package/build/shared.cjs +315 -0
- package/build/shared.js +741 -0
- package/package.json +52 -0
- package/src/DepthEffect.ts +81 -0
- package/src/DitheringEffect.ts +28 -0
- package/src/DownsampleThresholdMaterial.ts +83 -0
- package/src/GeometryEffect.ts +79 -0
- package/src/GeometryPass.ts +53 -0
- package/src/LensFlareEffect.ts +185 -0
- package/src/LensFlareFeaturesMaterial.ts +96 -0
- package/src/NormalEffect.ts +135 -0
- package/src/createHaldLookupTexture.ts +20 -0
- package/src/index.ts +7 -0
- package/src/r3f/Depth.tsx +8 -0
- package/src/r3f/Dithering.tsx +5 -0
- package/src/r3f/EffectComposer.tsx +189 -0
- package/src/r3f/Geometry.tsx +45 -0
- package/src/r3f/LensFlare.tsx +30 -0
- package/src/r3f/Normal.tsx +49 -0
- package/src/r3f/SSAO.tsx +123 -0
- package/src/r3f/index.ts +8 -0
- package/src/r3f/types.ts +12 -0
- package/src/setupMaterialsForGeometryPass.ts +131 -0
- package/src/shaders/depthEffect.frag +26 -0
- package/src/shaders/ditheringEffect.frag +7 -0
- package/src/shaders/downsampleThreshold.frag +73 -0
- package/src/shaders/downsampleThreshold.vert +34 -0
- package/src/shaders/geometryEffect.frag +17 -0
- package/src/shaders/lensFlareEffect.frag +12 -0
- package/src/shaders/lensFlareFeatures.frag +73 -0
- package/src/shaders/lensFlareFeatures.vert +10 -0
- package/src/shaders/normalEffect.frag +37 -0
- package/src/shaders/ssr.frag +381 -0
- package/src/shaders/ssr.vert +6 -0
- package/src/shaders/ssrEffect.frag +6 -0
- package/types/DepthEffect.d.ts +23 -0
- package/types/DitheringEffect.d.ts +11 -0
- package/types/DownsampleThresholdMaterial.d.ts +21 -0
- package/types/GeometryEffect.d.ts +20 -0
- package/types/GeometryPass.d.ts +9 -0
- package/types/LensFlareEffect.d.ts +43 -0
- package/types/LensFlareFeaturesMaterial.d.ts +26 -0
- package/types/NormalEffect.d.ts +27 -0
- package/types/createHaldLookupTexture.d.ts +4 -0
- package/types/index.d.ts +7 -0
- package/types/r3f/Depth.d.ts +8 -0
- package/types/r3f/Dithering.d.ts +6 -0
- package/types/r3f/EffectComposer.d.ts +25 -0
- package/types/r3f/Geometry.d.ts +6 -0
- package/types/r3f/LensFlare.d.ts +6 -0
- package/types/r3f/Normal.d.ts +6 -0
- package/types/r3f/SSAO.d.ts +26 -0
- package/types/r3f/index.d.ts +8 -0
- package/types/r3f/types.d.ts +8 -0
- package/types/setupMaterialsForGeometryPass.d.ts +8 -0
package/build/shared.cjs
ADDED
@@ -0,0 +1,315 @@
|
|
1
|
+
"use strict";var R=Object.defineProperty;var T=(i,e,t)=>e in i?R(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var l=(i,e,t)=>T(i,typeof e!="symbol"?e+"":e,t);const s=require("postprocessing"),r=require("three"),f=require("@takram/three-geospatial");var S=`uniform float near;
|
2
|
+
uniform float far;
|
3
|
+
|
4
|
+
vec3 turbo(const float x) {
|
5
|
+
float r = 0.1357 + x * (4.5974 - x * (42.3277 - x * (130.5887 - x * (150.5666 - x * 58.1375))));
|
6
|
+
float g = 0.0914 + x * (2.1856 + x * (4.8052 - x * (14.0195 - x * (4.2109 + x * 2.7747))));
|
7
|
+
float b = 0.1067 + x * (12.5925 - x * (60.1097 - x * (109.0745 - x * (88.5066 - x * 26.8183))));
|
8
|
+
return vec3(r, g, b);
|
9
|
+
}
|
10
|
+
|
11
|
+
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
12
|
+
float depth = readDepth(uv);
|
13
|
+
depth = reverseLogDepth(depth, cameraNear, cameraFar);
|
14
|
+
depth = linearizeDepth(depth, near, far) / far;
|
15
|
+
|
16
|
+
#ifdef USE_TURBO
|
17
|
+
vec3 color = turbo(1.0 - depth);
|
18
|
+
#else
|
19
|
+
vec3 color = vec3(depth);
|
20
|
+
#endif
|
21
|
+
|
22
|
+
outputColor = vec4(color, inputColor.a);
|
23
|
+
}`;const d={blendFunction:s.BlendFunction.SRC,useTurbo:!1,near:1,far:1e3};class b extends s.Effect{constructor(e){const{blendFunction:t,useTurbo:o,near:n,far:a}={...d,...e};super("DepthEffect",`
|
24
|
+
${f.depthShader}
|
25
|
+
${S}
|
26
|
+
`,{blendFunction:t,attributes:s.EffectAttribute.DEPTH,uniforms:new Map([["near",new r.Uniform(n)],["far",new r.Uniform(a)]])}),this.useTurbo=o}get useTurbo(){return this.defines.has("USE_TURBO")}set useTurbo(e){this.useTurbo!==e&&(e?this.defines.set("USE_TURBO","1"):this.defines.delete("USE_TURBO"),this.setChanged())}get near(){return this.uniforms.get("near").value}set near(e){this.uniforms.get("near").value=e}get far(){return this.uniforms.get("far").value}set far(e){this.uniforms.get("far").value=e}}var B=`#define DITHERING
|
27
|
+
|
28
|
+
#include <dithering_pars_fragment>
|
29
|
+
|
30
|
+
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
31
|
+
outputColor = vec4(dithering(inputColor.rgb), inputColor.a);
|
32
|
+
}`;const m={blendFunction:s.BlendFunction.NORMAL};class D extends s.Effect{constructor(e){const{blendFunction:t}={...m,...e};super("DitheringEffect",B,{blendFunction:t})}}const h=Symbol("SETUP");function E(i){const e=i.vertexShader.replace("#include <fog_pars_vertex>",`
|
33
|
+
#include <fog_pars_vertex>
|
34
|
+
#include <normal_pars_vertex>
|
35
|
+
`).replace("#include <defaultnormal_vertex>",`
|
36
|
+
#include <defaultnormal_vertex>
|
37
|
+
#include <normal_vertex>
|
38
|
+
`).replace("#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )","#if 1").replace("#include <clipping_planes_vertex>",`
|
39
|
+
#include <clipping_planes_vertex>
|
40
|
+
vViewPosition = - mvPosition.xyz;
|
41
|
+
`);i.vertexShader=`
|
42
|
+
#undef FLAT_SHADED
|
43
|
+
varying vec3 vViewPosition;
|
44
|
+
${e}
|
45
|
+
`;const t=i.fragmentShader.replace(/#ifndef FLAT_SHADED\s+varying vec3 vNormal;\s+#endif/m,"#include <normal_pars_fragment>").replace("#include <common>",`
|
46
|
+
#include <common>
|
47
|
+
#include <packing>
|
48
|
+
`).replace("#include <specularmap_fragment>",`
|
49
|
+
#include <specularmap_fragment>
|
50
|
+
#include <normal_fragment_begin>
|
51
|
+
#include <normal_fragment_maps>
|
52
|
+
`);return i.fragmentShader=`
|
53
|
+
#undef FLAT_SHADED
|
54
|
+
varying vec3 vViewPosition;
|
55
|
+
${t}
|
56
|
+
`,i}function v(i,{type:e}={}){if(i[h]===!0)return i;e==="basic"&&E(i);const t=e==="physical"?`
|
57
|
+
vec4(
|
58
|
+
packNormalToVec2(normal),
|
59
|
+
metalnessFactor,
|
60
|
+
roughnessFactor
|
61
|
+
)
|
62
|
+
`:`
|
63
|
+
vec4(
|
64
|
+
packNormalToVec2(normal),
|
65
|
+
reflectivity,
|
66
|
+
0.0
|
67
|
+
);
|
68
|
+
`;return i.fragmentShader=`
|
69
|
+
layout(location = 1) out vec4 outputBuffer1;
|
70
|
+
|
71
|
+
#ifndef USE_ENVMAP
|
72
|
+
uniform float reflectivity;
|
73
|
+
#endif
|
74
|
+
|
75
|
+
${f.packingShader}
|
76
|
+
${i.fragmentShader.replace(/}\s*$/m,`
|
77
|
+
outputBuffer1 = ${t};
|
78
|
+
}
|
79
|
+
`)}
|
80
|
+
`,i[h]=!0,i}function p(){v(r.ShaderLib.lambert),v(r.ShaderLib.phong),v(r.ShaderLib.basic,{type:"basic"}),v(r.ShaderLib.standard,{type:"physical"}),v(r.ShaderLib.physical,{type:"physical"})}class C extends s.RenderPass{constructor(t,o,n,a){super(o,n,a);l(this,"geometryTexture");this.geometryTexture=t.texture.clone(),this.geometryTexture.isRenderTargetTexture=!0,this.geometryTexture.type=r.HalfFloatType,p()}render(t,o,n,a,u){o!=null&&(o.textures[1]=this.geometryTexture),super.render(t,o,null),o!=null&&(o.textures.length=1)}setSize(t,o){this.geometryTexture.image.width=t,this.geometryTexture.image.height=o}}var _=`#include <common>
|
81
|
+
|
82
|
+
uniform sampler2D inputBuffer;
|
83
|
+
|
84
|
+
uniform float thresholdLevel;
|
85
|
+
uniform float thresholdRange;
|
86
|
+
|
87
|
+
in vec2 vCenterUv1;
|
88
|
+
in vec2 vCenterUv2;
|
89
|
+
in vec2 vCenterUv3;
|
90
|
+
in vec2 vCenterUv4;
|
91
|
+
in vec2 vRowUv1;
|
92
|
+
in vec2 vRowUv2;
|
93
|
+
in vec2 vRowUv3;
|
94
|
+
in vec2 vRowUv4;
|
95
|
+
in vec2 vRowUv5;
|
96
|
+
in vec2 vRowUv6;
|
97
|
+
in vec2 vRowUv7;
|
98
|
+
in vec2 vRowUv8;
|
99
|
+
in vec2 vRowUv9;
|
100
|
+
|
101
|
+
float clampToBorder(const vec2 uv) {
|
102
|
+
return float(uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0);
|
103
|
+
}
|
104
|
+
|
105
|
+
void main() {
|
106
|
+
vec3 color = 0.125 * texture2D(inputBuffer, vec2(vRowUv5)).rgb;
|
107
|
+
vec4 weight =
|
108
|
+
0.03125 *
|
109
|
+
vec4(
|
110
|
+
clampToBorder(vRowUv1),
|
111
|
+
clampToBorder(vRowUv3),
|
112
|
+
clampToBorder(vRowUv7),
|
113
|
+
clampToBorder(vRowUv9)
|
114
|
+
);
|
115
|
+
color += weight.x * texture2D(inputBuffer, vec2(vRowUv1)).rgb;
|
116
|
+
color += weight.y * texture2D(inputBuffer, vec2(vRowUv3)).rgb;
|
117
|
+
color += weight.z * texture2D(inputBuffer, vec2(vRowUv7)).rgb;
|
118
|
+
color += weight.w * texture2D(inputBuffer, vec2(vRowUv9)).rgb;
|
119
|
+
|
120
|
+
weight =
|
121
|
+
0.0625 *
|
122
|
+
vec4(
|
123
|
+
clampToBorder(vRowUv2),
|
124
|
+
clampToBorder(vRowUv4),
|
125
|
+
clampToBorder(vRowUv6),
|
126
|
+
clampToBorder(vRowUv8)
|
127
|
+
);
|
128
|
+
color += weight.x * texture2D(inputBuffer, vec2(vRowUv2)).rgb;
|
129
|
+
color += weight.y * texture2D(inputBuffer, vec2(vRowUv4)).rgb;
|
130
|
+
color += weight.z * texture2D(inputBuffer, vec2(vRowUv6)).rgb;
|
131
|
+
color += weight.w * texture2D(inputBuffer, vec2(vRowUv8)).rgb;
|
132
|
+
|
133
|
+
weight =
|
134
|
+
0.125 *
|
135
|
+
vec4(
|
136
|
+
clampToBorder(vRowUv2),
|
137
|
+
clampToBorder(vRowUv4),
|
138
|
+
clampToBorder(vRowUv6),
|
139
|
+
clampToBorder(vRowUv8)
|
140
|
+
);
|
141
|
+
color += weight.x * texture2D(inputBuffer, vec2(vCenterUv1)).rgb;
|
142
|
+
color += weight.y * texture2D(inputBuffer, vec2(vCenterUv2)).rgb;
|
143
|
+
color += weight.z * texture2D(inputBuffer, vec2(vCenterUv3)).rgb;
|
144
|
+
color += weight.w * texture2D(inputBuffer, vec2(vCenterUv4)).rgb;
|
145
|
+
|
146
|
+
float l = luminance(color);
|
147
|
+
float scale = saturate(
|
148
|
+
smoothstep(thresholdLevel, thresholdLevel + thresholdRange, l)
|
149
|
+
);
|
150
|
+
gl_FragColor = vec4(color * scale, 1.0);
|
151
|
+
}`,F=`uniform vec2 texelSize;
|
152
|
+
|
153
|
+
out vec2 vCenterUv1;
|
154
|
+
out vec2 vCenterUv2;
|
155
|
+
out vec2 vCenterUv3;
|
156
|
+
out vec2 vCenterUv4;
|
157
|
+
out vec2 vRowUv1;
|
158
|
+
out vec2 vRowUv2;
|
159
|
+
out vec2 vRowUv3;
|
160
|
+
out vec2 vRowUv4;
|
161
|
+
out vec2 vRowUv5;
|
162
|
+
out vec2 vRowUv6;
|
163
|
+
out vec2 vRowUv7;
|
164
|
+
out vec2 vRowUv8;
|
165
|
+
out vec2 vRowUv9;
|
166
|
+
|
167
|
+
void main() {
|
168
|
+
vec2 uv = position.xy * 0.5 + 0.5;
|
169
|
+
vCenterUv1 = uv + texelSize * vec2(-1.0, 1.0);
|
170
|
+
vCenterUv2 = uv + texelSize * vec2(1.0, 1.0);
|
171
|
+
vCenterUv3 = uv + texelSize * vec2(-1.0, -1.0);
|
172
|
+
vCenterUv4 = uv + texelSize * vec2(1.0, -1.0);
|
173
|
+
vRowUv1 = uv + texelSize * vec2(-2.0, 2.0);
|
174
|
+
vRowUv2 = uv + texelSize * vec2(0.0, 2.0);
|
175
|
+
vRowUv3 = uv + texelSize * vec2(2.0, 2.0);
|
176
|
+
vRowUv4 = uv + texelSize * vec2(-2.0, 0.0);
|
177
|
+
vRowUv5 = uv + texelSize;
|
178
|
+
vRowUv6 = uv + texelSize * vec2(2.0, 0.0);
|
179
|
+
vRowUv7 = uv + texelSize * vec2(-2.0, -2.0);
|
180
|
+
vRowUv8 = uv + texelSize * vec2(0.0, -2.0);
|
181
|
+
vRowUv9 = uv + texelSize * vec2(2.0, -2.0);
|
182
|
+
|
183
|
+
gl_Position = vec4(position.xy, 1.0, 1.0);
|
184
|
+
}`;const y={thresholdLevel:10,thresholdRange:1};class M extends r.ShaderMaterial{constructor(e){const{inputBuffer:t=null,thresholdLevel:o,thresholdRange:n,...a}={...y,...e};super({name:"DownsampleThresholdMaterial",fragmentShader:_,vertexShader:F,uniforms:{inputBuffer:new r.Uniform(t),texelSize:new r.Uniform(new r.Vector2),thresholdLevel:new r.Uniform(o),thresholdRange:new r.Uniform(n)},blending:r.NoBlending,toneMapped:!1,depthWrite:!1,depthTest:!1,...a})}setSize(e,t){this.uniforms.texelSize.value.set(1/e,1/t)}get inputBuffer(){return this.uniforms.inputBuffer.value}set inputBuffer(e){this.uniforms.inputBuffer.value=e}get thresholdLevel(){return this.uniforms.thresholdLevel.value}set thresholdLevel(e){this.uniforms.thresholdLevel.value=e}get thresholdRange(){return this.uniforms.thresholdRange.value}set thresholdRange(e){this.uniforms.thresholdRange.value=e}}var P=`#include <common>
|
185
|
+
|
186
|
+
#define SQRT_2 (0.7071067811865476)
|
187
|
+
|
188
|
+
uniform sampler2D inputBuffer;
|
189
|
+
|
190
|
+
uniform vec2 texelSize;
|
191
|
+
uniform float ghostAmount;
|
192
|
+
uniform float haloAmount;
|
193
|
+
uniform float chromaticAberration;
|
194
|
+
|
195
|
+
in vec2 vUv;
|
196
|
+
in vec2 vAspectRatio;
|
197
|
+
|
198
|
+
vec3 sampleGhost(const vec2 direction, const vec3 color, const float offset) {
|
199
|
+
vec2 suv = clamp(1.0 - vUv + direction * offset, 0.0, 1.0);
|
200
|
+
vec3 result = texture2D(inputBuffer, suv).rgb * color;
|
201
|
+
|
202
|
+
|
203
|
+
float d = clamp(length(0.5 - suv) / (0.5 * SQRT_2), 0.0, 1.0);
|
204
|
+
result *= pow(1.0 - d, 3.0);
|
205
|
+
return result;
|
206
|
+
}
|
207
|
+
|
208
|
+
vec4 sampleGhosts(float amount) {
|
209
|
+
vec3 color = vec3(0.0);
|
210
|
+
vec2 direction = vUv - 0.5;
|
211
|
+
color += sampleGhost(direction, vec3(0.8, 0.8, 1.0), -5.0);
|
212
|
+
color += sampleGhost(direction, vec3(1.0, 0.8, 0.4), -1.5);
|
213
|
+
color += sampleGhost(direction, vec3(0.9, 1.0, 0.8), -0.4);
|
214
|
+
color += sampleGhost(direction, vec3(1.0, 0.8, 0.4), -0.2);
|
215
|
+
color += sampleGhost(direction, vec3(0.9, 0.7, 0.7), -0.1);
|
216
|
+
color += sampleGhost(direction, vec3(0.5, 1.0, 0.4), 0.7);
|
217
|
+
color += sampleGhost(direction, vec3(0.5, 0.5, 0.5), 1.0);
|
218
|
+
color += sampleGhost(direction, vec3(1.0, 1.0, 0.6), 2.5);
|
219
|
+
color += sampleGhost(direction, vec3(0.5, 0.8, 1.0), 10.0);
|
220
|
+
return vec4(color * amount, 1.0);
|
221
|
+
}
|
222
|
+
|
223
|
+
float cubicRingMask(const float x, const float radius, const float thickness) {
|
224
|
+
float v = min(abs(x - radius) / thickness, 1.0);
|
225
|
+
return 1.0 - v * v * (3.0 - 2.0 * v);
|
226
|
+
}
|
227
|
+
|
228
|
+
vec3 sampleHalo(const float radius) {
|
229
|
+
vec2 direction = normalize((vUv - 0.5) / vAspectRatio) * vAspectRatio;
|
230
|
+
vec3 offset = vec3(texelSize.x * chromaticAberration) * vec3(-1.0, 0.0, 1.0);
|
231
|
+
vec2 suv = fract(1.0 - vUv + direction * radius);
|
232
|
+
vec3 result = vec3(
|
233
|
+
texture2D(inputBuffer, suv + direction * offset.r).r,
|
234
|
+
texture2D(inputBuffer, suv + direction * offset.g).g,
|
235
|
+
texture2D(inputBuffer, suv + direction * offset.b).b
|
236
|
+
);
|
237
|
+
|
238
|
+
|
239
|
+
vec2 wuv = (vUv - vec2(0.5, 0.0)) / vAspectRatio + vec2(0.5, 0.0);
|
240
|
+
float d = saturate(distance(wuv, vec2(0.5)));
|
241
|
+
result *= cubicRingMask(d, 0.45, 0.25);
|
242
|
+
return result;
|
243
|
+
}
|
244
|
+
|
245
|
+
vec4 sampleHalos(const float amount) {
|
246
|
+
vec3 color = vec3(0.0);
|
247
|
+
color += sampleHalo(0.3);
|
248
|
+
return vec4(color, 1.0) * amount;
|
249
|
+
}
|
250
|
+
|
251
|
+
void main() {
|
252
|
+
gl_FragColor += sampleGhosts(ghostAmount);
|
253
|
+
gl_FragColor += sampleHalos(haloAmount);
|
254
|
+
}`,z=`uniform vec2 texelSize;
|
255
|
+
|
256
|
+
out vec2 vUv;
|
257
|
+
out vec2 vAspectRatio;
|
258
|
+
|
259
|
+
void main() {
|
260
|
+
vUv = position.xy * 0.5 + 0.5;
|
261
|
+
vAspectRatio = vec2(texelSize.x / texelSize.y, 1.0);
|
262
|
+
gl_Position = vec4(position.xy, 1.0, 1.0);
|
263
|
+
}`;const A={ghostAmount:.001,haloAmount:.001,chromaticAberration:10};class L extends r.ShaderMaterial{constructor(e){const{inputBuffer:t=null,ghostAmount:o,haloAmount:n,chromaticAberration:a}={...A,...e};super({name:"LensFlareFeaturesMaterial",fragmentShader:P,vertexShader:z,uniforms:{inputBuffer:new r.Uniform(t),texelSize:new r.Uniform(new r.Vector2),ghostAmount:new r.Uniform(o),haloAmount:new r.Uniform(n),chromaticAberration:new r.Uniform(a)},blending:r.NoBlending,toneMapped:!1,depthWrite:!1,depthTest:!1})}setSize(e,t){const o=this.uniforms.texelSize;o.value.x=1/e,o.value.y=1/t}get inputBuffer(){return this.uniforms.inputBuffer.value}set inputBuffer(e){this.uniforms.inputBuffer.value=e}get ghostAmount(){return this.uniforms.ghostAmount.value}set ghostAmount(e){this.uniforms.ghostAmount.value=e}get haloAmount(){return this.uniforms.haloAmount.value}set haloAmount(e){this.uniforms.haloAmount.value=e}get chromaticAberration(){return this.uniforms.chromaticAberration.value}set chromaticAberration(e){this.uniforms.chromaticAberration.value=e}}var N=`uniform sampler2D bloomBuffer;
|
264
|
+
uniform sampler2D featuresBuffer;
|
265
|
+
uniform float intensity;
|
266
|
+
|
267
|
+
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
268
|
+
vec3 bloom = texture2D(bloomBuffer, uv).rgb;
|
269
|
+
vec3 features = texture2D(featuresBuffer, uv).rgb;
|
270
|
+
outputColor = vec4(
|
271
|
+
inputColor.rgb + (bloom + features) * intensity,
|
272
|
+
inputColor.a
|
273
|
+
);
|
274
|
+
}`;const g={blendFunction:s.BlendFunction.NORMAL,resolutionScale:.5,width:s.Resolution.AUTO_SIZE,height:s.Resolution.AUTO_SIZE,intensity:.005};class O extends s.Effect{constructor(t){const{blendFunction:o,resolutionScale:n,width:a,height:u,resolutionX:c=a,resolutionY:w=u,intensity:U}={...g,...t};super("LensFlareEffect",N,{blendFunction:o,uniforms:new Map([["bloomBuffer",new r.Uniform(null)],["featuresBuffer",new r.Uniform(null)],["intensity",new r.Uniform(1)]])});l(this,"resolution");l(this,"renderTarget1");l(this,"renderTarget2");l(this,"thresholdMaterial");l(this,"thresholdPass");l(this,"blurPass");l(this,"preBlurPass");l(this,"featuresMaterial");l(this,"featuresPass");l(this,"onResolutionChange",()=>{this.setSize(this.resolution.baseWidth,this.resolution.baseHeight)});this.renderTarget1=new r.WebGLRenderTarget(1,1,{depthBuffer:!1,stencilBuffer:!1,type:r.HalfFloatType}),this.renderTarget1.texture.name="LensFlare.Target1",this.renderTarget2=new r.WebGLRenderTarget(1,1,{depthBuffer:!1,stencilBuffer:!1,type:r.HalfFloatType}),this.renderTarget2.texture.name="LensFlare.Target2",this.thresholdMaterial=new M,this.thresholdPass=new s.ShaderPass(this.thresholdMaterial),this.blurPass=new s.MipmapBlurPass,this.blurPass.levels=8,this.preBlurPass=new s.KawaseBlurPass({kernelSize:s.KernelSize.SMALL}),this.featuresMaterial=new L,this.featuresPass=new s.ShaderPass(this.featuresMaterial),this.uniforms.get("bloomBuffer").value=this.blurPass.texture,this.uniforms.get("featuresBuffer").value=this.renderTarget1.texture,this.resolution=new s.Resolution(this,c,w,n),this.resolution.addEventListener("change",this.onResolutionChange),this.intensity=U}initialize(t,o,n){this.thresholdPass.initialize(t,o,n),this.blurPass.initialize(t,o,n),this.preBlurPass.initialize(t,o,n),this.featuresPass.initialize(t,o,n)}update(t,o,n){this.thresholdPass.render(t,o,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)}setSize(t,o){const n=this.resolution;n.setBaseSize(t,o),this.renderTarget1.setSize(n.width,n.height),this.renderTarget2.setSize(n.width,n.height),this.thresholdMaterial.setSize(n.width,n.height),this.blurPass.setSize(n.width,n.height),this.preBlurPass.setSize(n.width,n.height),this.featuresMaterial.setSize(n.width,n.height)}get intensity(){return this.uniforms.get("intensity").value}set intensity(t){this.uniforms.get("intensity").value=t}get thresholdLevel(){return this.thresholdMaterial.thresholdLevel}set thresholdLevel(t){this.thresholdMaterial.thresholdLevel=t}get thresholdRange(){return this.thresholdMaterial.thresholdRange}set thresholdRange(t){this.thresholdMaterial.thresholdRange=t}}var G=`uniform highp sampler2D normalBuffer;
|
275
|
+
|
276
|
+
uniform mat4 projectionMatrix;
|
277
|
+
uniform mat4 inverseProjectionMatrix;
|
278
|
+
|
279
|
+
vec3 reconstructNormal(const vec2 uv) {
|
280
|
+
float depth = readDepth(uv);
|
281
|
+
depth = reverseLogDepth(depth, cameraNear, cameraFar);
|
282
|
+
vec3 position = screenToView(
|
283
|
+
uv,
|
284
|
+
depth,
|
285
|
+
getViewZ(depth),
|
286
|
+
projectionMatrix,
|
287
|
+
inverseProjectionMatrix
|
288
|
+
);
|
289
|
+
vec3 dx = dFdx(position);
|
290
|
+
vec3 dy = dFdy(position);
|
291
|
+
return normalize(cross(dx, dy));
|
292
|
+
}
|
293
|
+
|
294
|
+
vec3 readNormal(const vec2 uv) {
|
295
|
+
#ifdef OCT_ENCODED
|
296
|
+
return unpackVec2ToNormal(texture2D(normalBuffer, uv).xy);
|
297
|
+
#else
|
298
|
+
return 2.0 * texture2D(normalBuffer, uv).xyz - 1.0;
|
299
|
+
#endif
|
300
|
+
}
|
301
|
+
|
302
|
+
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
303
|
+
#ifdef RECONSTRUCT_FROM_DEPTH
|
304
|
+
vec3 normal = reconstructNormal(uv);
|
305
|
+
#else
|
306
|
+
vec3 normal = readNormal(uv);
|
307
|
+
#endif
|
308
|
+
|
309
|
+
outputColor = vec4(normal * 0.5 + 0.5, inputColor.a);
|
310
|
+
}`;const x={blendFunction:s.BlendFunction.SRC,octEncoded:!1,reconstructFromDepth:!1};class H extends s.Effect{constructor(e,t){const{blendFunction:o,normalBuffer:n=null,octEncoded:a,reconstructFromDepth:u}={...x,...t};super("NormalEffect",`
|
311
|
+
${f.depthShader}
|
312
|
+
${f.packingShader}
|
313
|
+
${f.transformShader}
|
314
|
+
${G}
|
315
|
+
`,{blendFunction:o,attributes:s.EffectAttribute.DEPTH,uniforms:new Map([["normalBuffer",new r.Uniform(n)],["projectionMatrix",new r.Uniform(new r.Matrix4)],["inverseProjectionMatrix",new r.Uniform(new r.Matrix4)]])}),this.camera=e,e!=null&&(this.mainCamera=e),this.octEncoded=a,this.reconstructFromDepth=u}get mainCamera(){return this.camera}set mainCamera(e){this.camera=e}update(e,t,o){const n=this.uniforms,a=n.get("projectionMatrix"),u=n.get("inverseProjectionMatrix"),c=this.camera;c!=null&&(a.value.copy(c.projectionMatrix),u.value.copy(c.projectionMatrixInverse))}get normalBuffer(){return this.uniforms.get("normalBuffer").value}set normalBuffer(e){this.uniforms.get("normalBuffer").value=e}get octEncoded(){return this.defines.has("OCT_ENCODED")}set octEncoded(e){e!==this.octEncoded&&(e?this.defines.set("OCT_ENCODED","1"):this.defines.delete("OCT_ENCODED"),this.setChanged())}get reconstructFromDepth(){return this.defines.has("RECONSTRUCT_FROM_DEPTH")}set reconstructFromDepth(e){e!==this.reconstructFromDepth&&(e?this.defines.set("RECONSTRUCT_FROM_DEPTH","1"):this.defines.delete("RECONSTRUCT_FROM_DEPTH"),this.setChanged())}}exports.DepthEffect=b;exports.DitheringEffect=D;exports.GeometryPass=C;exports.LensFlareEffect=O;exports.NormalEffect=H;exports.depthEffectOptionsDefaults=d;exports.ditheringOptionsDefaults=m;exports.lensFlareEffectOptionsDefaults=g;exports.normalEffectOptionsDefaults=x;exports.setupMaterialsForGeometryPass=p;
|