image-color-grading 1.0.0 → 1.0.1

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/shaders.js DELETED
@@ -1,674 +0,0 @@
1
- /**
2
- * WebGL 着色器代码
3
- */
4
- export const vertexSource = `
5
- precision highp float;
6
- attribute vec2 aPosition;
7
- attribute vec2 aTexCoord;
8
- varying vec2 vUv;
9
- void main() {
10
- vUv = aTexCoord;
11
- gl_Position = vec4(aPosition, 0.0, 1.0);
12
- }
13
- `;
14
- export const blackVertexSource = `
15
- precision highp float;
16
- attribute vec2 apos;
17
- attribute vec2 auv;
18
- varying vec2 uv;
19
- uniform vec4 transform;
20
- void main(void) {
21
- uv = auv;
22
- gl_Position = vec4(
23
- apos.x * transform.x + transform.z,
24
- apos.y * transform.y + transform.w,
25
- 0.0,
26
- 1.0
27
- );
28
- }
29
- `;
30
- export const passFragment = `
31
- precision highp float;
32
- varying vec2 vUv;
33
- uniform sampler2D uTexture;
34
- void main() {
35
- gl_FragColor = texture2D(uTexture, vUv);
36
- }
37
- `;
38
- export const vibranceFragment = `
39
- precision highp float;
40
- varying vec2 vUv;
41
- uniform sampler2D uTexture;
42
- uniform float uAmount;
43
- void main() {
44
- vec4 col = texture2D(uTexture, vUv);
45
- vec3 color = col.rgb;
46
- float luminance = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
47
- float mn = min(min(color.r, color.g), color.b);
48
- float mx = max(max(color.r, color.g), color.b);
49
- float sat = (1.0 - (mx - mn)) * (1.0 - mx) * luminance * 5.0;
50
- vec3 lightness = vec3((mn + mx) / 2.0);
51
- color = mix(color, mix(color, lightness, -uAmount), sat);
52
- gl_FragColor = vec4(
53
- mix(color, lightness, (1.0 - lightness) * (1.0 - uAmount) / 2.0 * abs(uAmount)),
54
- col.a
55
- );
56
- }
57
- `;
58
- export const saturationFragment = `
59
- precision highp float;
60
- varying vec2 vUv;
61
- uniform sampler2D uTexture;
62
- uniform float uMatrix[20];
63
- void main(void) {
64
- vec4 c = texture2D(uTexture, vUv);
65
- gl_FragColor.r = uMatrix[0] * c.r + uMatrix[1] * c.g + uMatrix[2] * c.b + uMatrix[3] * c.a + uMatrix[4];
66
- gl_FragColor.g = uMatrix[5] * c.r + uMatrix[6] * c.g + uMatrix[7] * c.b + uMatrix[8] * c.a + uMatrix[9];
67
- gl_FragColor.b = uMatrix[10] * c.r + uMatrix[11] * c.g + uMatrix[12] * c.b + uMatrix[13] * c.a + uMatrix[14];
68
- gl_FragColor.a = uMatrix[15] * c.r + uMatrix[16] * c.g + uMatrix[17] * c.b + uMatrix[18] * c.a + uMatrix[19];
69
- }
70
- `;
71
- export const temperatureFragment = `
72
- precision highp float;
73
- varying vec2 vUv;
74
- uniform sampler2D uTexture;
75
- uniform float uAmount;
76
- void main() {
77
- vec4 color = texture2D(uTexture, vUv);
78
- color.r = clamp(color.r + uAmount, 0.0, 1.0);
79
- color.b = clamp(color.b - uAmount, 0.0, 1.0);
80
- gl_FragColor = color;
81
- }
82
- `;
83
- export const tintFragment = `
84
- precision highp float;
85
- varying vec2 vUv;
86
- uniform sampler2D uTexture;
87
- uniform float uAmount;
88
- void main() {
89
- vec4 color = texture2D(uTexture, vUv);
90
- color.g = clamp(color.g + uAmount, 0.0, 1.0);
91
- gl_FragColor = color;
92
- }
93
- `;
94
- export const hueFragment = `
95
- precision highp float;
96
- varying vec2 vUv;
97
- uniform sampler2D uTexture;
98
- uniform float uRotation;
99
- vec3 rgb2hsv(vec3 c) {
100
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
101
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
102
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
103
- float d = q.x - min(q.w, q.y);
104
- float e = 1.0e-10;
105
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
106
- }
107
- vec3 hsv2rgb(vec3 c) {
108
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
109
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
110
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
111
- }
112
- void main() {
113
- lowp vec4 base = texture2D(uTexture, vUv);
114
- vec3 hsv = rgb2hsv(base.rgb);
115
- hsv.x = fract(hsv.x + uRotation);
116
- gl_FragColor = vec4(hsv2rgb(hsv), base.a);
117
- }
118
- `;
119
- export const brightnessFragment = `
120
- precision highp float;
121
- varying vec2 vUv;
122
- uniform sampler2D uTexture;
123
- uniform float uAmount;
124
- const float PI = 3.1415926535897932384626433832795;
125
- void main() {
126
- vec4 color = texture2D(uTexture, vUv);
127
- if (uAmount >= 0.0) {
128
- color.r = color.r + uAmount * sin(color.r * PI);
129
- color.g = color.g + uAmount * sin(color.g * PI);
130
- color.b = color.b + uAmount * sin(color.b * PI);
131
- } else {
132
- color.r = (1.0 + uAmount) * color.r;
133
- color.g = (1.0 + uAmount) * color.g;
134
- color.b = (1.0 + uAmount) * color.b;
135
- }
136
- gl_FragColor = color;
137
- }
138
- `;
139
- export const exposureFragment = `
140
- precision highp float;
141
- varying vec2 vUv;
142
- uniform sampler2D uTexture;
143
- uniform float uAmount;
144
- const float epsilon = 0.000001;
145
- const float mx = 1.0 - epsilon;
146
- const mat3 matRGBtoROMM = mat3(
147
- 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,
148
- 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,
149
- 0.01688321679830551, 0.11767247319221497, 0.8654443025588989
150
- );
151
- const mat3 matROMMtoRGB = mat3(
152
- 2.0340757369995117, -0.727334201335907, -0.3067416846752167,
153
- -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,
154
- -0.008569774217903614, -0.1532866358757019, 1.1618564128875732
155
- );
156
- float ramp(in float t) {
157
- t *= 2.0;
158
- if (t >= 1.0) {
159
- t -= 1.0;
160
- t = log(0.5) / log(0.5 * (1.0 - t) + 0.9332 * t);
161
- }
162
- return clamp(t, 0.001, 10.0);
163
- }
164
- vec3 rgb2hsv(in vec3 c) {
165
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
166
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
167
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
168
- float d = q.x - min(q.w, q.y);
169
- float e = 1.0e-10;
170
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
171
- }
172
- vec3 hsv2rgb(in vec3 c) {
173
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
174
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
175
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
176
- }
177
- vec3 setHue(in vec3 res, in vec3 base) {
178
- vec3 hsv = rgb2hsv(base);
179
- vec3 res_hsv = rgb2hsv(res);
180
- return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));
181
- }
182
- void main() {
183
- lowp vec4 col = texture2D(uTexture, vUv);
184
- vec3 base = col.rgb * matRGBtoROMM;
185
- float a = abs(uAmount) * col.a + epsilon;
186
- float v = pow(2.0, a * 2.0 + 1.0) - 2.0;
187
- float m = mx - exp(-v);
188
- vec3 res = (uAmount > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;
189
- res = mix(base, res, min(a * 100.0, 1.0));
190
- res = setHue(res, base);
191
- res = pow(res, vec3(ramp(1.0 - (0.0 * col.a + 1.0) / 2.0)));
192
- res = res * matROMMtoRGB;
193
- gl_FragColor = vec4(res, col.a);
194
- }
195
- `;
196
- export const contrastFragment = `
197
- precision highp float;
198
- varying vec2 vUv;
199
- uniform sampler2D uTexture;
200
- uniform float uMatrix[20];
201
- void main(void) {
202
- vec4 c = texture2D(uTexture, vUv);
203
- gl_FragColor.r = uMatrix[0] * c.r + uMatrix[1] * c.g + uMatrix[2] * c.b + uMatrix[3] * c.a + uMatrix[4];
204
- gl_FragColor.g = uMatrix[5] * c.r + uMatrix[6] * c.g + uMatrix[7] * c.b + uMatrix[8] * c.a + uMatrix[9];
205
- gl_FragColor.b = uMatrix[10] * c.r + uMatrix[11] * c.g + uMatrix[12] * c.b + uMatrix[13] * c.a + uMatrix[14];
206
- gl_FragColor.a = uMatrix[15] * c.r + uMatrix[16] * c.g + uMatrix[17] * c.b + uMatrix[18] * c.a + uMatrix[19];
207
- }
208
- `;
209
- export const whitesFragment = `
210
- precision highp float;
211
- varying vec2 vUv;
212
- uniform sampler2D uTexture;
213
- uniform float uAmount;
214
- const vec3 RGB2Y = vec3(0.2126, 0.7152, 0.0722);
215
- void main() {
216
- vec4 base = texture2D(uTexture, vUv.xy);
217
- vec3 color = base.rgb;
218
- float lum = dot(color, RGB2Y);
219
- float whiteMask = smoothstep(0.5, 1.0, lum);
220
- color += uAmount * whiteMask;
221
- gl_FragColor = vec4(clamp(color, 0.0, 1.0), base.a);
222
- }
223
- `;
224
- export const blackPaletteFragment = `
225
- precision highp float;
226
- varying vec2 uv;
227
- uniform sampler2D uTexture;
228
- uniform sampler2D uPaletteMap;
229
- void main() {
230
- lowp vec4 base = texture2D(uTexture, uv.xy);
231
- float r = texture2D(uPaletteMap, vec2(base.r, 0.0)).r;
232
- float g = texture2D(uPaletteMap, vec2(base.g, 0.0)).g;
233
- float b = texture2D(uPaletteMap, vec2(base.b, 0.0)).b;
234
- gl_FragColor = vec4(r, g, b, base.a);
235
- }
236
- `;
237
- export const highlightsFragment = `
238
- precision highp float;
239
- varying vec2 vUv;
240
- uniform sampler2D uTexture;
241
- uniform float uAmount;
242
- const float epsilon = 0.000001;
243
- const float mx = 1.0 - epsilon;
244
- const float PI = 3.1415926535897932384626433832795;
245
- const mat3 matRGBtoROMM = mat3(
246
- 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,
247
- 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,
248
- 0.01688321679830551, 0.11767247319221497, 0.8654443025588989
249
- );
250
- const mat3 matROMMtoRGB = mat3(
251
- 2.0340757369995117, -0.727334201335907, -0.3067416846752167,
252
- -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,
253
- -0.008569774217903614, -0.1532866358757019, 1.1618564128875732
254
- );
255
- float luma_romm(in vec3 color) {
256
- return dot(color, vec3(0.242655, 0.755158, 0.002187));
257
- }
258
- float luma(in vec3 color) {
259
- return dot(color, vec3(0.298839, 0.586811, 0.11435));
260
- }
261
- vec3 rgb2hsv(in vec3 c) {
262
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
263
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
264
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
265
- float d = q.x - min(q.w, q.y);
266
- float e = 1.0e-10;
267
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
268
- }
269
- vec3 hsv2rgb(in vec3 c) {
270
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
271
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
272
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
273
- }
274
- vec3 setHue(in vec3 res, in vec3 base) {
275
- vec3 hsv = rgb2hsv(base);
276
- vec3 res_hsv = rgb2hsv(res);
277
- return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));
278
- }
279
- float gaussian(in float x) {
280
- return 1.0 - exp(-PI * 2.0 * x * x);
281
- }
282
- void main() {
283
- lowp vec4 col = texture2D(uTexture, vUv);
284
- lowp vec3 map = col.rgb;
285
- vec3 base = col.rgb * matRGBtoROMM;
286
- float base_lum = luma(col.rgb);
287
- float map_lum = luma_romm(map * matRGBtoROMM);
288
- float exposure = mix(uAmount, 0.0, 1.0 - map_lum) * col.a;
289
- float a = abs(exposure) * col.a + epsilon;
290
- float v = pow(2.0, a + 1.0) - 2.0;
291
- float m = mx - exp(-v);
292
- vec3 res = (exposure > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;
293
- res = mix(base, res, min(a * 100.0, 1.0));
294
- res = setHue(res, base);
295
- res = res * matROMMtoRGB;
296
- gl_FragColor = vec4(res, col.a);
297
- }
298
- `;
299
- export const shadowsFragment = `
300
- precision highp float;
301
- varying vec2 vUv;
302
- uniform sampler2D uTexture;
303
- uniform float uAmount;
304
- const float epsilon = 0.000001;
305
- const float mx = 1.0 - epsilon;
306
- const float PI = 3.1415926535897932384626433832795;
307
- const mat3 matRGBtoROMM = mat3(
308
- 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,
309
- 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,
310
- 0.01688321679830551, 0.11767247319221497, 0.8654443025588989
311
- );
312
- const mat3 matROMMtoRGB = mat3(
313
- 2.0340757369995117, -0.727334201335907, -0.3067416846752167,
314
- -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,
315
- -0.008569774217903614, -0.1532866358757019, 1.1618564128875732
316
- );
317
- float luma_romm(in vec3 color) {
318
- return dot(color, vec3(0.242655, 0.755158, 0.002187));
319
- }
320
- float luma(in vec3 color) {
321
- return dot(color, vec3(0.298839, 0.586811, 0.11435));
322
- }
323
- vec3 rgb2hsv(in vec3 c) {
324
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
325
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
326
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
327
- float d = q.x - min(q.w, q.y);
328
- float e = 1.0e-10;
329
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
330
- }
331
- vec3 hsv2rgb(in vec3 c) {
332
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
333
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
334
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
335
- }
336
- vec3 setHue(in vec3 res, in vec3 base) {
337
- vec3 hsv = rgb2hsv(base);
338
- vec3 res_hsv = rgb2hsv(res);
339
- return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));
340
- }
341
- float gaussian(in float x) {
342
- return 1.0 - exp(-PI * 2.0 * x * x);
343
- }
344
- void main() {
345
- lowp vec4 col = texture2D(uTexture, vUv);
346
- lowp vec3 map = col.rgb;
347
- vec3 base = col.rgb * matRGBtoROMM;
348
- float base_lum = luma(col.rgb);
349
- float map_lum = luma_romm(map * matRGBtoROMM);
350
- float exposure = mix(0.0, uAmount, 1.0 - map_lum) * col.a;
351
- float a = abs(exposure) * col.a + epsilon;
352
- float v = pow(2.0, a + 1.0) - 2.0;
353
- float m = mx - exp(-v);
354
- vec3 res = (exposure > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;
355
- res = mix(base, res, min(a * 100.0, 1.0));
356
- res = setHue(res, base);
357
- res = res * matROMMtoRGB;
358
- gl_FragColor = vec4(res, col.a);
359
- }
360
- `;
361
- export const dehazeFragment = `
362
- precision highp float;
363
- varying vec2 vUv;
364
- uniform sampler2D uTexture;
365
- uniform float uAmount;
366
- uniform vec2 uSize;
367
-
368
- float hazeMap(vec2 coord) {
369
- vec3 color = vec3(1.0);
370
- vec2 stepSize = vec2(1.0 / uSize.x, 1.0 / uSize.y);
371
- for (int i = -1; i <= 1; ++i) {
372
- for (int j = -1; j <= 1; ++j) {
373
- vec2 offset = vec2(float(i), float(j)) * stepSize;
374
- vec2 uv = clamp(coord + offset, 0.0, 1.0);
375
- vec3 sample = texture2D(uTexture, uv).rgb;
376
- color = min(color, sample);
377
- }
378
- }
379
- return min(color.r, min(color.g, color.b));
380
- }
381
-
382
- void main() {
383
- vec4 base = texture2D(uTexture, vUv);
384
- float haze = hazeMap(vUv);
385
- float transmission = 1.0 - 0.95 * haze;
386
- const float A = 0.95;
387
- const float t0 = 0.1;
388
- float t = mix(1.0, max(t0, transmission), uAmount);
389
- vec3 J = (base.rgb - A) / t + A;
390
- gl_FragColor = vec4(J, base.a);
391
- }
392
- `;
393
- export const bloomFragment = `
394
- precision highp float;
395
- varying vec2 vUv;
396
- uniform sampler2D uTexture;
397
- uniform float uAmount;
398
- uniform vec2 uTexel;
399
- uniform float uThreshold;
400
-
401
- void main() {
402
- vec4 sum = vec4(0.0);
403
- int j = -2;
404
- for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);
405
- j = -1;
406
- for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);
407
- j = 0;
408
- for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);
409
- j = 1;
410
- for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);
411
- j = 2;
412
- for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);
413
- sum /= 25.0;
414
- vec4 base = texture2D(uTexture, vUv);
415
- if (length(sum.rgb) > uThreshold) {
416
- base += sum * uAmount;
417
- }
418
- gl_FragColor = base;
419
- }
420
- `;
421
- export const glamourFragment = `
422
- precision highp float;
423
- varying vec2 vUv;
424
- uniform sampler2D uTexture;
425
- uniform float uAmount;
426
- uniform vec2 uTexel;
427
-
428
- float normpdf(in float x, in float sigma) {
429
- return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;
430
- }
431
-
432
- vec3 blurMap() {
433
- const int mSize = 11;
434
- const int kSize = (mSize - 1) / 2;
435
- float kernel[mSize];
436
- vec3 final_colour = vec3(0.0);
437
- float sigma = 7.0;
438
- float Z = 0.0;
439
- for (int j = 0; j <= kSize; ++j) {
440
- kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);
441
- }
442
- for (int j = 0; j < mSize; ++j) {
443
- Z += kernel[j];
444
- }
445
- for (int i = -kSize; i <= kSize; ++i) {
446
- for (int j = -kSize; j <= kSize; ++j) {
447
- final_colour += kernel[kSize + j] * kernel[kSize + i] *
448
- texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel).rgb;
449
- }
450
- }
451
- return vec3(final_colour / (Z * Z));
452
- }
453
-
454
- float luma(vec3 color) {
455
- return dot(color, vec3(0.299, 0.587, 0.114));
456
- }
457
-
458
- void main() {
459
- vec4 base = texture2D(uTexture, vUv);
460
- vec3 color = blurMap();
461
- color = vec3(luma(color));
462
- color = vec3(
463
- (base.r <= 0.5) ? (2.0 * base.r * color.r) : (1.0 - 2.0 * (1.0 - base.r) * (1.0 - color.r)),
464
- (base.g <= 0.5) ? (2.0 * base.g * color.g) : (1.0 - 2.0 * (1.0 - base.g) * (1.0 - color.g)),
465
- (base.b <= 0.5) ? (2.0 * base.b * color.b) : (1.0 - 2.0 * (1.0 - base.b) * (1.0 - color.b))
466
- );
467
- gl_FragColor = mix(base, vec4(color, base.a), uAmount);
468
- }
469
- `;
470
- export const clarityFragment = `
471
- precision highp float;
472
- varying vec2 vUv;
473
- uniform sampler2D uTexture;
474
- uniform float uAmount;
475
- uniform vec2 uTexel;
476
-
477
- float Lum(vec3 c) {
478
- return 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;
479
- }
480
- float BlendOverlayf(float base, float blend) {
481
- return (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)));
482
- }
483
- vec3 BlendOverlay(vec3 base, vec3 blend) {
484
- return vec3(BlendOverlayf(base.r, blend.r), BlendOverlayf(base.g, blend.g), BlendOverlayf(base.b, blend.b));
485
- }
486
- float BlendVividLightf(float base, float blend) {
487
- float BlendColorBurnf = (((2.0 * blend) == 0.0) ? (2.0 * blend) : max((1.0 - ((1.0 - base) / (2.0 * blend))), 0.0));
488
- float BlendColorDodgef = (((2.0 * (blend - 0.5)) == 1.0) ? (2.0 * (blend - 0.5)) : min(base / (1.0 - (2.0 * (blend - 0.5))), 1.0));
489
- return ((blend < 0.5) ? BlendColorBurnf : BlendColorDodgef);
490
- }
491
- vec3 BlendVividLight(vec3 base, vec3 blend) {
492
- return vec3(BlendVividLightf(base.r, blend.r), BlendVividLightf(base.g, blend.g), BlendVividLightf(base.b, blend.b));
493
- }
494
- float normpdf(in float x, in float sigma) {
495
- return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;
496
- }
497
- vec3 blurMap() {
498
- const int mSize = 11;
499
- const int kSize = (mSize - 1) / 2;
500
- float kernel[mSize];
501
- vec3 final_colour = vec3(0.0);
502
- float sigma = 7.0;
503
- float Z = 0.0;
504
- for (int j = 0; j <= kSize; ++j) {
505
- kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);
506
- }
507
- for (int j = 0; j < mSize; ++j) {
508
- Z += kernel[j];
509
- }
510
- for (int i = -kSize; i <= kSize; ++i) {
511
- for (int j = -kSize; j <= kSize; ++j) {
512
- final_colour += kernel[kSize + j] * kernel[kSize + i] *
513
- texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel).rgb;
514
- }
515
- }
516
- return vec3(final_colour / (Z * Z));
517
- }
518
- void main() {
519
- vec4 base4 = texture2D(uTexture, vUv);
520
- vec3 blur = blurMap();
521
- vec3 base = base4.rgb;
522
- float intensity = (uAmount < 0.0) ? (uAmount / 2.0) : uAmount;
523
- float lum = Lum(base);
524
- vec3 col = vec3(lum);
525
- vec3 mask = vec3(1.0 - pow(lum, 1.8));
526
- vec3 layer = vec3(1.0 - Lum(blur));
527
- vec3 detail = clamp(BlendVividLight(col, layer), 0.0, 1.0);
528
- vec3 inverse = mix(1.0 - detail, detail, (intensity + 1.0) / 2.0);
529
- gl_FragColor = vec4(BlendOverlay(base, mix(vec3(0.5), inverse, mask)), base4.a);
530
- }
531
- `;
532
- export const kernelFragment = `
533
- precision highp float;
534
- varying vec2 vUv;
535
- uniform sampler2D uTexture;
536
- uniform vec2 uTexel;
537
- uniform float uKernel[9];
538
- uniform float uAmount;
539
- void main(void) {
540
- vec4 c11 = texture2D(uTexture, vUv - uTexel);
541
- vec4 c12 = texture2D(uTexture, vec2(vUv.x, vUv.y - uTexel.y));
542
- vec4 c13 = texture2D(uTexture, vec2(vUv.x + uTexel.x, vUv.y - uTexel.y));
543
- vec4 c21 = texture2D(uTexture, vec2(vUv.x - uTexel.x, vUv.y));
544
- vec4 c22 = texture2D(uTexture, vUv);
545
- vec4 c23 = texture2D(uTexture, vec2(vUv.x + uTexel.x, vUv.y));
546
- vec4 c31 = texture2D(uTexture, vec2(vUv.x - uTexel.x, vUv.y + uTexel.y));
547
- vec4 c32 = texture2D(uTexture, vec2(vUv.x, vUv.y + uTexel.y));
548
- vec4 c33 = texture2D(uTexture, vUv + uTexel);
549
- vec4 color = c11 * uKernel[0] + c12 * uKernel[1] + c13 * uKernel[2] +
550
- c21 * uKernel[3] + c22 * uKernel[4] + c23 * uKernel[5] +
551
- c31 * uKernel[6] + c32 * uKernel[7] + c33 * uKernel[8];
552
- gl_FragColor = color * uAmount + (c22 * (1.0 - uAmount));
553
- }
554
- `;
555
- export const blurFragment = `
556
- precision highp float;
557
- varying vec2 vUv;
558
- uniform sampler2D uTexture;
559
- uniform vec2 uSize;
560
- float random(vec3 scale, float seed) {
561
- return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
562
- }
563
- void main() {
564
- vec4 color = vec4(0.0);
565
- float total = 0.0;
566
- float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
567
- for (int t = -30; t <= 30; t++) {
568
- float percent = (float(t) + offset - 0.5) / 30.0;
569
- float weight = 1.0 - abs(percent);
570
- vec4 sample = texture2D(uTexture, vUv + uSize * percent);
571
- sample.rgb *= sample.a;
572
- color += sample * weight;
573
- total += weight;
574
- }
575
- gl_FragColor = color / total;
576
- gl_FragColor.rgb /= gl_FragColor.a + 0.00001;
577
- }
578
- `;
579
- export const vignetteFragment = `
580
- precision highp float;
581
- varying vec2 vUv;
582
- uniform sampler2D uTexture;
583
- uniform float uAmount;
584
- uniform float uSize;
585
- void main() {
586
- vec4 color = texture2D(uTexture, vUv);
587
- float dist = distance(vUv, vec2(0.5, 0.5));
588
- float amt = clamp(uAmount, -1.0, 1.0);
589
- float edge = dist * (abs(amt) * 0.75 + uSize * 2.0);
590
- float vignette = smoothstep(0.8, uSize * 0.799, edge);
591
- if (amt < 0.0) {
592
- vignette = 1.0 + (1.0 - vignette) * (-amt);
593
- } else {
594
- vignette = mix(1.0, vignette, amt);
595
- }
596
- color.rgb *= vignette;
597
- gl_FragColor = color;
598
- }
599
- `;
600
- export const grainFragment = `
601
- precision highp float;
602
- uniform sampler2D uTexture;
603
- varying vec2 vUv;
604
- uniform vec2 uResolution;
605
- uniform float uAmount;
606
- uniform float uTime;
607
- const float permTexUnit = 1.0 / 256.0;
608
- const float permTexUnitHalf = 0.5 / 256.0;
609
- float grainsize = 1.8;
610
- float lumamount = 1.0;
611
-
612
- vec4 rnm(in vec2 tc) {
613
- float noise = sin(dot(tc + vec2(uTime, uTime), vec2(12.9898, 78.233))) * 43758.5453;
614
- float noiseR = fract(noise) * 2.0 - 1.0;
615
- float noiseG = fract(noise * 1.2154) * 2.0 - 1.0;
616
- float noiseB = fract(noise * 1.3453) * 2.0 - 1.0;
617
- float noiseA = fract(noise * 1.3647) * 2.0 - 1.0;
618
- return vec4(noiseR, noiseG, noiseB, noiseA);
619
- }
620
- float fade(in float t) {
621
- return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
622
- }
623
- float pnoise3D(in vec3 p) {
624
- vec3 pi = permTexUnit * floor(p) + permTexUnitHalf;
625
- vec3 pf = fract(p);
626
- float perm00 = rnm(pi.xy).a;
627
- vec3 grad000 = rnm(vec2(perm00, pi.z)).rgb * 4.0 - 1.0;
628
- float n000 = dot(grad000, pf);
629
- vec3 grad001 = rnm(vec2(perm00, pi.z + permTexUnit)).rgb * 4.0 - 1.0;
630
- float n001 = dot(grad001, pf - vec3(0.0, 0.0, 1.0));
631
- float perm01 = rnm(pi.xy + vec2(0.0, permTexUnit)).a;
632
- vec3 grad010 = rnm(vec2(perm01, pi.z)).rgb * 4.0 - 1.0;
633
- float n010 = dot(grad010, pf - vec3(0.0, 1.0, 0.0));
634
- vec3 grad011 = rnm(vec2(perm01, pi.z + permTexUnit)).rgb * 4.0 - 1.0;
635
- float n011 = dot(grad011, pf - vec3(0.0, 1.0, 1.0));
636
- float perm10 = rnm(pi.xy + vec2(permTexUnit, 0.0)).a;
637
- vec3 grad100 = rnm(vec2(perm10, pi.z)).rgb * 4.0 - 1.0;
638
- float n100 = dot(grad100, pf - vec3(1.0, 0.0, 0.0));
639
- vec3 grad101 = rnm(vec2(perm10, pi.z + permTexUnit)).rgb * 4.0 - 1.0;
640
- float n101 = dot(grad101, pf - vec3(1.0, 0.0, 1.0));
641
- float perm11 = rnm(pi.xy + vec2(permTexUnit, permTexUnit)).a;
642
- vec3 grad110 = rnm(vec2(perm11, pi.z)).rgb * 4.0 - 1.0;
643
- float n110 = dot(grad110, pf - vec3(1.0, 1.0, 0.0));
644
- vec3 grad111 = rnm(vec2(perm11, pi.z + permTexUnit)).rgb * 4.0 - 1.0;
645
- float n111 = dot(grad111, pf - vec3(1.0, 1.0, 1.0));
646
- vec4 n_x = mix(vec4(n000, n001, n010, n011), vec4(n100, n101, n110, n111), fade(pf.x));
647
- vec2 n_xy = mix(n_x.xy, n_x.zw, fade(pf.y));
648
- float n_xyz = mix(n_xy.x, n_xy.y, fade(pf.z));
649
- return n_xyz;
650
- }
651
- vec2 coordRot(in vec2 tc, in float angle) {
652
- float aspect = uResolution.x / uResolution.y;
653
- float rotX = ((tc.x * 2.0 - 1.0) * aspect * cos(angle)) - ((tc.y * 2.0 - 1.0) * sin(angle));
654
- float rotY = ((tc.y * 2.0 - 1.0) * cos(angle)) + ((tc.x * 2.0 - 1.0) * aspect * sin(angle));
655
- rotX = ((rotX / aspect) * 0.5 + 0.5);
656
- rotY = rotY * 0.5 + 0.5;
657
- return vec2(rotX, rotY);
658
- }
659
- void main() {
660
- vec3 rotOffset = vec3(1.425, 3.892, 5.835);
661
- vec2 rotCoordsR = coordRot(vUv, uTime + rotOffset.x);
662
- vec3 noise = vec3(pnoise3D(vec3(rotCoordsR * vec2(uResolution.x / grainsize, uResolution.y / grainsize), 0.0)));
663
- vec4 tex = texture2D(uTexture, vUv);
664
- vec3 col = tex.rgb;
665
- vec3 lumcoeff = vec3(0.299, 0.587, 0.114);
666
- float luminance = mix(0.0, dot(col, lumcoeff), lumamount);
667
- float lum = smoothstep(0.2, 0.0, luminance);
668
- lum += luminance;
669
- noise = mix(noise, vec3(0.0), pow(lum, 4.0));
670
- col = col + noise * uAmount;
671
- gl_FragColor = vec4(col, tex.a);
672
- }
673
- `;
674
- //# sourceMappingURL=shaders.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shaders.js","sourceRoot":"","sources":["../src/shaders.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;CAS3B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;CAehC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;CAO3B,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;CAmB/B,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;CAYjC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;CAWlC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;CAU3B,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;CAwB1B,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;CAmBjC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwD/B,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;CAY/B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;CAc7B,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;CAYnC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6DjC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6D9B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+B7B,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B5B,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgD9B,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6D9B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsB7B,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuB3B,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;CAoB/B,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyE5B,CAAC"}