@react-three/postprocessing 2.18.0 → 2.19.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/dist/effects/LensFlare.cjs +505 -121
- package/dist/effects/LensFlare.cjs.map +1 -1
- package/dist/effects/LensFlare.d.ts +49 -46
- package/dist/effects/LensFlare.js +506 -122
- package/dist/effects/LensFlare.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ const fiber = require("@react-three/fiber");
|
|
|
7
7
|
const postprocessing = require("postprocessing");
|
|
8
8
|
const maath = require("maath");
|
|
9
9
|
const EffectComposer = require("../EffectComposer.cjs");
|
|
10
|
+
const util = require("../util.cjs");
|
|
10
11
|
function _interopNamespaceDefault(e) {
|
|
11
12
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
12
13
|
if (e) {
|
|
@@ -28,82 +29,422 @@ const LensFlareShader = {
|
|
|
28
29
|
fragmentShader: (
|
|
29
30
|
/* glsl */
|
|
30
31
|
`
|
|
32
|
+
uniform float time;
|
|
33
|
+
uniform vec2 lensPosition;
|
|
34
|
+
uniform vec2 screenRes;
|
|
35
|
+
uniform vec3 colorGain;
|
|
36
|
+
uniform float starPoints;
|
|
37
|
+
uniform float glareSize;
|
|
38
|
+
uniform float flareSize;
|
|
39
|
+
uniform float flareSpeed;
|
|
40
|
+
uniform float flareShape;
|
|
41
|
+
uniform float haloScale;
|
|
42
|
+
uniform float opacity;
|
|
43
|
+
uniform bool animated;
|
|
44
|
+
uniform bool anamorphic;
|
|
45
|
+
uniform bool enabled;
|
|
46
|
+
uniform bool secondaryGhosts;
|
|
47
|
+
uniform bool starBurst;
|
|
48
|
+
uniform float ghostScale;
|
|
49
|
+
uniform bool aditionalStreaks;
|
|
50
|
+
uniform sampler2D lensDirtTexture;
|
|
51
|
+
vec2 vTexCoord;
|
|
52
|
+
|
|
53
|
+
float rand(float n){return fract(sin(n) * 43758.5453123);}
|
|
31
54
|
|
|
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
|
-
|
|
55
|
+
float noise(float p){
|
|
56
|
+
float fl = floor(p);
|
|
57
|
+
float fc = fract(p);
|
|
58
|
+
return mix(rand(fl),rand(fl + 1.0), fc);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
vec3 hsv2rgb(vec3 c)
|
|
62
|
+
{
|
|
63
|
+
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
|
64
|
+
vec3 p = abs(fract(c.xxx + k.xyz) * 6.0 - k.www);
|
|
65
|
+
return c.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), c.y);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
float saturate(float x)
|
|
69
|
+
{
|
|
70
|
+
return clamp(x, 0.,1.);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
vec2 rotateUV(vec2 uv, float rotation)
|
|
74
|
+
{
|
|
75
|
+
return vec2(
|
|
76
|
+
cos(rotation) * uv.x + sin(rotation) * uv.y,
|
|
77
|
+
cos(rotation) * uv.y - sin(rotation) * uv.x
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Based on https://www.shadertoy.com/view/XtKfRV
|
|
82
|
+
vec3 drawflare(vec2 p, float intensity, float rnd, float speed, int id)
|
|
83
|
+
{
|
|
84
|
+
float flarehueoffset = (1. / 32.) * float(id) * 0.1;
|
|
85
|
+
float lingrad = distance(vec2(0.), p);
|
|
86
|
+
float expgrad = 1. / exp(lingrad * (fract(rnd) * 0.66 + 0.33));
|
|
87
|
+
vec3 colgrad = hsv2rgb(vec3( fract( (expgrad * 8.) + speed * flareSpeed + flarehueoffset), pow(1.-abs(expgrad*2.-1.), 0.45), 20.0 * expgrad * intensity)); //rainbow spectrum effect
|
|
88
|
+
|
|
89
|
+
float internalStarPoints;
|
|
90
|
+
|
|
91
|
+
if(anamorphic){
|
|
92
|
+
internalStarPoints = 1.0;
|
|
93
|
+
} else{
|
|
94
|
+
internalStarPoints = starPoints;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
float blades = length(p * flareShape * sin(internalStarPoints * atan(p.x, p.y)));
|
|
98
|
+
|
|
99
|
+
float comp = pow(1.-saturate(blades), ( anamorphic ? 100. : 12.));
|
|
100
|
+
comp += saturate(expgrad-0.9) * 3.;
|
|
101
|
+
comp = pow(comp * expgrad, 8. + (1.-intensity) * 5.);
|
|
102
|
+
|
|
103
|
+
if(flareSpeed > 0.0){
|
|
104
|
+
return vec3(comp) * colgrad;
|
|
105
|
+
} else{
|
|
106
|
+
return vec3(comp) * flareSize * 15.;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
float dist(vec3 a, vec3 b) { return abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z); }
|
|
111
|
+
|
|
112
|
+
vec3 saturate(vec3 x)
|
|
113
|
+
{
|
|
114
|
+
return clamp(x, vec3(0.0), vec3(1.0));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Based on https://www.shadertoy.com/view/XtKfRV
|
|
118
|
+
float glare(vec2 uv, vec2 pos, float size)
|
|
119
|
+
{
|
|
120
|
+
vec2 main;
|
|
121
|
+
|
|
122
|
+
if(animated){
|
|
123
|
+
main = rotateUV(uv-pos, time * 0.1);
|
|
124
|
+
} else{
|
|
125
|
+
main = uv-pos;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
float ang = atan(main.y, main.x) * (anamorphic ? 1.0 : starPoints);
|
|
129
|
+
float dist = length(main);
|
|
130
|
+
dist = pow(dist, .9);
|
|
131
|
+
|
|
132
|
+
float f0 = 1.0/(length(uv-pos)*(1.0/size*16.0)+.2);
|
|
133
|
+
|
|
134
|
+
return f0+f0*(sin((ang))*.2 +.3);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
float sdHex(vec2 p){
|
|
138
|
+
p = abs(p);
|
|
139
|
+
vec2 q = vec2(p.x*2.0*0.5773503, p.y + p.x*0.5773503);
|
|
140
|
+
return dot(step(q.xy,q.yx), 1.0-q.yx);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//Based on https://www.shadertoy.com/view/dllSRX
|
|
144
|
+
float fpow(float x, float k){
|
|
145
|
+
return x > k ? pow((x-k)/(1.0-k),2.0) : 0.0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
vec3 renderhex(vec2 uv, vec2 p, float s, vec3 col){
|
|
149
|
+
uv -= p;
|
|
150
|
+
if (abs(uv.x) < 0.2*s && abs(uv.y) < 0.2*s){
|
|
151
|
+
return mix(vec3(0),mix(vec3(0),col,0.1 + fpow(length(uv/s),0.1)*10.0),smoothstep(0.0,0.1,sdHex(uv*20.0/s)));
|
|
152
|
+
}
|
|
153
|
+
return vec3(0);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Based on https://www.shadertoy.com/view/4sX3Rs
|
|
157
|
+
vec3 LensFlare(vec2 uv, vec2 pos)
|
|
158
|
+
{
|
|
159
|
+
vec2 main = uv-pos;
|
|
160
|
+
vec2 uvd = uv*(length(uv));
|
|
161
|
+
|
|
162
|
+
float ang = atan(main.x,main.y);
|
|
163
|
+
|
|
164
|
+
float f0 = .3/(length(uv-pos)*16.0+1.0);
|
|
165
|
+
|
|
166
|
+
f0 = f0*(sin(noise(sin(ang*3.9-(animated ? time : 0.0) * 0.3) * starPoints))*.2 );
|
|
167
|
+
|
|
168
|
+
float f1 = max(0.01-pow(length(uv+1.2*pos),1.9),.0)*7.0;
|
|
169
|
+
|
|
170
|
+
float f2 = max(.9/(10.0+32.0*pow(length(uvd+0.99*pos),2.0)),.0)*0.35;
|
|
171
|
+
float f22 = max(.9/(11.0+32.0*pow(length(uvd+0.85*pos),2.0)),.0)*0.23;
|
|
172
|
+
float f23 = max(.9/(12.0+32.0*pow(length(uvd+0.95*pos),2.0)),.0)*0.6;
|
|
173
|
+
|
|
174
|
+
vec2 uvx = mix(uv,uvd, 0.1);
|
|
175
|
+
|
|
176
|
+
float f4 = max(0.01-pow(length(uvx+0.4*pos),2.9),.0)*4.02;
|
|
177
|
+
float f42 = max(0.0-pow(length(uvx+0.45*pos),2.9),.0)*4.1;
|
|
178
|
+
float f43 = max(0.01-pow(length(uvx+0.5*pos),2.9),.0)*4.6;
|
|
179
|
+
|
|
180
|
+
uvx = mix(uv,uvd,-.4);
|
|
181
|
+
|
|
182
|
+
float f5 = max(0.01-pow(length(uvx+0.1*pos),5.5),.0)*2.0;
|
|
183
|
+
float f52 = max(0.01-pow(length(uvx+0.2*pos),5.5),.0)*2.0;
|
|
184
|
+
float f53 = max(0.01-pow(length(uvx+0.1*pos),5.5),.0)*2.0;
|
|
185
|
+
|
|
186
|
+
uvx = mix(uv,uvd, 2.1);
|
|
187
|
+
|
|
188
|
+
float f6 = max(0.01-pow(length(uvx-0.3*pos),1.61),.0)*3.159;
|
|
189
|
+
float f62 = max(0.01-pow(length(uvx-0.325*pos),1.614),.0)*3.14;
|
|
190
|
+
float f63 = max(0.01-pow(length(uvx-0.389*pos),1.623),.0)*3.12;
|
|
191
|
+
|
|
192
|
+
vec3 c = vec3(glare(uv,pos, glareSize));
|
|
193
|
+
|
|
194
|
+
vec2 prot;
|
|
195
|
+
|
|
196
|
+
if(animated){
|
|
197
|
+
prot = rotateUV(uv - pos, (time * 0.1));
|
|
198
|
+
} else if(anamorphic){
|
|
199
|
+
prot = rotateUV(uv - pos, 1.570796);
|
|
200
|
+
} else {
|
|
201
|
+
prot = uv - pos;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
c += drawflare(prot, (anamorphic ? flareSize * 10. : flareSize), 0.1, time, 1);
|
|
205
|
+
|
|
206
|
+
c.r+=f1+f2+f4+f5+f6; c.g+=f1+f22+f42+f52+f62; c.b+=f1+f23+f43+f53+f63;
|
|
207
|
+
c = c*1.3 * vec3(length(uvd)+.09);
|
|
208
|
+
c+=vec3(f0);
|
|
209
|
+
|
|
210
|
+
return c;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
vec3 cc(vec3 color, float factor,float factor2)
|
|
214
|
+
{
|
|
215
|
+
float w = color.x+color.y+color.z;
|
|
216
|
+
return mix(color,vec3(w)*factor,w*factor2);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
float rnd(vec2 p)
|
|
220
|
+
{
|
|
221
|
+
float f = fract(sin(dot(p, vec2(12.1234, 72.8392) )*45123.2));
|
|
222
|
+
return f;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
float rnd(float w)
|
|
226
|
+
{
|
|
227
|
+
float f = fract(sin(w)*1000.);
|
|
228
|
+
return f;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
float regShape(vec2 p, int N)
|
|
232
|
+
{
|
|
233
|
+
float f;
|
|
234
|
+
|
|
235
|
+
float a=atan(p.x,p.y)+.2;
|
|
236
|
+
float b=6.28319/float(N);
|
|
237
|
+
f=smoothstep(.5,.51, cos(floor(.5+a/b)*b-a)*length(p.xy)* 2.0 -ghostScale);
|
|
238
|
+
|
|
239
|
+
return f;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Based on https://www.shadertoy.com/view/Xlc3D2
|
|
243
|
+
vec3 circle(vec2 p, float size, float decay, vec3 color, vec3 color2, float dist, vec2 position)
|
|
244
|
+
{
|
|
245
|
+
float l = length(p + position*(dist*2.))+size/2.;
|
|
246
|
+
float l2 = length(p + position*(dist*4.))+size/3.;
|
|
247
|
+
|
|
248
|
+
float c = max(0.01-pow(length(p + position*dist), size*ghostScale), 0.0)*10.;
|
|
249
|
+
float c1 = max(0.001-pow(l-0.3, 1./40.)+sin(l*20.), 0.0)*3.;
|
|
250
|
+
float c2 = max(0.09/pow(length(p-position*dist/.5)*1., .95), 0.0)/20.;
|
|
251
|
+
float s = max(0.02-pow(regShape(p*5. + position*dist*5. + decay, 6) , 1.), 0.0)*1.5;
|
|
252
|
+
|
|
253
|
+
color = cos(vec3(0.44, .24, .2)*16. + dist/8.)*0.5+.5;
|
|
254
|
+
vec3 f = c*color;
|
|
255
|
+
f += c1*color;
|
|
256
|
+
f += c2*color;
|
|
257
|
+
f += s*color;
|
|
258
|
+
return f;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
vec4 getLensColor(float x){
|
|
262
|
+
return vec4(vec3(mix(mix(mix(mix(mix(mix(mix(mix(mix(mix(mix(mix(mix(mix(mix(vec3(0., 0., 0.),
|
|
263
|
+
vec3(0., 0., 0.), smoothstep(0.0, 0.063, x)),
|
|
264
|
+
vec3(0., 0., 0.), smoothstep(0.063, 0.125, x)),
|
|
265
|
+
vec3(0.0, 0., 0.), smoothstep(0.125, 0.188, x)),
|
|
266
|
+
vec3(0.188, 0.131, 0.116), smoothstep(0.188, 0.227, x)),
|
|
267
|
+
vec3(0.31, 0.204, 0.537), smoothstep(0.227, 0.251, x)),
|
|
268
|
+
vec3(0.192, 0.106, 0.286), smoothstep(0.251, 0.314, x)),
|
|
269
|
+
vec3(0.102, 0.008, 0.341), smoothstep(0.314, 0.392, x)),
|
|
270
|
+
vec3(0.086, 0.0, 0.141), smoothstep(0.392, 0.502, x)),
|
|
271
|
+
vec3(1.0, 0.31, 0.0), smoothstep(0.502, 0.604, x)),
|
|
272
|
+
vec3(.1, 0.1, 0.1), smoothstep(0.604, 0.643, x)),
|
|
273
|
+
vec3(1.0, 0.929, 0.0), smoothstep(0.643, 0.761, x)),
|
|
274
|
+
vec3(1.0, 0.086, 0.424), smoothstep(0.761, 0.847, x)),
|
|
275
|
+
vec3(1.0, 0.49, 0.0), smoothstep(0.847, 0.89, x)),
|
|
276
|
+
vec3(0.945, 0.275, 0.475), smoothstep(0.89, 0.941, x)),
|
|
277
|
+
vec3(0.251, 0.275, 0.796), smoothstep(0.941, 1.0, x))),
|
|
278
|
+
1.0);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
float dirtNoise(vec2 p){
|
|
282
|
+
vec2 f = fract(p);
|
|
283
|
+
f = (f * f) * (3.0 - (2.0 * f));
|
|
284
|
+
float n = dot(floor(p), vec2(1.0, 157.0));
|
|
285
|
+
vec4 a = fract(sin(vec4(n + 0.0, n + 1.0, n + 157.0, n + 158.0)) * 43758.5453123);
|
|
286
|
+
return mix(mix(a.x, a.y, f.x), mix(a.z, a.w, f.x), f.y);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
float fbm(vec2 p){
|
|
290
|
+
const mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
|
|
291
|
+
float f = 0.0;
|
|
292
|
+
f += 0.5000*dirtNoise(p); p = m*p*2.02;
|
|
293
|
+
f += 0.2500*dirtNoise(p); p = m*p*2.03;
|
|
294
|
+
f += 0.1250*dirtNoise(p); p = m*p*2.01;
|
|
295
|
+
f += 0.0625*dirtNoise(p);
|
|
296
|
+
return f/0.9375;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
vec4 getLensStar(vec2 p){
|
|
300
|
+
vec2 pp = (p - vec2(0.5)) * 2.0;
|
|
301
|
+
float a = atan(pp.y, pp.x);
|
|
302
|
+
vec4 cp = vec4(sin(a * 1.0), length(pp), sin(a * 13.0), sin(a * 53.0));
|
|
303
|
+
float d = sin(clamp(pow(length(vec2(0.5) - p) * 0.5 + haloScale /2., 5.0), 0.0, 1.0) * 3.14159);
|
|
304
|
+
vec3 c = vec3(d) * vec3(fbm(cp.xy * 16.0) * fbm(cp.zw * 9.0) * max(max(max(max(0.5, sin(a * 1.0)), sin(a * 3.0) * 0.8), sin(a * 7.0) * 0.8), sin(a * 9.0) * 10.6));
|
|
305
|
+
c *= vec3(mix(2.0, (sin(length(pp.xy) * 256.0) * 0.5) + 0.5, sin((clamp((length(pp.xy) - 0.875) / 0.1, 0.0, 1.0) + 0.0) * 2.0 * 3.14159) * 1.5) + 0.5) * 0.3275;
|
|
306
|
+
return vec4(vec3(c * 1.0), d);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
vec4 getLensDirt(vec2 p){
|
|
310
|
+
p.xy += vec2(fbm(p.yx * 3.0), fbm(p.yx * 2.0)) * 0.0825;
|
|
311
|
+
vec3 o = vec3(mix(0.125, 0.25, max(max(smoothstep(0.1, 0.0, length(p - vec2(0.25))),
|
|
312
|
+
smoothstep(0.4, 0.0, length(p - vec2(0.75)))),
|
|
313
|
+
smoothstep(0.8, 0.0, length(p - vec2(0.875, 0.125))))));
|
|
314
|
+
o += vec3(max(fbm(p * 1.0) - 0.5, 0.0)) * 0.5;
|
|
315
|
+
o += vec3(max(fbm(p * 2.0) - 0.5, 0.0)) * 0.5;
|
|
316
|
+
o += vec3(max(fbm(p * 4.0) - 0.5, 0.0)) * 0.25;
|
|
317
|
+
o += vec3(max(fbm(p * 8.0) - 0.75, 0.0)) * 1.0;
|
|
318
|
+
o += vec3(max(fbm(p * 16.0) - 0.75, 0.0)) * 0.75;
|
|
319
|
+
o += vec3(max(fbm(p * 64.0) - 0.75, 0.0)) * 0.5;
|
|
320
|
+
return vec4(clamp(o, vec3(0.15), vec3(1.0)), 1.0);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
vec4 textureLimited(sampler2D tex, vec2 texCoord){
|
|
324
|
+
if(((texCoord.x < 0.) || (texCoord.y < 0.)) || ((texCoord.x > 1.) || (texCoord.y > 1.))){
|
|
325
|
+
return vec4(0.0);
|
|
326
|
+
}else{
|
|
327
|
+
return texture(tex, texCoord);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
vec4 textureDistorted(sampler2D tex, vec2 texCoord, vec2 direction, vec3 distortion) {
|
|
332
|
+
return vec4(textureLimited(tex, (texCoord + (direction * distortion.r))).r,
|
|
333
|
+
textureLimited(tex, (texCoord + (direction * distortion.g))).g,
|
|
334
|
+
textureLimited(tex, (texCoord + (direction * distortion.b))).b,
|
|
335
|
+
1.0);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Based on https://www.shadertoy.com/view/4sK3W3
|
|
339
|
+
vec4 getStartBurst(){
|
|
340
|
+
vec2 aspectTexCoord = vec2(1.0) - (((vTexCoord - vec2(0.5)) * vec2(1.0)) + vec2(0.5));
|
|
341
|
+
vec2 texCoord = vec2(1.0) - vTexCoord;
|
|
342
|
+
vec2 ghostVec = (vec2(0.5) - texCoord) * 0.3 - lensPosition;
|
|
343
|
+
vec2 ghostVecAspectNormalized = normalize(ghostVec * vec2(1.0)) * vec2(1.0);
|
|
344
|
+
vec2 haloVec = normalize(ghostVec) * 0.6;
|
|
345
|
+
vec2 haloVecAspectNormalized = ghostVecAspectNormalized * 0.6;
|
|
346
|
+
vec2 texelSize = vec2(1.0) / vec2(screenRes.xy);
|
|
347
|
+
vec3 distortion = vec3(-(texelSize.x * 1.5), 0.2, texelSize.x * 1.5);
|
|
348
|
+
vec4 c = vec4(0.0);
|
|
349
|
+
for (int i = 0; i < 8; i++) {
|
|
350
|
+
vec2 offset = texCoord + (ghostVec * float(i));
|
|
351
|
+
c += textureDistorted(lensDirtTexture, offset, ghostVecAspectNormalized, distortion) * pow(max(0.0, 1.0 - (length(vec2(0.5) - offset) / length(vec2(0.5)))), 10.0);
|
|
352
|
+
}
|
|
353
|
+
vec2 haloOffset = texCoord + haloVecAspectNormalized;
|
|
354
|
+
return (c * getLensColor((length(vec2(0.5) - aspectTexCoord) / length(vec2(haloScale))))) +
|
|
355
|
+
(textureDistorted(lensDirtTexture, haloOffset, ghostVecAspectNormalized, distortion) * pow(max(0.0, 1.0 - (length(vec2(0.5) - haloOffset) / length(vec2(0.5)))), 10.0));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
void mainImage(vec4 inputColor, vec2 uv, out vec4 outputColor)
|
|
359
|
+
{
|
|
360
|
+
vec2 myUV = uv -0.5;
|
|
361
|
+
myUV.y *= screenRes.y/screenRes.x;
|
|
362
|
+
vec2 finalLensPosition = lensPosition * 0.5;
|
|
363
|
+
finalLensPosition.y *= screenRes.y/screenRes.x;
|
|
364
|
+
|
|
365
|
+
//First Lens flare pass
|
|
366
|
+
vec3 finalColor = LensFlare(myUV, finalLensPosition) * 20.0 * colorGain / 256.;
|
|
367
|
+
|
|
368
|
+
//Aditional streaks
|
|
369
|
+
if(aditionalStreaks){
|
|
370
|
+
vec3 circColor = vec3(0.9, 0.2, 0.1);
|
|
371
|
+
vec3 circColor2 = vec3(0.3, 0.1, 0.9);
|
|
372
|
+
|
|
373
|
+
for(float i=0.;i<10.;i++){
|
|
374
|
+
finalColor += circle(myUV, pow(rnd(i*2000.)*2.8, .1)+1.41, 0.0, circColor+i , circColor2+i, rnd(i*20.)*3.+0.2-.5, lensPosition);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
//Alternative ghosts
|
|
379
|
+
if(secondaryGhosts){
|
|
380
|
+
vec3 altGhosts = vec3(0);
|
|
381
|
+
altGhosts += renderhex(myUV, -lensPosition*0.25, ghostScale * 1.4, vec3(0.25,0.35,0));
|
|
382
|
+
altGhosts += renderhex(myUV, lensPosition*0.25, ghostScale * 0.5, vec3(1,0.5,0.5));
|
|
383
|
+
altGhosts += renderhex(myUV, lensPosition*0.1, ghostScale * 1.6, vec3(1,1,1));
|
|
384
|
+
altGhosts += renderhex(myUV, lensPosition*1.8, ghostScale * 2.0, vec3(0,0.5,0.75));
|
|
385
|
+
altGhosts += renderhex(myUV, lensPosition*1.25, ghostScale * 0.8, vec3(1,1,0.5));
|
|
386
|
+
altGhosts += renderhex(myUV, -lensPosition*1.25, ghostScale * 5.0, vec3(0.5,0.5,0.25));
|
|
387
|
+
|
|
388
|
+
//Circular ghosts
|
|
389
|
+
altGhosts += fpow(1.0 - abs(distance(lensPosition*0.8,myUV) - 0.7),0.985)*colorGain / 2100.;
|
|
390
|
+
finalColor += altGhosts;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
//Starburst
|
|
395
|
+
if(starBurst){
|
|
396
|
+
vTexCoord = myUV + 0.5;
|
|
397
|
+
vec4 lensMod = getLensDirt(myUV);
|
|
398
|
+
float tooBright = 1.0 - (clamp(0.5, 0.0, 0.5) * 2.0);
|
|
399
|
+
float tooDark = clamp(0.5 - 0.5, 0.0, 0.5) * 2.0;
|
|
400
|
+
lensMod += mix(lensMod, pow(lensMod * 2.0, vec4(2.0)) * 0.5, tooBright);
|
|
401
|
+
float lensStarRotationAngle = ((myUV.x + myUV.y)) * (1.0 / 6.0);
|
|
402
|
+
vec2 lensStarTexCoord = (mat2(cos(lensStarRotationAngle), -sin(lensStarRotationAngle), sin(lensStarRotationAngle), cos(lensStarRotationAngle)) * vTexCoord);
|
|
403
|
+
lensMod += getLensStar(lensStarTexCoord) * 2.;
|
|
404
|
+
|
|
405
|
+
finalColor += clamp((lensMod.rgb * getStartBurst().rgb ), 0.01, 1.0);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
//Final composed output
|
|
409
|
+
if(enabled){
|
|
410
|
+
outputColor = vec4(mix(finalColor, vec3(.0), opacity) + inputColor.rgb, inputColor.a);
|
|
411
|
+
} else {
|
|
412
|
+
outputColor = vec4(inputColor);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
`
|
|
75
416
|
)
|
|
76
417
|
};
|
|
77
418
|
class LensFlareEffect extends postprocessing.Effect {
|
|
78
419
|
constructor({
|
|
79
|
-
blendFunction
|
|
80
|
-
enabled
|
|
81
|
-
glareSize
|
|
82
|
-
lensPosition
|
|
83
|
-
|
|
84
|
-
starPoints
|
|
85
|
-
flareSize
|
|
86
|
-
flareSpeed
|
|
87
|
-
flareShape
|
|
88
|
-
animated
|
|
89
|
-
anamorphic
|
|
90
|
-
colorGain
|
|
91
|
-
lensDirtTexture
|
|
92
|
-
haloScale
|
|
93
|
-
secondaryGhosts
|
|
94
|
-
aditionalStreaks
|
|
95
|
-
ghostScale
|
|
96
|
-
opacity
|
|
97
|
-
starBurst
|
|
98
|
-
}
|
|
420
|
+
blendFunction,
|
|
421
|
+
enabled,
|
|
422
|
+
glareSize,
|
|
423
|
+
lensPosition,
|
|
424
|
+
screenRes,
|
|
425
|
+
starPoints,
|
|
426
|
+
flareSize,
|
|
427
|
+
flareSpeed,
|
|
428
|
+
flareShape,
|
|
429
|
+
animated,
|
|
430
|
+
anamorphic,
|
|
431
|
+
colorGain,
|
|
432
|
+
lensDirtTexture,
|
|
433
|
+
haloScale,
|
|
434
|
+
secondaryGhosts,
|
|
435
|
+
aditionalStreaks,
|
|
436
|
+
ghostScale,
|
|
437
|
+
opacity,
|
|
438
|
+
starBurst
|
|
439
|
+
}) {
|
|
99
440
|
super("LensFlareEffect", LensFlareShader.fragmentShader, {
|
|
100
441
|
blendFunction,
|
|
101
442
|
uniforms: /* @__PURE__ */ new Map([
|
|
102
443
|
["enabled", new THREE__namespace.Uniform(enabled)],
|
|
103
444
|
["glareSize", new THREE__namespace.Uniform(glareSize)],
|
|
104
445
|
["lensPosition", new THREE__namespace.Uniform(lensPosition)],
|
|
105
|
-
["
|
|
106
|
-
["
|
|
446
|
+
["time", new THREE__namespace.Uniform(0)],
|
|
447
|
+
["screenRes", new THREE__namespace.Uniform(screenRes)],
|
|
107
448
|
["starPoints", new THREE__namespace.Uniform(starPoints)],
|
|
108
449
|
["flareSize", new THREE__namespace.Uniform(flareSize)],
|
|
109
450
|
["flareSpeed", new THREE__namespace.Uniform(flareSpeed)],
|
|
@@ -122,68 +463,111 @@ class LensFlareEffect extends postprocessing.Effect {
|
|
|
122
463
|
});
|
|
123
464
|
}
|
|
124
465
|
update(_renderer, _inputBuffer, deltaTime) {
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
|
|
466
|
+
const time = this.uniforms.get("time");
|
|
467
|
+
if (time) {
|
|
468
|
+
time.value += deltaTime;
|
|
128
469
|
}
|
|
129
470
|
}
|
|
130
471
|
}
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
472
|
+
const LensFlareWrapped = /* @__PURE__ */ util.wrapEffect(LensFlareEffect);
|
|
473
|
+
const LensFlare = ({
|
|
474
|
+
smoothTime = 0.07,
|
|
475
|
+
//
|
|
476
|
+
blendFunction = postprocessing.BlendFunction.NORMAL,
|
|
477
|
+
enabled = true,
|
|
478
|
+
glareSize = 0.2,
|
|
479
|
+
lensPosition = new THREE__namespace.Vector3(-25, 6, -60),
|
|
480
|
+
screenRes = new THREE__namespace.Vector2(0, 0),
|
|
481
|
+
starPoints = 6,
|
|
482
|
+
flareSize = 0.01,
|
|
483
|
+
flareSpeed = 0.01,
|
|
484
|
+
flareShape = 0.01,
|
|
485
|
+
animated = true,
|
|
486
|
+
anamorphic = false,
|
|
487
|
+
colorGain = new THREE__namespace.Color(20, 20, 20),
|
|
488
|
+
lensDirtTexture = null,
|
|
489
|
+
haloScale = 0.5,
|
|
490
|
+
secondaryGhosts = true,
|
|
491
|
+
aditionalStreaks = true,
|
|
492
|
+
ghostScale = 0,
|
|
493
|
+
opacity = 1,
|
|
494
|
+
starBurst = false
|
|
495
|
+
}) => {
|
|
496
|
+
const viewport = fiber.useThree(({ viewport: viewport2 }) => viewport2);
|
|
497
|
+
const raycaster = fiber.useThree(({ raycaster: raycaster2 }) => raycaster2);
|
|
498
|
+
const { scene, camera } = React.useContext(EffectComposer.EffectComposerContext);
|
|
499
|
+
const [raycasterPos] = React.useState(() => new THREE__namespace.Vector2());
|
|
500
|
+
const [projectedPosition] = React.useState(() => new THREE__namespace.Vector3());
|
|
501
|
+
const ref = React.useRef(null);
|
|
502
|
+
fiber.useFrame((_, delta) => {
|
|
503
|
+
var _a, _b, _c;
|
|
504
|
+
if (!(ref == null ? void 0 : ref.current))
|
|
505
|
+
return;
|
|
506
|
+
const uLensPosition = ref.current.uniforms.get("lensPosition");
|
|
507
|
+
const uOpacity = ref.current.uniforms.get("opacity");
|
|
508
|
+
if (!uLensPosition || !uOpacity)
|
|
509
|
+
return;
|
|
510
|
+
let target = 1;
|
|
511
|
+
projectedPosition.copy(lensPosition).project(camera);
|
|
512
|
+
if (projectedPosition.z > 1)
|
|
513
|
+
return;
|
|
514
|
+
uLensPosition.value.x = projectedPosition.x;
|
|
515
|
+
uLensPosition.value.y = projectedPosition.y;
|
|
516
|
+
raycasterPos.x = projectedPosition.x;
|
|
517
|
+
raycasterPos.y = projectedPosition.y;
|
|
518
|
+
raycaster.setFromCamera(raycasterPos, camera);
|
|
519
|
+
const intersects = raycaster.intersectObjects(scene.children, true);
|
|
520
|
+
const { object } = intersects[0] || {};
|
|
521
|
+
if (object) {
|
|
522
|
+
if (((_a = object.userData) == null ? void 0 : _a.lensflare) === "no-occlusion") {
|
|
150
523
|
target = 0;
|
|
151
|
-
} else {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
raycaster.setFromCamera(mouse2d, camera);
|
|
159
|
-
const intersects = raycaster.intersectObjects(scene.children, true);
|
|
160
|
-
const { object } = intersects[0];
|
|
161
|
-
if (object) {
|
|
162
|
-
if (((_a = object.userData) == null ? void 0 : _a.lensflare) === "no-occlusion") {
|
|
163
|
-
target = 0;
|
|
164
|
-
} else if (object instanceof THREE__namespace.Mesh) {
|
|
165
|
-
if (((_c = (_b = object.material.uniforms) == null ? void 0 : _b._transmission) == null ? void 0 : _c.value) > 0.2) {
|
|
166
|
-
target = 0.2;
|
|
167
|
-
} else if (object.material._transmission && object.material._transmission > 0.2) {
|
|
168
|
-
target = 0.2;
|
|
169
|
-
} else if (object.material.transparent) {
|
|
170
|
-
target = object.material.opacity;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
524
|
+
} else if (object instanceof THREE__namespace.Mesh) {
|
|
525
|
+
if (((_c = (_b = object.material.uniforms) == null ? void 0 : _b._transmission) == null ? void 0 : _c.value) > 0.2) {
|
|
526
|
+
target = 0.2;
|
|
527
|
+
} else if (object.material._transmission && object.material._transmission > 0.2) {
|
|
528
|
+
target = 0.2;
|
|
529
|
+
} else if (object.material.transparent) {
|
|
530
|
+
target = object.material.opacity;
|
|
173
531
|
}
|
|
174
532
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
);
|
|
533
|
+
}
|
|
534
|
+
maath.easing.damp(uOpacity, "value", target, smoothTime, delta);
|
|
535
|
+
});
|
|
536
|
+
React.useEffect(() => {
|
|
537
|
+
if (!(ref == null ? void 0 : ref.current))
|
|
538
|
+
return;
|
|
539
|
+
const screenRes2 = ref.current.uniforms.get("screenRes");
|
|
540
|
+
if (screenRes2) {
|
|
541
|
+
screenRes2.value.x = viewport.width;
|
|
542
|
+
screenRes2.value.y = viewport.height;
|
|
543
|
+
}
|
|
544
|
+
}, [viewport]);
|
|
545
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
546
|
+
LensFlareWrapped,
|
|
547
|
+
{
|
|
548
|
+
ref,
|
|
549
|
+
blendFunction,
|
|
550
|
+
enabled,
|
|
551
|
+
glareSize,
|
|
552
|
+
lensPosition,
|
|
553
|
+
screenRes,
|
|
554
|
+
starPoints,
|
|
555
|
+
flareSize,
|
|
556
|
+
flareSpeed,
|
|
557
|
+
flareShape,
|
|
558
|
+
animated,
|
|
559
|
+
anamorphic,
|
|
560
|
+
colorGain,
|
|
561
|
+
lensDirtTexture,
|
|
562
|
+
haloScale,
|
|
563
|
+
secondaryGhosts,
|
|
564
|
+
aditionalStreaks,
|
|
565
|
+
ghostScale,
|
|
566
|
+
opacity,
|
|
567
|
+
starBurst
|
|
568
|
+
}
|
|
569
|
+
);
|
|
570
|
+
};
|
|
187
571
|
exports.LensFlare = LensFlare;
|
|
188
572
|
exports.LensFlareEffect = LensFlareEffect;
|
|
189
573
|
//# sourceMappingURL=LensFlare.cjs.map
|