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