@chromatic-coherence/generative-engine 1.1.0 → 1.3.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 +137 -120
- package/dist/post.d.ts +13 -0
- package/dist/post.js +44 -4
- package/dist/shaders.d.ts +4 -0
- package/dist/shaders.js +362 -274
- package/dist/world.d.ts +37 -0
- package/dist/world.js +108 -2
- package/package.json +44 -44
package/dist/shaders.js
CHANGED
|
@@ -5,303 +5,391 @@
|
|
|
5
5
|
// maps, and HDR output for the post chain. No clamping in the scene pass — light
|
|
6
6
|
// is allowed to exceed 1.0 and the composite tone-maps it.
|
|
7
7
|
// ── shared vertex preamble: 8 groups, each with a mat4, normal mat3, morph weight, alpha ──
|
|
8
|
-
const GROUPS = `
|
|
8
|
+
const GROUPS = `
|
|
9
9
|
uniform mat4 uGM[8]; uniform mat3 uNM[8]; uniform float uMW[8]; uniform float uGA[8];`;
|
|
10
|
-
export const FACE_VS = `#version 300 es
|
|
11
|
-
in vec3 aPos; in vec3 aNorm; in vec4 aCol; in float aBlood; in float aGrp;
|
|
12
|
-
in vec3 aPos2; in vec3 aNorm2;
|
|
13
|
-
uniform mat4 uVP; uniform mat4 uSVP;${GROUPS}
|
|
14
|
-
out vec3 vPos; out vec3 vNorm; out vec4 vCol; out float vZ; out vec4 vSh;
|
|
15
|
-
out float vGA; out float vBlood;
|
|
16
|
-
void main(){
|
|
17
|
-
int g = int(aGrp + 0.5);
|
|
18
|
-
float w = uMW[g];
|
|
19
|
-
vec3 p = mix(aPos, aPos2, w), n = mix(aNorm, aNorm2, w);
|
|
20
|
-
vec4 wp = uGM[g] * vec4(p, 1.0);
|
|
21
|
-
vPos = wp.xyz; vNorm = uNM[g] * n; vCol = aCol; vGA = uGA[g]; vBlood = aBlood;
|
|
22
|
-
vec4 cp = uVP * wp; vZ = cp.w; vSh = uSVP * wp; gl_Position = cp;
|
|
10
|
+
export const FACE_VS = `#version 300 es
|
|
11
|
+
in vec3 aPos; in vec3 aNorm; in vec4 aCol; in float aBlood; in float aGrp;
|
|
12
|
+
in vec3 aPos2; in vec3 aNorm2;
|
|
13
|
+
uniform mat4 uVP; uniform mat4 uSVP;${GROUPS}
|
|
14
|
+
out vec3 vPos; out vec3 vNorm; out vec4 vCol; out float vZ; out vec4 vSh;
|
|
15
|
+
out float vGA; out float vBlood;
|
|
16
|
+
void main(){
|
|
17
|
+
int g = int(aGrp + 0.5);
|
|
18
|
+
float w = uMW[g];
|
|
19
|
+
vec3 p = mix(aPos, aPos2, w), n = mix(aNorm, aNorm2, w);
|
|
20
|
+
vec4 wp = uGM[g] * vec4(p, 1.0);
|
|
21
|
+
vPos = wp.xyz; vNorm = uNM[g] * n; vCol = aCol; vGA = uGA[g]; vBlood = aBlood;
|
|
22
|
+
vec4 cp = uVP * wp; vZ = cp.w; vSh = uSVP * wp; gl_Position = cp;
|
|
23
23
|
}`;
|
|
24
|
-
export const FACE_FS = `#version 300 es
|
|
25
|
-
precision highp float;
|
|
26
|
-
in vec3 vPos; in vec3 vNorm; in vec4 vCol; in float vZ; in vec4 vSh;
|
|
27
|
-
in float vGA; in float vBlood;
|
|
28
|
-
uniform vec3 uLdir; uniform float uAmb; uniform float uDif; uniform float uSigned;
|
|
29
|
-
uniform vec3 uLp[8]; uniform float uLi[8]; uniform float uLf[8]; uniform int uLn;
|
|
30
|
-
uniform vec3 uCam; uniform float uFogK; uniform float uSpec; uniform vec3 uBg;
|
|
31
|
-
uniform vec3 uSkyC; uniform vec3 uGroundC; uniform float uPulse;
|
|
32
|
-
uniform float uShadowOn; uniform float uShadowSoft; uniform float uShadowBias;
|
|
33
|
-
uniform lowp sampler2DShadow uShadow; uniform float uShadowPx;
|
|
34
|
-
out vec4 fragColor;
|
|
35
|
-
float h3(vec3 p){ return fract(sin(dot(p, vec3(12.9898, 78.233, 37.719))) * 43758.5453); }
|
|
36
|
-
float vnoise(vec3 p){ vec3 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);
|
|
37
|
-
return mix(mix(mix(h3(i), h3(i + vec3(1,0,0)), f.x), mix(h3(i + vec3(0,1,0)), h3(i + vec3(1,1,0)), f.x), f.y),
|
|
38
|
-
mix(mix(h3(i + vec3(0,0,1)), h3(i + vec3(1,0,1)), f.x), mix(h3(i + vec3(0,1,1)), h3(i + vec3(1,1,1)), f.x), f.y), f.z); }
|
|
39
|
-
float shadowFactor(){
|
|
40
|
-
vec3 pr = vSh.xyz / vSh.w * 0.5 + 0.5;
|
|
41
|
-
if (pr.x < 0.0 || pr.x > 1.0 || pr.y < 0.0 || pr.y > 1.0 || pr.z > 1.0) return 1.0;
|
|
42
|
-
float ref = pr.z - uShadowBias;
|
|
43
|
-
// 3x3 taps over a hardware-compared (LINEAR sampler2DShadow => free 2x2 PCF each) map
|
|
44
|
-
float s = 0.0;
|
|
45
|
-
for (int sy = -1; sy <= 1; sy++)
|
|
46
|
-
for (int sx = -1; sx <= 1; sx++)
|
|
47
|
-
s += texture(uShadow, vec3(pr.xy + vec2(float(sx), float(sy)) * uShadowPx * uShadowSoft, ref));
|
|
48
|
-
s /= 9.0;
|
|
49
|
-
return 0.35 + 0.65 * s;
|
|
50
|
-
}
|
|
51
|
-
void main(){
|
|
52
|
-
vec3 n = normalize(vNorm);
|
|
53
|
-
vec3 V = normalize(uCam - vPos);
|
|
54
|
-
float skin = clamp(vBlood * 5.0, 0.0, 1.0);
|
|
55
|
-
{ // procedural micro-relief: perturb the shading normal by a fine noise gradient
|
|
56
|
-
float bs = 5.5, e = 0.12, n0 = vnoise(vPos * bs);
|
|
57
|
-
vec3 g = vec3(vnoise(vPos * bs + vec3(e, 0.0, 0.0)) - n0,
|
|
58
|
-
vnoise(vPos * bs + vec3(0.0, e, 0.0)) - n0,
|
|
59
|
-
vnoise(vPos * bs + vec3(0.0, 0.0, e)) - n0) / e;
|
|
60
|
-
n = normalize(n - g * (0.10 + 0.30 * skin));
|
|
61
|
-
}
|
|
62
|
-
float d = dot(n, normalize(uLdir));
|
|
63
|
-
float shade = uAmb + uDif * mix(abs(d), max(d, 0.0), uSigned);
|
|
64
|
-
float spec = 0.0;
|
|
65
|
-
float sh = uShadowOn > 0.5 ? shadowFactor() : 1.0;
|
|
66
|
-
for (int i = 0; i < 8; i++) { if (i >= uLn) break;
|
|
67
|
-
vec3 v = uLp[i] - vPos; float d2 = dot(v, v); vec3 L = v * inversesqrt(d2 + 1e-4);
|
|
68
|
-
float lam = dot(n, L); lam = mix(abs(lam), max(lam, 0.0), uSigned);
|
|
69
|
-
float fall = 1.0 / (1.0 + d2 / (uLf[i] * uLf[i]));
|
|
70
|
-
float k = (i == 0) ? sh : 1.0;
|
|
71
|
-
shade += uLi[i] * lam * fall * k;
|
|
72
|
-
// GGX microfacet + Fresnel — roughness from the face's gloss (colour alpha slot)
|
|
73
|
-
vec3 H = normalize(L + V);
|
|
74
|
-
float nh = max(dot(n, H), 0.0);
|
|
75
|
-
float rough = clamp(1.0 - vCol.a, 0.08, 1.0), a2 = rough * rough; a2 = a2 * a2;
|
|
76
|
-
float dnm = nh * nh * (a2 - 1.0) + 1.0;
|
|
77
|
-
float ggx = a2 / (3.14159 * dnm * dnm);
|
|
78
|
-
float fres = 0.04 + 0.96 * pow(1.0 - max(dot(H, V), 0.0), 5.0);
|
|
79
|
-
spec += uLi[i] * min(ggx, 6.0) * fres * fall * k * 0.16;
|
|
80
|
-
}
|
|
81
|
-
// coloured hemispheric ambient: cool from above, warm from below
|
|
82
|
-
vec3 tint = mix(uGroundC, uSkyC, n.y * 0.5 + 0.5);
|
|
83
|
-
vec3 lit = vCol.rgb * (uAmb * tint + vec3(shade - uAmb));
|
|
84
|
-
// the perfusion term: blood near the surface changes how it meets the light
|
|
85
|
-
float b = clamp(vBlood + uPulse * vBlood * 6.0, 0.0, 1.0);
|
|
86
|
-
lit *= mix(vec3(1.0), vec3(1.07, 0.95, 0.94), b);
|
|
87
|
-
lit += vec3(0.62, 0.06, 0.08) * (b * 0.20 * (1.0 - abs(d)));
|
|
88
|
-
// pore noise, only where there is blood (skin, not cloth)
|
|
89
|
-
float pore = vnoise(vPos * 2.4) * 0.6 + vnoise(vPos * 6.0) * 0.4;
|
|
90
|
-
lit *= 1.0 + (pore - 0.5) * 0.09 * skin;
|
|
91
|
-
// subsurface rim: grazing light bleeds through thin tissue, warm
|
|
92
|
-
float fres = pow(1.0 - clamp(dot(n, V), 0.0, 1.0), 3.0);
|
|
93
|
-
lit += vec3(0.55, 0.09, 0.10) * fres * skin * (0.28 + 0.5 * b);
|
|
94
|
-
float fog = clamp(uFogK / vZ, 0.08, 1.0);
|
|
95
|
-
vec3 outC = lit + vec3(1.0) * spec * uSpec * vCol.a;
|
|
96
|
-
// fog and fades resolve toward the REAL background colour (the engine owns its ground)
|
|
97
|
-
fragColor = vec4(mix(uBg, outC, fog * vGA), 1.0);
|
|
24
|
+
export const FACE_FS = `#version 300 es
|
|
25
|
+
precision highp float;
|
|
26
|
+
in vec3 vPos; in vec3 vNorm; in vec4 vCol; in float vZ; in vec4 vSh;
|
|
27
|
+
in float vGA; in float vBlood;
|
|
28
|
+
uniform vec3 uLdir; uniform float uAmb; uniform float uDif; uniform float uSigned;
|
|
29
|
+
uniform vec3 uLp[8]; uniform float uLi[8]; uniform float uLf[8]; uniform int uLn;
|
|
30
|
+
uniform vec3 uCam; uniform float uFogK; uniform float uSpec; uniform vec3 uBg;
|
|
31
|
+
uniform vec3 uSkyC; uniform vec3 uGroundC; uniform float uPulse;
|
|
32
|
+
uniform float uShadowOn; uniform float uShadowSoft; uniform float uShadowBias;
|
|
33
|
+
uniform lowp sampler2DShadow uShadow; uniform float uShadowPx;
|
|
34
|
+
out vec4 fragColor;
|
|
35
|
+
float h3(vec3 p){ return fract(sin(dot(p, vec3(12.9898, 78.233, 37.719))) * 43758.5453); }
|
|
36
|
+
float vnoise(vec3 p){ vec3 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);
|
|
37
|
+
return mix(mix(mix(h3(i), h3(i + vec3(1,0,0)), f.x), mix(h3(i + vec3(0,1,0)), h3(i + vec3(1,1,0)), f.x), f.y),
|
|
38
|
+
mix(mix(h3(i + vec3(0,0,1)), h3(i + vec3(1,0,1)), f.x), mix(h3(i + vec3(0,1,1)), h3(i + vec3(1,1,1)), f.x), f.y), f.z); }
|
|
39
|
+
float shadowFactor(){
|
|
40
|
+
vec3 pr = vSh.xyz / vSh.w * 0.5 + 0.5;
|
|
41
|
+
if (pr.x < 0.0 || pr.x > 1.0 || pr.y < 0.0 || pr.y > 1.0 || pr.z > 1.0) return 1.0;
|
|
42
|
+
float ref = pr.z - uShadowBias;
|
|
43
|
+
// 3x3 taps over a hardware-compared (LINEAR sampler2DShadow => free 2x2 PCF each) map
|
|
44
|
+
float s = 0.0;
|
|
45
|
+
for (int sy = -1; sy <= 1; sy++)
|
|
46
|
+
for (int sx = -1; sx <= 1; sx++)
|
|
47
|
+
s += texture(uShadow, vec3(pr.xy + vec2(float(sx), float(sy)) * uShadowPx * uShadowSoft, ref));
|
|
48
|
+
s /= 9.0;
|
|
49
|
+
return 0.35 + 0.65 * s;
|
|
50
|
+
}
|
|
51
|
+
void main(){
|
|
52
|
+
vec3 n = normalize(vNorm);
|
|
53
|
+
vec3 V = normalize(uCam - vPos);
|
|
54
|
+
float skin = clamp(vBlood * 5.0, 0.0, 1.0);
|
|
55
|
+
{ // procedural micro-relief: perturb the shading normal by a fine noise gradient
|
|
56
|
+
float bs = 5.5, e = 0.12, n0 = vnoise(vPos * bs);
|
|
57
|
+
vec3 g = vec3(vnoise(vPos * bs + vec3(e, 0.0, 0.0)) - n0,
|
|
58
|
+
vnoise(vPos * bs + vec3(0.0, e, 0.0)) - n0,
|
|
59
|
+
vnoise(vPos * bs + vec3(0.0, 0.0, e)) - n0) / e;
|
|
60
|
+
n = normalize(n - g * (0.10 + 0.30 * skin));
|
|
61
|
+
}
|
|
62
|
+
float d = dot(n, normalize(uLdir));
|
|
63
|
+
float shade = uAmb + uDif * mix(abs(d), max(d, 0.0), uSigned);
|
|
64
|
+
float spec = 0.0;
|
|
65
|
+
float sh = uShadowOn > 0.5 ? shadowFactor() : 1.0;
|
|
66
|
+
for (int i = 0; i < 8; i++) { if (i >= uLn) break;
|
|
67
|
+
vec3 v = uLp[i] - vPos; float d2 = dot(v, v); vec3 L = v * inversesqrt(d2 + 1e-4);
|
|
68
|
+
float lam = dot(n, L); lam = mix(abs(lam), max(lam, 0.0), uSigned);
|
|
69
|
+
float fall = 1.0 / (1.0 + d2 / (uLf[i] * uLf[i]));
|
|
70
|
+
float k = (i == 0) ? sh : 1.0;
|
|
71
|
+
shade += uLi[i] * lam * fall * k;
|
|
72
|
+
// GGX microfacet + Fresnel — roughness from the face's gloss (colour alpha slot)
|
|
73
|
+
vec3 H = normalize(L + V);
|
|
74
|
+
float nh = max(dot(n, H), 0.0);
|
|
75
|
+
float rough = clamp(1.0 - vCol.a, 0.08, 1.0), a2 = rough * rough; a2 = a2 * a2;
|
|
76
|
+
float dnm = nh * nh * (a2 - 1.0) + 1.0;
|
|
77
|
+
float ggx = a2 / (3.14159 * dnm * dnm);
|
|
78
|
+
float fres = 0.04 + 0.96 * pow(1.0 - max(dot(H, V), 0.0), 5.0);
|
|
79
|
+
spec += uLi[i] * min(ggx, 6.0) * fres * fall * k * 0.16;
|
|
80
|
+
}
|
|
81
|
+
// coloured hemispheric ambient: cool from above, warm from below
|
|
82
|
+
vec3 tint = mix(uGroundC, uSkyC, n.y * 0.5 + 0.5);
|
|
83
|
+
vec3 lit = vCol.rgb * (uAmb * tint + vec3(shade - uAmb));
|
|
84
|
+
// the perfusion term: blood near the surface changes how it meets the light
|
|
85
|
+
float b = clamp(vBlood + uPulse * vBlood * 6.0, 0.0, 1.0);
|
|
86
|
+
lit *= mix(vec3(1.0), vec3(1.07, 0.95, 0.94), b);
|
|
87
|
+
lit += vec3(0.62, 0.06, 0.08) * (b * 0.20 * (1.0 - abs(d)));
|
|
88
|
+
// pore noise, only where there is blood (skin, not cloth)
|
|
89
|
+
float pore = vnoise(vPos * 2.4) * 0.6 + vnoise(vPos * 6.0) * 0.4;
|
|
90
|
+
lit *= 1.0 + (pore - 0.5) * 0.09 * skin;
|
|
91
|
+
// subsurface rim: grazing light bleeds through thin tissue, warm
|
|
92
|
+
float fres = pow(1.0 - clamp(dot(n, V), 0.0, 1.0), 3.0);
|
|
93
|
+
lit += vec3(0.55, 0.09, 0.10) * fres * skin * (0.28 + 0.5 * b);
|
|
94
|
+
float fog = clamp(uFogK / vZ, 0.08, 1.0);
|
|
95
|
+
vec3 outC = lit + vec3(1.0) * spec * uSpec * vCol.a;
|
|
96
|
+
// fog and fades resolve toward the REAL background colour (the engine owns its ground)
|
|
97
|
+
fragColor = vec4(mix(uBg, outC, fog * vGA), 1.0);
|
|
98
98
|
}`;
|
|
99
99
|
// depth-only pass (shadow map) — same morph + group transforms, no colour output
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
// instanced face VS (W8): the per-instance model matrix arrives as 4 vec4 attributes
|
|
101
|
+
// (divisor 1) and composes INSIDE the group transform — instances ride their group's
|
|
102
|
+
// fade / morph / transform like any other geometry. Normals use mat3(instance); with
|
|
103
|
+
// rotation + uniform scale that is exact (the normalize() in the FS absorbs scale).
|
|
104
|
+
export const FACE_INST_VS = `#version 300 es
|
|
105
|
+
in vec3 aPos; in vec3 aNorm; in vec4 aCol; in float aBlood; in float aGrp;
|
|
106
|
+
in vec3 aPos2; in vec3 aNorm2;
|
|
107
|
+
in vec4 aI0; in vec4 aI1; in vec4 aI2; in vec4 aI3; in vec4 aIP;
|
|
108
|
+
uniform mat4 uVP; uniform mat4 uSVP; uniform float uT; uniform vec3 uWindDir;${GROUPS}
|
|
109
|
+
out vec3 vPos; out vec3 vNorm; out vec4 vCol; out float vZ; out vec4 vSh;
|
|
110
|
+
out float vGA; out float vBlood;
|
|
111
|
+
void main(){
|
|
112
|
+
int g = int(aGrp + 0.5);
|
|
113
|
+
float w = uMW[g];
|
|
114
|
+
mat4 inst = mat4(aI0, aI1, aI2, aI3);
|
|
115
|
+
vec3 p = mix(aPos, aPos2, w), n = mix(aNorm, aNorm2, w);
|
|
116
|
+
// W9 GPU WIND: per-instance (phase, freq, amp); displacement grows with height,
|
|
117
|
+
// plus a second harmonic so the sway breathes instead of ticking
|
|
118
|
+
float sw = sin(uT * aIP.y + aIP.x) + 0.5 * sin(uT * aIP.y * 2.3 + aIP.x * 1.7);
|
|
119
|
+
p += uWindDir * (sw * aIP.z * max(p.y, 0.0));
|
|
120
|
+
vec4 wp = uGM[g] * (inst * vec4(p, 1.0));
|
|
121
|
+
vPos = wp.xyz; vNorm = uNM[g] * (mat3(inst) * n); vCol = aCol; vGA = uGA[g]; vBlood = aBlood;
|
|
122
|
+
vec4 cp = uVP * wp; vZ = cp.w; vSh = uSVP * wp; gl_Position = cp;
|
|
107
123
|
}`;
|
|
108
|
-
export const
|
|
109
|
-
|
|
124
|
+
export const DEPTH_INST_VS = `#version 300 es
|
|
125
|
+
in vec3 aPos; in float aGrp; in vec3 aPos2;
|
|
126
|
+
in vec4 aI0; in vec4 aI1; in vec4 aI2; in vec4 aI3; in vec4 aIP;
|
|
127
|
+
uniform mat4 uVP; uniform float uT; uniform vec3 uWindDir;${GROUPS}
|
|
128
|
+
void main(){
|
|
129
|
+
int g = int(aGrp + 0.5);
|
|
130
|
+
vec3 p = mix(aPos, aPos2, uMW[g]);
|
|
131
|
+
float sw = sin(uT * aIP.y + aIP.x) + 0.5 * sin(uT * aIP.y * 2.3 + aIP.x * 1.7);
|
|
132
|
+
p += uWindDir * (sw * aIP.z * max(p.y, 0.0));
|
|
133
|
+
gl_Position = uVP * (uGM[g] * (mat4(aI0, aI1, aI2, aI3) * vec4(p, 1.0)));
|
|
134
|
+
}`;
|
|
135
|
+
export const DEPTH_VS = `#version 300 es
|
|
136
|
+
in vec3 aPos; in float aGrp; in vec3 aPos2;
|
|
137
|
+
uniform mat4 uVP;${GROUPS}
|
|
138
|
+
void main(){
|
|
139
|
+
int g = int(aGrp + 0.5);
|
|
140
|
+
vec3 p = mix(aPos, aPos2, uMW[g]);
|
|
141
|
+
gl_Position = uVP * (uGM[g] * vec4(p, 1.0));
|
|
142
|
+
}`;
|
|
143
|
+
export const DEPTH_FS = `#version 300 es
|
|
144
|
+
precision mediump float;
|
|
110
145
|
void main(){}`;
|
|
111
|
-
export const LINE_VS = `#version 300 es
|
|
112
|
-
in vec3 aPos; in vec4 aCol; in float aGrp;
|
|
113
|
-
uniform mat4 uVP;${GROUPS}
|
|
114
|
-
out vec4 vCol; out float vZ; out float vGA;
|
|
115
|
-
void main(){
|
|
116
|
-
int g = int(aGrp + 0.5);
|
|
117
|
-
vCol = aCol; vGA = uGA[g];
|
|
118
|
-
vec4 p = uVP * (uGM[g] * vec4(aPos, 1.0)); vZ = p.w; gl_Position = p;
|
|
146
|
+
export const LINE_VS = `#version 300 es
|
|
147
|
+
in vec3 aPos; in vec4 aCol; in float aGrp;
|
|
148
|
+
uniform mat4 uVP;${GROUPS}
|
|
149
|
+
out vec4 vCol; out float vZ; out float vGA;
|
|
150
|
+
void main(){
|
|
151
|
+
int g = int(aGrp + 0.5);
|
|
152
|
+
vCol = aCol; vGA = uGA[g];
|
|
153
|
+
vec4 p = uVP * (uGM[g] * vec4(aPos, 1.0)); vZ = p.w; gl_Position = p;
|
|
119
154
|
}`;
|
|
120
|
-
export const LINE_FS = `#version 300 es
|
|
121
|
-
precision mediump float;
|
|
122
|
-
in vec4 vCol; in float vZ; in float vGA;
|
|
123
|
-
uniform float uFogK; uniform float uInk;
|
|
124
|
-
out vec4 fragColor;
|
|
125
|
-
void main(){
|
|
126
|
-
float fog = clamp(uFogK / vZ, 0.08, 1.0);
|
|
127
|
-
if (uInk > 0.5) fragColor = vec4(vCol.rgb, min(1.0, vCol.a * 1.6) * fog * vGA);
|
|
128
|
-
else fragColor = vec4(vCol.rgb * fog, vCol.a * fog * vGA);
|
|
155
|
+
export const LINE_FS = `#version 300 es
|
|
156
|
+
precision mediump float;
|
|
157
|
+
in vec4 vCol; in float vZ; in float vGA;
|
|
158
|
+
uniform float uFogK; uniform float uInk;
|
|
159
|
+
out vec4 fragColor;
|
|
160
|
+
void main(){
|
|
161
|
+
float fog = clamp(uFogK / vZ, 0.08, 1.0);
|
|
162
|
+
if (uInk > 0.5) fragColor = vec4(vCol.rgb, min(1.0, vCol.a * 1.6) * fog * vGA);
|
|
163
|
+
else fragColor = vec4(vCol.rgb * fog, vCol.a * fog * vGA);
|
|
129
164
|
}`;
|
|
130
|
-
export const PT_VS = `#version 300 es
|
|
131
|
-
in vec3 aPos; in float aSize; in vec4 aCol; in float aGrp;
|
|
132
|
-
uniform mat4 uVP; uniform float uFocal;${GROUPS}
|
|
133
|
-
out vec4 vCol; out float vZ; out float vGA;
|
|
134
|
-
void main(){
|
|
135
|
-
int g = int(aGrp + 0.5);
|
|
136
|
-
vCol = aCol; vGA = uGA[g];
|
|
137
|
-
vec4 p = uVP * (uGM[g] * vec4(aPos, 1.0)); vZ = p.w;
|
|
138
|
-
gl_PointSize = clamp(aSize * uFocal / p.w, 1.0, 256.0); gl_Position = p;
|
|
165
|
+
export const PT_VS = `#version 300 es
|
|
166
|
+
in vec3 aPos; in float aSize; in vec4 aCol; in float aGrp;
|
|
167
|
+
uniform mat4 uVP; uniform float uFocal;${GROUPS}
|
|
168
|
+
out vec4 vCol; out float vZ; out float vGA;
|
|
169
|
+
void main(){
|
|
170
|
+
int g = int(aGrp + 0.5);
|
|
171
|
+
vCol = aCol; vGA = uGA[g];
|
|
172
|
+
vec4 p = uVP * (uGM[g] * vec4(aPos, 1.0)); vZ = p.w;
|
|
173
|
+
gl_PointSize = clamp(aSize * uFocal / p.w, 1.0, 256.0); gl_Position = p;
|
|
139
174
|
}`;
|
|
140
|
-
export const PT_FS = `#version 300 es
|
|
141
|
-
precision mediump float;
|
|
142
|
-
in vec4 vCol; in float vZ; in float vGA;
|
|
143
|
-
uniform float uFogK; uniform float uInk;
|
|
144
|
-
out vec4 fragColor;
|
|
145
|
-
void main(){
|
|
146
|
-
float r = length(gl_PointCoord - 0.5) * 2.0;
|
|
147
|
-
float a = exp(-3.2 * r * r) * (1.0 - smoothstep(0.85, 1.0, r));
|
|
148
|
-
float fog = clamp(uFogK / vZ, 0.08, 1.0);
|
|
149
|
-
if (uInk > 0.5) fragColor = vec4(vCol.rgb, min(1.0, vCol.a * 1.6) * a * fog * vGA);
|
|
150
|
-
else fragColor = vec4(vCol.rgb, 1.0) * (vCol.a * a * fog * vGA);
|
|
175
|
+
export const PT_FS = `#version 300 es
|
|
176
|
+
precision mediump float;
|
|
177
|
+
in vec4 vCol; in float vZ; in float vGA;
|
|
178
|
+
uniform float uFogK; uniform float uInk;
|
|
179
|
+
out vec4 fragColor;
|
|
180
|
+
void main(){
|
|
181
|
+
float r = length(gl_PointCoord - 0.5) * 2.0;
|
|
182
|
+
float a = exp(-3.2 * r * r) * (1.0 - smoothstep(0.85, 1.0, r));
|
|
183
|
+
float fog = clamp(uFogK / vZ, 0.08, 1.0);
|
|
184
|
+
if (uInk > 0.5) fragColor = vec4(vCol.rgb, min(1.0, vCol.a * 1.6) * a * fog * vGA);
|
|
185
|
+
else fragColor = vec4(vCol.rgb, 1.0) * (vCol.a * a * fog * vGA);
|
|
151
186
|
}`;
|
|
152
187
|
// ── ribbons: screen-space-expanded strokes with real pixel width ──
|
|
153
188
|
// Each vertex carries its neighbours; the direction is the central difference in
|
|
154
189
|
// screen space, so joins round themselves. aSide is -1/+1; the fragment feathers
|
|
155
190
|
// the edge for free antialiasing.
|
|
156
|
-
export const RIBBON_VS = `#version 300 es
|
|
157
|
-
in vec3 aPos; in vec3 aPrev; in vec3 aNext; in float aSide; in float aWidth;
|
|
158
|
-
in vec4 aCol; in float aGrp;
|
|
159
|
-
uniform mat4 uVP; uniform vec2 uRes;${GROUPS}
|
|
160
|
-
out vec4 vCol; out float vZ; out float vGA; out float vSide;
|
|
161
|
-
void main(){
|
|
162
|
-
int g = int(aGrp + 0.5);
|
|
163
|
-
mat4 M = uGM[g];
|
|
164
|
-
vec4 cp = uVP * (M * vec4(aPos, 1.0));
|
|
165
|
-
vec4 cq = uVP * (M * vec4(aPrev, 1.0));
|
|
166
|
-
vec4 cr = uVP * (M * vec4(aNext, 1.0));
|
|
167
|
-
vec2 sp = cp.xy / max(cp.w, 1e-4) * uRes;
|
|
168
|
-
vec2 sq = cq.xy / max(cq.w, 1e-4) * uRes;
|
|
169
|
-
vec2 sr = cr.xy / max(cr.w, 1e-4) * uRes;
|
|
170
|
-
vec2 dir = sr - sq;
|
|
171
|
-
float dl = length(dir);
|
|
172
|
-
dir = dl > 1e-3 ? dir / dl : vec2(1.0, 0.0);
|
|
173
|
-
vec2 perp = vec2(-dir.y, dir.x);
|
|
174
|
-
vec2 off = perp * aWidth * 0.5 * aSide;
|
|
175
|
-
cp.xy += off / uRes * cp.w * 2.0;
|
|
176
|
-
vCol = aCol; vZ = cp.w; vGA = uGA[g]; vSide = aSide;
|
|
177
|
-
gl_Position = cp;
|
|
191
|
+
export const RIBBON_VS = `#version 300 es
|
|
192
|
+
in vec3 aPos; in vec3 aPrev; in vec3 aNext; in float aSide; in float aWidth;
|
|
193
|
+
in vec4 aCol; in float aGrp;
|
|
194
|
+
uniform mat4 uVP; uniform vec2 uRes;${GROUPS}
|
|
195
|
+
out vec4 vCol; out float vZ; out float vGA; out float vSide;
|
|
196
|
+
void main(){
|
|
197
|
+
int g = int(aGrp + 0.5);
|
|
198
|
+
mat4 M = uGM[g];
|
|
199
|
+
vec4 cp = uVP * (M * vec4(aPos, 1.0));
|
|
200
|
+
vec4 cq = uVP * (M * vec4(aPrev, 1.0));
|
|
201
|
+
vec4 cr = uVP * (M * vec4(aNext, 1.0));
|
|
202
|
+
vec2 sp = cp.xy / max(cp.w, 1e-4) * uRes;
|
|
203
|
+
vec2 sq = cq.xy / max(cq.w, 1e-4) * uRes;
|
|
204
|
+
vec2 sr = cr.xy / max(cr.w, 1e-4) * uRes;
|
|
205
|
+
vec2 dir = sr - sq;
|
|
206
|
+
float dl = length(dir);
|
|
207
|
+
dir = dl > 1e-3 ? dir / dl : vec2(1.0, 0.0);
|
|
208
|
+
vec2 perp = vec2(-dir.y, dir.x);
|
|
209
|
+
vec2 off = perp * aWidth * 0.5 * aSide;
|
|
210
|
+
cp.xy += off / uRes * cp.w * 2.0;
|
|
211
|
+
vCol = aCol; vZ = cp.w; vGA = uGA[g]; vSide = aSide;
|
|
212
|
+
gl_Position = cp;
|
|
178
213
|
}`;
|
|
179
|
-
export const RIBBON_FS = `#version 300 es
|
|
180
|
-
precision mediump float;
|
|
181
|
-
in vec4 vCol; in float vZ; in float vGA; in float vSide;
|
|
182
|
-
uniform float uFogK; uniform float uInk;
|
|
183
|
-
out vec4 fragColor;
|
|
184
|
-
void main(){
|
|
185
|
-
float edge = 1.0 - smoothstep(0.55, 1.0, abs(vSide));
|
|
186
|
-
float fog = clamp(uFogK / vZ, 0.08, 1.0);
|
|
187
|
-
float a = vCol.a * edge * fog * vGA;
|
|
188
|
-
if (uInk > 0.5) fragColor = vec4(vCol.rgb, min(1.0, a * 1.6));
|
|
189
|
-
else fragColor = vec4(vCol.rgb * a, a);
|
|
214
|
+
export const RIBBON_FS = `#version 300 es
|
|
215
|
+
precision mediump float;
|
|
216
|
+
in vec4 vCol; in float vZ; in float vGA; in float vSide;
|
|
217
|
+
uniform float uFogK; uniform float uInk;
|
|
218
|
+
out vec4 fragColor;
|
|
219
|
+
void main(){
|
|
220
|
+
float edge = 1.0 - smoothstep(0.55, 1.0, abs(vSide));
|
|
221
|
+
float fog = clamp(uFogK / vZ, 0.08, 1.0);
|
|
222
|
+
float a = vCol.a * edge * fog * vGA;
|
|
223
|
+
if (uInk > 0.5) fragColor = vec4(vCol.rgb, min(1.0, a * 1.6));
|
|
224
|
+
else fragColor = vec4(vCol.rgb * a, a);
|
|
190
225
|
}`;
|
|
191
226
|
// ── post chain ──
|
|
192
227
|
// fullscreen triangle, attribute-less (gl_VertexID)
|
|
193
|
-
export const FST_VS = `#version 300 es
|
|
194
|
-
out vec2 vUv;
|
|
195
|
-
void main(){
|
|
196
|
-
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
197
|
-
vUv = p; gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
228
|
+
export const FST_VS = `#version 300 es
|
|
229
|
+
out vec2 vUv;
|
|
230
|
+
void main(){
|
|
231
|
+
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
232
|
+
vUv = p; gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
233
|
+
}`;
|
|
234
|
+
export const BRIGHT_FS = `#version 300 es
|
|
235
|
+
precision mediump float;
|
|
236
|
+
in vec2 vUv; uniform sampler2D uTex; uniform float uThresh; uniform float uKnee;
|
|
237
|
+
out vec4 fragColor;
|
|
238
|
+
void main(){
|
|
239
|
+
vec3 c = texture(uTex, vUv).rgb;
|
|
240
|
+
float luma = max(c.r, max(c.g, c.b));
|
|
241
|
+
float w = smoothstep(uThresh, uThresh + uKnee, luma);
|
|
242
|
+
fragColor = vec4(c * w, 1.0);
|
|
243
|
+
}`;
|
|
244
|
+
export const BLUR_FS = `#version 300 es
|
|
245
|
+
precision mediump float;
|
|
246
|
+
in vec2 vUv; uniform sampler2D uTex; uniform vec2 uDir;
|
|
247
|
+
out vec4 fragColor;
|
|
248
|
+
void main(){
|
|
249
|
+
vec3 s = texture(uTex, vUv).rgb * 0.227027;
|
|
250
|
+
vec2 o1 = uDir * 1.3846153846, o2 = uDir * 3.2307692308;
|
|
251
|
+
s += (texture(uTex, vUv + o1).rgb + texture(uTex, vUv - o1).rgb) * 0.3162162162;
|
|
252
|
+
s += (texture(uTex, vUv + o2).rgb + texture(uTex, vUv - o2).rgb) * 0.0702702703;
|
|
253
|
+
fragColor = vec4(s, 1.0);
|
|
198
254
|
}`;
|
|
199
|
-
export const
|
|
200
|
-
precision
|
|
201
|
-
in vec2 vUv; uniform sampler2D
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
float
|
|
206
|
-
|
|
207
|
-
|
|
255
|
+
export const SSAO_FS = `#version 300 es
|
|
256
|
+
precision highp float;
|
|
257
|
+
in vec2 vUv; uniform sampler2D uDepth;
|
|
258
|
+
uniform float uNear; uniform float uFar; uniform float uRadius; uniform vec2 uRes;
|
|
259
|
+
out vec4 fragColor;
|
|
260
|
+
float viewZ(vec2 uv){
|
|
261
|
+
float d = texture(uDepth, uv).r * 2.0 - 1.0;
|
|
262
|
+
return 2.0 * uNear * uFar / (uFar + uNear - d * (uFar - uNear));
|
|
263
|
+
}
|
|
264
|
+
float hash(vec2 p){ return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); }
|
|
265
|
+
void main(){
|
|
266
|
+
float z0 = viewZ(vUv);
|
|
267
|
+
// screen-space sample radius shrinks with distance (a world-ish radius)
|
|
268
|
+
float rad = uRadius / z0;
|
|
269
|
+
float ang = hash(vUv * uRes) * 6.2831853;
|
|
270
|
+
float occ = 0.0;
|
|
271
|
+
for (int i = 0; i < 12; i++) {
|
|
272
|
+
float fi = float(i);
|
|
273
|
+
float a = ang + fi * 2.3999632; // golden-angle spiral
|
|
274
|
+
float r = rad * (0.25 + 0.75 * fract(fi * 0.618034));
|
|
275
|
+
vec2 uv = vUv + vec2(cos(a), sin(a)) * r;
|
|
276
|
+
float dz = z0 - viewZ(uv); // positive => sample nearer camera => occluder
|
|
277
|
+
occ += smoothstep(z0 * 0.002, z0 * 0.02, dz) * smoothstep(z0 * 0.35, 0.0, dz);
|
|
278
|
+
}
|
|
279
|
+
float ao = 1.0 - occ / 12.0;
|
|
280
|
+
fragColor = vec4(vec3(ao), 1.0);
|
|
208
281
|
}`;
|
|
209
|
-
export const
|
|
210
|
-
precision mediump float;
|
|
211
|
-
in vec2 vUv; uniform sampler2D uTex; uniform vec2
|
|
212
|
-
out vec4 fragColor;
|
|
213
|
-
void main(){
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
fragColor = vec4(s, 1.0);
|
|
282
|
+
export const AOBLUR_FS = `#version 300 es
|
|
283
|
+
precision mediump float;
|
|
284
|
+
in vec2 vUv; uniform sampler2D uTex; uniform vec2 uPx;
|
|
285
|
+
out vec4 fragColor;
|
|
286
|
+
void main(){
|
|
287
|
+
float s = 0.0;
|
|
288
|
+
for (int y = -1; y <= 2; y++)
|
|
289
|
+
for (int x = -1; x <= 2; x++)
|
|
290
|
+
s += texture(uTex, vUv + vec2(float(x) - 0.5, float(y) - 0.5) * uPx).r;
|
|
291
|
+
fragColor = vec4(vec3(s / 16.0), 1.0);
|
|
219
292
|
}`;
|
|
220
|
-
export const
|
|
221
|
-
precision
|
|
222
|
-
in vec2 vUv;
|
|
223
|
-
uniform
|
|
224
|
-
|
|
225
|
-
float
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
293
|
+
export const COMPOSITE_FS = `#version 300 es
|
|
294
|
+
precision mediump float;
|
|
295
|
+
in vec2 vUv;
|
|
296
|
+
uniform sampler2D uScene; uniform sampler2D uBloom; uniform sampler2D uAO;
|
|
297
|
+
uniform float uBloomStr; uniform float uAOStr;
|
|
298
|
+
uniform float uFilm; uniform float uGrade; uniform float uVig; uniform float uInk;
|
|
299
|
+
out vec4 fragColor;
|
|
300
|
+
void main(){
|
|
301
|
+
vec3 c = texture(uScene, vUv).rgb;
|
|
302
|
+
c *= mix(1.0, texture(uAO, vUv).r, uAOStr);
|
|
303
|
+
c += texture(uBloom, vUv).rgb * uBloomStr;
|
|
304
|
+
if (uFilm > 0.5) { // ACES-ish filmic: highlights roll off instead of clipping
|
|
305
|
+
c = (c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14);
|
|
306
|
+
}
|
|
307
|
+
c = clamp(c, 0.0, 1.0);
|
|
308
|
+
if (uGrade > 0.5) { // violet-cool shadows, warm highlights
|
|
309
|
+
float luma = dot(c, vec3(0.299, 0.587, 0.114));
|
|
310
|
+
c *= mix(vec3(0.85, 0.83, 1.07), vec3(1.07, 0.99, 0.92), smoothstep(0.12, 0.72, luma));
|
|
311
|
+
c = clamp(c, 0.0, 1.0);
|
|
312
|
+
}
|
|
313
|
+
if (uVig > 0.0) { // cinematic vignette, in the composite now (off the overlay)
|
|
314
|
+
vec2 q = vUv - vec2(0.5, 0.54);
|
|
315
|
+
float r = smoothstep(0.35, 0.9, length(q * vec2(1.15, 1.0)));
|
|
316
|
+
vec3 dk = uInk > 0.5 ? vec3(0.20, 0.19, 0.30) : vec3(0.024, 0.016, 0.055);
|
|
317
|
+
c = mix(c, dk, uVig * r * (uInk > 0.5 ? 0.3 : 1.0));
|
|
318
|
+
}
|
|
319
|
+
fragColor = vec4(c, 1.0);
|
|
246
320
|
}`;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
321
|
+
// depth of field — CoC from linearized depth, 12-tap poisson disc gather on the LDR
|
|
322
|
+
export const DOF_FS = `#version 300 es
|
|
323
|
+
precision highp float;
|
|
324
|
+
in vec2 vUv; uniform sampler2D uTex; uniform sampler2D uDepth;
|
|
325
|
+
uniform float uNear; uniform float uFar; uniform float uFocus; uniform float uRange;
|
|
326
|
+
uniform float uMaxBlur; uniform vec2 uPx;
|
|
327
|
+
out vec4 fragColor;
|
|
328
|
+
float lin(float d){ return uNear * uFar / (uFar - d * (uFar - uNear)); }
|
|
329
|
+
const vec2 DISC[12] = vec2[](
|
|
330
|
+
vec2(-0.326, -0.406), vec2(-0.840, -0.074), vec2(-0.696, 0.457), vec2(-0.203, 0.621),
|
|
331
|
+
vec2(0.962, -0.195), vec2(0.473, -0.480), vec2(0.519, 0.767), vec2(0.185, -0.893),
|
|
332
|
+
vec2(0.507, 0.064), vec2(0.896, 0.412), vec2(-0.322, -0.933), vec2(-0.792, -0.598));
|
|
333
|
+
void main(){
|
|
334
|
+
float z = lin(texture(uDepth, vUv).r);
|
|
335
|
+
float coc = clamp(abs(z - uFocus) / max(1.0, uRange), 0.0, 1.0) * uMaxBlur;
|
|
336
|
+
vec3 acc = texture(uTex, vUv).rgb;
|
|
337
|
+
float wsum = 1.0;
|
|
338
|
+
for (int i = 0; i < 12; i++) {
|
|
339
|
+
vec2 off = DISC[i] * coc * uPx;
|
|
340
|
+
// a sharp (in-focus) neighbour must not bleed into a blurred one: weight each tap
|
|
341
|
+
// by ITS OWN CoC so foreground focus stays crisp against a soft background
|
|
342
|
+
float zt = lin(texture(uDepth, vUv + off).r);
|
|
343
|
+
float ct = clamp(abs(zt - uFocus) / max(1.0, uRange), 0.0, 1.0);
|
|
344
|
+
float w = 0.25 + 0.75 * ct;
|
|
345
|
+
acc += texture(uTex, vUv + off).rgb * w;
|
|
346
|
+
wsum += w;
|
|
347
|
+
}
|
|
348
|
+
fragColor = vec4(acc / wsum, 1.0);
|
|
257
349
|
}`;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
uniform
|
|
263
|
-
uniform
|
|
264
|
-
out vec4 fragColor;
|
|
265
|
-
void main(){
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
vec3 dk = uInk > 0.5 ? vec3(0.20, 0.19, 0.30) : vec3(0.024, 0.016, 0.055);
|
|
282
|
-
c = mix(c, dk, uVig * r * (uInk > 0.5 ? 0.3 : 1.0));
|
|
283
|
-
}
|
|
284
|
-
fragColor = vec4(c, 1.0);
|
|
350
|
+
// camera motion blur — reconstruct world position from depth, reproject into the
|
|
351
|
+
// previous frame's clip space, sample along the screen-space velocity
|
|
352
|
+
export const MOBLUR_FS = `#version 300 es
|
|
353
|
+
precision highp float;
|
|
354
|
+
in vec2 vUv; uniform sampler2D uTex; uniform sampler2D uDepth;
|
|
355
|
+
uniform mat4 uInvVP; uniform mat4 uPrevVP; uniform float uStrength;
|
|
356
|
+
out vec4 fragColor;
|
|
357
|
+
void main(){
|
|
358
|
+
float d = texture(uDepth, vUv).r;
|
|
359
|
+
vec4 ndc = vec4(vUv * 2.0 - 1.0, d * 2.0 - 1.0, 1.0);
|
|
360
|
+
vec4 wp = uInvVP * ndc; wp /= wp.w;
|
|
361
|
+
vec4 pc = uPrevVP * wp;
|
|
362
|
+
vec2 prevUv = (pc.xy / pc.w) * 0.5 + 0.5;
|
|
363
|
+
vec2 vel = (vUv - prevUv) * uStrength;
|
|
364
|
+
float vlen = length(vel);
|
|
365
|
+
if (vlen < 1e-5 || pc.w <= 0.0) { fragColor = vec4(texture(uTex, vUv).rgb, 1.0); return; }
|
|
366
|
+
vel = vlen > 0.04 ? vel * (0.04 / vlen) : vel; // clamp the streak to 4% of the screen
|
|
367
|
+
vec3 acc = vec3(0.0);
|
|
368
|
+
for (int i = 0; i < 8; i++) {
|
|
369
|
+
float t = (float(i) / 7.0) - 0.5;
|
|
370
|
+
acc += texture(uTex, clamp(vUv + vel * t, vec2(0.001), vec2(0.999))).rgb;
|
|
371
|
+
}
|
|
372
|
+
fragColor = vec4(acc / 8.0, 1.0);
|
|
285
373
|
}`;
|
|
286
374
|
// compact FXAA (luma-based, 5-tap edge blend) — runs last, on the LDR composite
|
|
287
|
-
export const FXAA_FS = `#version 300 es
|
|
288
|
-
precision mediump float;
|
|
289
|
-
in vec2 vUv; uniform sampler2D uTex; uniform vec2 uPx;
|
|
290
|
-
out vec4 fragColor;
|
|
291
|
-
float luma(vec3 c){ return dot(c, vec3(0.299, 0.587, 0.114)); }
|
|
292
|
-
void main(){
|
|
293
|
-
vec3 cM = texture(uTex, vUv).rgb;
|
|
294
|
-
float lM = luma(cM);
|
|
295
|
-
float lN = luma(texture(uTex, vUv + vec2(0.0, -uPx.y)).rgb);
|
|
296
|
-
float lS = luma(texture(uTex, vUv + vec2(0.0, uPx.y)).rgb);
|
|
297
|
-
float lW = luma(texture(uTex, vUv + vec2(-uPx.x, 0.0)).rgb);
|
|
298
|
-
float lE = luma(texture(uTex, vUv + vec2(uPx.x, 0.0)).rgb);
|
|
299
|
-
float lMin = min(lM, min(min(lN, lS), min(lW, lE)));
|
|
300
|
-
float lMax = max(lM, max(max(lN, lS), max(lW, lE)));
|
|
301
|
-
float range = lMax - lMin;
|
|
302
|
-
if (range < max(0.0312, lMax * 0.125)) { fragColor = vec4(cM, 1.0); return; }
|
|
303
|
-
vec2 dir = normalize(vec2((lE + lS) - (lW + lN), (lN + lE) - (lS + lW)) + 1e-6);
|
|
304
|
-
vec3 a = texture(uTex, vUv + dir * uPx * 0.5).rgb;
|
|
305
|
-
vec3 b = texture(uTex, vUv - dir * uPx * 0.5).rgb;
|
|
306
|
-
fragColor = vec4(mix(cM, (a + b) * 0.5, 0.75), 1.0);
|
|
375
|
+
export const FXAA_FS = `#version 300 es
|
|
376
|
+
precision mediump float;
|
|
377
|
+
in vec2 vUv; uniform sampler2D uTex; uniform vec2 uPx;
|
|
378
|
+
out vec4 fragColor;
|
|
379
|
+
float luma(vec3 c){ return dot(c, vec3(0.299, 0.587, 0.114)); }
|
|
380
|
+
void main(){
|
|
381
|
+
vec3 cM = texture(uTex, vUv).rgb;
|
|
382
|
+
float lM = luma(cM);
|
|
383
|
+
float lN = luma(texture(uTex, vUv + vec2(0.0, -uPx.y)).rgb);
|
|
384
|
+
float lS = luma(texture(uTex, vUv + vec2(0.0, uPx.y)).rgb);
|
|
385
|
+
float lW = luma(texture(uTex, vUv + vec2(-uPx.x, 0.0)).rgb);
|
|
386
|
+
float lE = luma(texture(uTex, vUv + vec2(uPx.x, 0.0)).rgb);
|
|
387
|
+
float lMin = min(lM, min(min(lN, lS), min(lW, lE)));
|
|
388
|
+
float lMax = max(lM, max(max(lN, lS), max(lW, lE)));
|
|
389
|
+
float range = lMax - lMin;
|
|
390
|
+
if (range < max(0.0312, lMax * 0.125)) { fragColor = vec4(cM, 1.0); return; }
|
|
391
|
+
vec2 dir = normalize(vec2((lE + lS) - (lW + lN), (lN + lE) - (lS + lW)) + 1e-6);
|
|
392
|
+
vec3 a = texture(uTex, vUv + dir * uPx * 0.5).rgb;
|
|
393
|
+
vec3 b = texture(uTex, vUv - dir * uPx * 0.5).rgb;
|
|
394
|
+
fragColor = vec4(mix(cM, (a + b) * 0.5, 0.75), 1.0);
|
|
307
395
|
}`;
|