@paper-design/shaders 0.0.40 → 0.0.46
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 +2 -1
- package/dist/get-shader-noise-texture.d.ts +1 -1
- package/dist/get-shader-noise-texture.js +5 -9
- package/dist/get-shader-noise-texture.js.map +2 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +2 -2
- package/dist/shader-mount.d.ts +8 -2
- package/dist/shader-mount.js +12 -177
- package/dist/shader-mount.js.map +2 -2
- package/dist/shader-sizing.d.ts +2 -2
- package/dist/shader-sizing.js +39 -1
- package/dist/shader-sizing.js.map +2 -2
- package/dist/shader-utils.d.ts +8 -5
- package/dist/shader-utils.js +70 -51
- package/dist/shader-utils.js.map +2 -2
- package/dist/shaders/dithering.js +13 -11
- package/dist/shaders/dithering.js.map +2 -2
- package/dist/shaders/dot-grid.js +2 -2
- package/dist/shaders/dot-grid.js.map +2 -2
- package/dist/shaders/dot-orbit.d.ts +3 -0
- package/dist/shaders/dot-orbit.js +9 -9
- package/dist/shaders/dot-orbit.js.map +2 -2
- package/dist/shaders/fluted-glass.d.ts +72 -0
- package/dist/shaders/fluted-glass.js +188 -0
- package/dist/shaders/fluted-glass.js.map +7 -0
- package/dist/shaders/god-rays.d.ts +2 -0
- package/dist/shaders/god-rays.js +20 -9
- package/dist/shaders/god-rays.js.map +2 -2
- package/dist/shaders/grain-gradient.d.ts +1 -0
- package/dist/shaders/grain-gradient.js +65 -42
- package/dist/shaders/grain-gradient.js.map +2 -2
- package/dist/shaders/image-dithering.d.ts +49 -0
- package/dist/shaders/image-dithering.js +164 -0
- package/dist/shaders/image-dithering.js.map +7 -0
- package/dist/shaders/liquid-metal.js +4 -4
- package/dist/shaders/liquid-metal.js.map +2 -2
- package/dist/shaders/mesh-gradient.js +2 -2
- package/dist/shaders/mesh-gradient.js.map +2 -2
- package/dist/shaders/metaballs.d.ts +3 -0
- package/dist/shaders/metaballs.js +8 -7
- package/dist/shaders/metaballs.js.map +2 -2
- package/dist/shaders/neuro-noise.js +2 -2
- package/dist/shaders/neuro-noise.js.map +2 -2
- package/dist/shaders/paper-texture.d.ts +53 -0
- package/dist/shaders/paper-texture.js +236 -0
- package/dist/shaders/paper-texture.js.map +7 -0
- package/dist/shaders/perlin-noise.js +111 -117
- package/dist/shaders/perlin-noise.js.map +2 -2
- package/dist/shaders/pulsing-border.d.ts +1 -0
- package/dist/shaders/pulsing-border.js +23 -15
- package/dist/shaders/pulsing-border.js.map +2 -2
- package/dist/shaders/simplex-noise.js +2 -2
- package/dist/shaders/simplex-noise.js.map +2 -2
- package/dist/shaders/smoke-ring.js +13 -8
- package/dist/shaders/smoke-ring.js.map +2 -2
- package/dist/shaders/spiral.js +3 -3
- package/dist/shaders/spiral.js.map +2 -2
- package/dist/shaders/static-mesh-gradient.d.ts +2 -0
- package/dist/shaders/static-mesh-gradient.js +15 -14
- package/dist/shaders/static-mesh-gradient.js.map +2 -2
- package/dist/shaders/static-radial-gradient.d.ts +2 -0
- package/dist/shaders/static-radial-gradient.js +15 -13
- package/dist/shaders/static-radial-gradient.js.map +2 -2
- package/dist/shaders/swirl.js +3 -3
- package/dist/shaders/swirl.js.map +2 -2
- package/dist/shaders/voronoi.js +6 -10
- package/dist/shaders/voronoi.js.map +2 -2
- package/dist/shaders/warp.d.ts +3 -0
- package/dist/shaders/warp.js +20 -4
- package/dist/shaders/warp.js.map +2 -2
- package/dist/shaders/water.d.ts +39 -0
- package/dist/shaders/water.js +119 -0
- package/dist/shaders/water.js.map +7 -0
- package/dist/vertex-shader.d.ts +2 -0
- package/dist/vertex-shader.js +212 -0
- package/dist/vertex-shader.js.map +7 -0
- package/package.json +1 -1
package/dist/shaders/voronoi.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
5
|
|
|
6
6
|
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
-
import { declarePI } from "../shader-utils.js";
|
|
7
|
+
import { declarePI, textureRandomizerGB } from "../shader-utils.js";
|
|
8
8
|
const voronoiMeta = {
|
|
9
9
|
maxColorCount: 5
|
|
10
10
|
};
|
|
@@ -32,11 +32,7 @@ ${sizingVariablesDeclaration}
|
|
|
32
32
|
out vec4 fragColor;
|
|
33
33
|
|
|
34
34
|
${declarePI}
|
|
35
|
-
|
|
36
|
-
vec2 hash(vec2 p) {
|
|
37
|
-
vec2 uv = floor(p) / 100. + .5;
|
|
38
|
-
return texture(u_noiseTexture, uv).gb;
|
|
39
|
-
}
|
|
35
|
+
${textureRandomizerGB}
|
|
40
36
|
|
|
41
37
|
vec4 voronoi(vec2 x, float t) {
|
|
42
38
|
vec2 ip = floor(x);
|
|
@@ -49,8 +45,8 @@ vec4 voronoi(vec2 x, float t) {
|
|
|
49
45
|
for (int j = -1; j <= 1; j++) {
|
|
50
46
|
for (int i = -1; i <= 1; i++) {
|
|
51
47
|
vec2 g = vec2(float(i), float(j));
|
|
52
|
-
vec2
|
|
53
|
-
|
|
48
|
+
vec2 o = randomGB(ip + g);
|
|
49
|
+
float raw_hash = o.x;
|
|
54
50
|
o = .5 + u_distortion * sin(t + TWO_PI * o);
|
|
55
51
|
vec2 r = g + o - fp;
|
|
56
52
|
float d = dot(r, r);
|
|
@@ -59,7 +55,7 @@ vec4 voronoi(vec2 x, float t) {
|
|
|
59
55
|
md = d;
|
|
60
56
|
mr = r;
|
|
61
57
|
mg = g;
|
|
62
|
-
rand = raw_hash
|
|
58
|
+
rand = raw_hash;
|
|
63
59
|
}
|
|
64
60
|
}
|
|
65
61
|
}
|
|
@@ -68,7 +64,7 @@ vec4 voronoi(vec2 x, float t) {
|
|
|
68
64
|
for (int j = -2; j <= 2; j++) {
|
|
69
65
|
for (int i = -2; i <= 2; i++) {
|
|
70
66
|
vec2 g = mg + vec2(float(i), float(j));
|
|
71
|
-
vec2 o =
|
|
67
|
+
vec2 o = randomGB(ip + g);
|
|
72
68
|
o = .5 + u_distortion * sin(t + TWO_PI * o);
|
|
73
69
|
vec2 r = g + o - fp;
|
|
74
70
|
if (dot(mr - r, mr - r) > .00001) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/voronoi.ts"],
|
|
4
|
-
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI } from '../shader-utils.js';\n\nexport const voronoiMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Double-pass Voronoi pattern cell edges\n * Original algorithm: https://www.shadertoy.com/view/ldl3W8\n *\n * Uniforms:\n * - u_colorBack, u_colorGlow (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_stepsPerColor: discrete color steps between u_colors\n * - u_distortion (0..0.5): max distance the cell center moves away from regular grid\n * - u_gap: width of the stroke between the cells\n * - u_glow: radial glow around each cell center\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n *\n * Note: gaps can't be removed completely due to artifacts of Voronoi cells\n *\n */\n\n// language=GLSL\nexport const voronoiFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${voronoiMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_stepsPerColor;\nuniform vec4 u_colorGlow;\nuniform vec4 u_colorGap;\nuniform float u_distortion;\nuniform float u_gap;\nuniform float u_glow;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n
|
|
5
|
-
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, textureRandomizerGB } from '../shader-utils.js';\n\nexport const voronoiMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Double-pass Voronoi pattern cell edges\n * Original algorithm: https://www.shadertoy.com/view/ldl3W8\n *\n * Uniforms:\n * - u_colorBack, u_colorGlow (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_stepsPerColor: discrete color steps between u_colors\n * - u_distortion (0..0.5): max distance the cell center moves away from regular grid\n * - u_gap: width of the stroke between the cells\n * - u_glow: radial glow around each cell center\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n *\n * Note: gaps can't be removed completely due to artifacts of Voronoi cells\n *\n */\n\n// language=GLSL\nexport const voronoiFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${voronoiMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_stepsPerColor;\nuniform vec4 u_colorGlow;\nuniform vec4 u_colorGap;\nuniform float u_distortion;\nuniform float u_gap;\nuniform float u_glow;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${textureRandomizerGB}\n\nvec4 voronoi(vec2 x, float t) {\n vec2 ip = floor(x);\n vec2 fp = fract(x);\n\n vec2 mg, mr;\n float md = 8.;\n float rand = 0.;\n\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n vec2 g = vec2(float(i), float(j));\n vec2 o = randomGB(ip + g);\n float raw_hash = o.x;\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n float d = dot(r, r);\n\n if (d < md) {\n md = d;\n mr = r;\n mg = g;\n rand = raw_hash;\n }\n }\n }\n\n md = 8.;\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n vec2 g = mg + vec2(float(i), float(j));\n vec2 o = randomGB(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n if (dot(mr - r, mr - r) > .00001) {\n md = min(md, dot(.5 * (mr + r), normalize(r - mr)));\n }\n }\n }\n\n return vec4(md, mr, rand);\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= 1.25;\n\n float t = u_time;\n\n vec4 voronoiRes = voronoi(shape_uv, t);\n\n float shape = clamp(voronoiRes.w, 0., 1.);\n float mixer = shape * (u_colorsCount - 1.);\n mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\n float steps = max(1., u_stepsPerColor);\n\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${voronoiMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n float localT = clamp(mixer - float(i - 1), 0.0, 1.0);\n localT = round(localT * steps) / steps;\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {\n float localT = mixer + 1.;\n if (mixer > (u_colorsCount - 1.)) {\n localT = mixer - (u_colorsCount - 1.);\n }\n localT = round(localT * steps) / steps;\n vec4 cFst = u_colors[0];\n cFst.rgb *= cFst.a;\n vec4 cLast = u_colors[int(u_colorsCount - 1.)];\n cLast.rgb *= cLast.a;\n gradient = mix(cLast, cFst, localT);\n }\n\n vec3 cellColor = gradient.rgb;\n float cellOpacity = gradient.a;\n\n float glows = length(voronoiRes.yz * u_glow);\n glows = pow(glows, 1.5);\n\n vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * glows);\n float opacity = cellOpacity + u_colorGlow.a * glows;\n\n float edge = voronoiRes.x;\n float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);\n edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);\n\n color = mix(u_colorGap.rgb * u_colorGap.a, color, edge);\n opacity = mix(u_colorGap.a, opacity, edge);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface VoronoiUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_stepsPerColor: number;\n u_colorGap: [number, number, number, number];\n u_colorGlow: [number, number, number, number];\n u_distortion: number;\n u_gap: number;\n u_glow: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n stepsPerColor?: number;\n colorGap?: string;\n colorGlow?: string;\n distortion?: number;\n gap?: number;\n glow?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,2BAA2B;AAExC,MAAM,cAAc;AAAA,EACzB,eAAe;AACjB;AAqBO,MAAM,wBAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBASrB,YAAY,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU/C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBA2DG,YAAY,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/shaders/warp.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export declare const warpMeta: {
|
|
|
19
19
|
* - u_distortion: value noise distortion over the UV coordinate
|
|
20
20
|
* - u_swirl, u_swirlIterations: swirly distortion (layering curves effect)
|
|
21
21
|
*
|
|
22
|
+
* - u_noiseTexture (sampler2D): pre-computed randomizer source
|
|
23
|
+
*
|
|
22
24
|
*/
|
|
23
25
|
export declare const warpFragmentShader: string;
|
|
24
26
|
export interface WarpUniforms extends ShaderSizingUniforms {
|
|
@@ -31,6 +33,7 @@ export interface WarpUniforms extends ShaderSizingUniforms {
|
|
|
31
33
|
u_distortion: number;
|
|
32
34
|
u_swirl: number;
|
|
33
35
|
u_swirlIterations: number;
|
|
36
|
+
u_noiseTexture?: HTMLImageElement;
|
|
34
37
|
}
|
|
35
38
|
export interface WarpParams extends ShaderSizingParams, ShaderMotionParams {
|
|
36
39
|
colors?: string[];
|
package/dist/shaders/warp.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
5
|
|
|
6
6
|
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
-
import { declarePI,
|
|
7
|
+
import { declarePI, rotation2, colorBandingFix } from "../shader-utils.js";
|
|
8
8
|
const warpMeta = {
|
|
9
9
|
maxColorCount: 10
|
|
10
10
|
};
|
|
@@ -14,6 +14,8 @@ precision mediump float;
|
|
|
14
14
|
uniform float u_time;
|
|
15
15
|
uniform float u_scale;
|
|
16
16
|
|
|
17
|
+
uniform sampler2D u_noiseTexture;
|
|
18
|
+
|
|
17
19
|
uniform vec4 u_colors[${warpMeta.maxColorCount}];
|
|
18
20
|
uniform float u_colorsCount;
|
|
19
21
|
uniform float u_proportion;
|
|
@@ -29,9 +31,23 @@ ${sizingVariablesDeclaration}
|
|
|
29
31
|
out vec4 fragColor;
|
|
30
32
|
|
|
31
33
|
${declarePI}
|
|
32
|
-
${
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
${rotation2}
|
|
35
|
+
float randomG(vec2 p) {
|
|
36
|
+
vec2 uv = floor(p) / 100. + .5;
|
|
37
|
+
return texture(u_noiseTexture, fract(uv)).g;
|
|
38
|
+
}
|
|
39
|
+
float valueNoise(vec2 st) {
|
|
40
|
+
vec2 i = floor(st);
|
|
41
|
+
vec2 f = fract(st);
|
|
42
|
+
float a = randomG(i);
|
|
43
|
+
float b = randomG(i + vec2(1.0, 0.0));
|
|
44
|
+
float c = randomG(i + vec2(0.0, 1.0));
|
|
45
|
+
float d = randomG(i + vec2(1.0, 1.0));
|
|
46
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
47
|
+
float x1 = mix(a, b, u.x);
|
|
48
|
+
float x2 = mix(c, d, u.x);
|
|
49
|
+
return mix(x1, x2, u.y);
|
|
50
|
+
}
|
|
35
51
|
|
|
36
52
|
|
|
37
53
|
void main() {
|
package/dist/shaders/warp.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/warp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI,
|
|
5
|
-
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,
|
|
4
|
+
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, rotation2, colorBandingFix } from '../shader-utils.js';\n\nexport const warpMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * Iterative layered + swirl-based distortion applied over different layouts (shapes)\n *\n * Uniforms:\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_proportion: (0..1) blend point between 2 colors (0.5 = equal distribution)\n * - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)\n * - u_shape (float used as integer):\n * ---- 0: checks\n * ---- 1: stripes\n * ---- 2: 2x halves of canvas (mapping the canvas height regardless of resolution)\n * - u_shapeScale: the scale of layouts (underlying shapes)\n * - u_distortion: value noise distortion over the UV coordinate\n * - u_swirl, u_swirlIterations: swirly distortion (layering curves effect)\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n *\n */\n\n// language=GLSL\nexport const warpFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${warpMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform float u_proportion;\nuniform float u_softness;\nuniform float u_shape;\nuniform float u_shapeScale;\nuniform float u_distortion;\nuniform float u_swirl;\nuniform float u_swirlIterations;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${rotation2}\nfloat randomG(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, fract(uv)).g;\n}\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = randomG(i);\n float b = randomG(i + vec2(1.0, 0.0));\n float c = randomG(i + vec2(0.0, 1.0));\n float d = randomG(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\n\n\nvoid main() {\n vec2 uv = v_patternUV;\n uv *= .5;\n\n float t = 0.0625 * u_time;\n\n float n1 = valueNoise(uv * 1. + t);\n float n2 = valueNoise(uv * 2. - t);\n float angle = n1 * TWO_PI;\n uv.x += 4. * u_distortion * n2 * cos(angle);\n uv.y += 4. * u_distortion * n2 * sin(angle);\n\n float swirl = u_swirl;\n for (int i = 1; i <= 20; i++) {\n if (i >= int(u_swirlIterations)) break;\n float iFloat = float(i);\n// swirl *= (1. - smoothstep(.0, .25, length(fwidth(uv))));\n uv.x += swirl / iFloat * cos(t + iFloat * 1.5 * uv.y);\n uv.y += swirl / iFloat * cos(t + iFloat * 1. * uv.x);\n }\n\n float proportion = clamp(u_proportion, 0., 1.);\n\n float shape = 0.;\n if (u_shape < .5) {\n vec2 checksShape_uv = uv * (.5 + 3.5 * u_shapeScale);\n shape = .5 + .5 * sin(checksShape_uv.x) * cos(checksShape_uv.y);\n shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);\n } else if (u_shape < 1.5) {\n vec2 stripesShape_uv = uv * (2. * u_shapeScale);\n float f = fract(stripesShape_uv.y);\n shape = smoothstep(.0, .55, f) * smoothstep(1., .45, f);\n shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);\n } else {\n float shapeScaling = 5. * (1. - u_shapeScale);\n shape = smoothstep(.45 - shapeScaling, .55 + shapeScaling, 1. - uv.y + .3 * (proportion - .5));\n }\n\n float mixer = shape * (u_colorsCount - 1.);\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n float aa = fwidth(shape);\n for (int i = 1; i < ${warpMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n float m = clamp(mixer - float(i - 1), 0.0, 1.0);\n\n float localMixerStart = floor(m);\n float softness = .5 * u_softness + fwidth(m);\n float smoothed = smoothstep(max(0., .5 - softness - aa), min(1., .5 + softness + aa), m - localMixerStart);\n float stepped = localMixerStart + smoothed;\n\n m = mix(stepped, m, u_softness);\n\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, m);\n }\n\n vec3 color = gradient.rgb;\n float opacity = gradient.a;\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface WarpUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_proportion: number;\n u_softness: number;\n u_shape: (typeof WarpPatterns)[WarpPattern];\n u_shapeScale: number;\n u_distortion: number;\n u_swirl: number;\n u_swirlIterations: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface WarpParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n rotation?: number;\n proportion?: number;\n softness?: number;\n shape?: WarpPattern;\n shapeScale?: number;\n distortion?: number;\n swirl?: number;\n swirlIterations?: number;\n}\n\nexport const WarpPatterns = {\n checks: 0,\n stripes: 1,\n edge: 2,\n} as const;\n\nexport type WarpPattern = keyof typeof WarpPatterns;\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,WAAW,uBAAuB;AAE/C,MAAM,WAAW;AAAA,EACtB,eAAe;AACjB;AAsBO,MAAM,qBAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAQlB,SAAS,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU5C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBA6Da,SAAS,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAmB1C,eAAe;AAAA;AAAA;AAAA;AAAA;AA+BZ,MAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ShaderMotionParams } from '../shader-mount.js';
|
|
2
|
+
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
|
|
3
|
+
/**
|
|
4
|
+
* Mimicking water surface distortion with a combination of noises;
|
|
5
|
+
* Can be applied over the texture or just be used as an animated pattern
|
|
6
|
+
*
|
|
7
|
+
* Uniforms:
|
|
8
|
+
* - u_colorBack, u_highlightColor (RGBA)
|
|
9
|
+
* - u_effectScale: pattern scale relative to the image
|
|
10
|
+
* - u_caustic: power of caustic distortion
|
|
11
|
+
* - u_layering: the power of 2nd layer of caustic distortion
|
|
12
|
+
* - u_edges: caustic distortion power on the image edges
|
|
13
|
+
* - u_waves: additional distortion based in Simplex noise, independent from caustic
|
|
14
|
+
* - u_highlights: a coloring added over the image/background, following the caustic shape
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare const waterFragmentShader: string;
|
|
18
|
+
export interface WaterUniforms extends ShaderSizingUniforms {
|
|
19
|
+
u_image: HTMLImageElement | string | undefined;
|
|
20
|
+
u_colorBack: [number, number, number, number];
|
|
21
|
+
u_highlightColor: [number, number, number, number];
|
|
22
|
+
u_highlights: number;
|
|
23
|
+
u_layering: number;
|
|
24
|
+
u_edges: number;
|
|
25
|
+
u_caustic: number;
|
|
26
|
+
u_waves: number;
|
|
27
|
+
u_effectScale: number;
|
|
28
|
+
}
|
|
29
|
+
export interface WaterParams extends ShaderSizingParams, ShaderMotionParams {
|
|
30
|
+
image?: HTMLImageElement | string | undefined;
|
|
31
|
+
colorBack?: string;
|
|
32
|
+
highlightColor?: string;
|
|
33
|
+
highlights?: number;
|
|
34
|
+
layering?: number;
|
|
35
|
+
edges?: number;
|
|
36
|
+
caustic?: number;
|
|
37
|
+
waves?: number;
|
|
38
|
+
effectScale?: number;
|
|
39
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
+
import { declarePI, rotation2, simplexNoise } from "../shader-utils.js";
|
|
8
|
+
const waterFragmentShader = `#version 300 es
|
|
9
|
+
precision mediump float;
|
|
10
|
+
|
|
11
|
+
uniform float u_time;
|
|
12
|
+
|
|
13
|
+
uniform vec4 u_colorBack;
|
|
14
|
+
uniform vec4 u_highlightColor;
|
|
15
|
+
|
|
16
|
+
uniform sampler2D u_image;
|
|
17
|
+
uniform float u_imageAspectRatio;
|
|
18
|
+
|
|
19
|
+
uniform float u_effectScale;
|
|
20
|
+
uniform float u_highlights;
|
|
21
|
+
uniform float u_layering;
|
|
22
|
+
uniform float u_edges;
|
|
23
|
+
uniform float u_caustic;
|
|
24
|
+
uniform float u_waves;
|
|
25
|
+
|
|
26
|
+
${sizingVariablesDeclaration}
|
|
27
|
+
|
|
28
|
+
out vec4 fragColor;
|
|
29
|
+
|
|
30
|
+
${declarePI}
|
|
31
|
+
${rotation2}
|
|
32
|
+
${simplexNoise}
|
|
33
|
+
|
|
34
|
+
float getUvFrame(vec2 uv) {
|
|
35
|
+
float aax = 2. * fwidth(uv.x);
|
|
36
|
+
float aay = 2. * fwidth(uv.y);
|
|
37
|
+
|
|
38
|
+
float left = smoothstep(0., aax, uv.x);
|
|
39
|
+
float right = smoothstep(1., 1. - aax, uv.x);
|
|
40
|
+
float bottom = smoothstep(0., aay, uv.y);
|
|
41
|
+
float top = smoothstep(1., 1. - aay, uv.y);
|
|
42
|
+
|
|
43
|
+
return left * right * bottom * top;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
mat2 rotate2D(float r) {
|
|
47
|
+
return mat2(cos(r), sin(r), -sin(r), cos(r));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
float getCausticNoise(vec2 uv, float t, float scale) {
|
|
51
|
+
vec2 n = vec2(.1);
|
|
52
|
+
vec2 N = vec2(.1);
|
|
53
|
+
mat2 m = rotate2D(.5);
|
|
54
|
+
for (int j = 0; j < 6; j++) {
|
|
55
|
+
uv *= m;
|
|
56
|
+
n *= m;
|
|
57
|
+
vec2 q = uv * scale + float(j) + n + (.5 + .5 * float(j)) * (mod(float(j), 2.) - 1.) * t;
|
|
58
|
+
n += sin(q);
|
|
59
|
+
N += cos(q) / scale;
|
|
60
|
+
scale *= 1.1;
|
|
61
|
+
}
|
|
62
|
+
return (N.x + N.y + 1.);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
void main() {
|
|
66
|
+
vec2 imageUV = v_imageUV;
|
|
67
|
+
vec2 patternUV = v_imageUV - .5;
|
|
68
|
+
patternUV = 10. * u_effectScale * (patternUV * vec2(u_imageAspectRatio, 1.));
|
|
69
|
+
|
|
70
|
+
float t = u_time;
|
|
71
|
+
|
|
72
|
+
float wavesNoise = snoise((.3 + .1 * sin(t)) * .1 * patternUV + vec2(0., .4 * t));
|
|
73
|
+
|
|
74
|
+
float causticNoise = getCausticNoise(patternUV + u_waves * vec2(1., -1.) * wavesNoise, 2. * t, 1.5);
|
|
75
|
+
|
|
76
|
+
causticNoise += u_layering * getCausticNoise(patternUV + 2. * u_waves * vec2(1., -1.) * wavesNoise, 1.5 * t, 2.);
|
|
77
|
+
causticNoise = pow(causticNoise, 2.);
|
|
78
|
+
|
|
79
|
+
float edgesDistortion = smoothstep(0., .1, imageUV.x);
|
|
80
|
+
edgesDistortion *= smoothstep(0., .1, imageUV.y);
|
|
81
|
+
edgesDistortion *= (smoothstep(1., 1.1, imageUV.x) + smoothstep(.95, .8, imageUV.x));
|
|
82
|
+
edgesDistortion *= smoothstep(1., .9, imageUV.y);
|
|
83
|
+
edgesDistortion = mix(edgesDistortion, 1., u_edges);
|
|
84
|
+
|
|
85
|
+
float causticNoiseDistortion = .02 * causticNoise * edgesDistortion;
|
|
86
|
+
|
|
87
|
+
float wavesDistortion = .1 * u_waves * wavesNoise;
|
|
88
|
+
|
|
89
|
+
imageUV += vec2(wavesDistortion, -wavesDistortion);
|
|
90
|
+
imageUV += (u_caustic * causticNoiseDistortion);
|
|
91
|
+
|
|
92
|
+
float frame = getUvFrame(imageUV);
|
|
93
|
+
|
|
94
|
+
vec4 image = texture(u_image, imageUV);
|
|
95
|
+
vec4 backColor = u_colorBack;
|
|
96
|
+
backColor.rgb *= backColor.a;
|
|
97
|
+
|
|
98
|
+
vec3 color = mix(backColor.rgb, image.rgb, image.a * frame);
|
|
99
|
+
float opacity = backColor.a + image.a * frame;
|
|
100
|
+
|
|
101
|
+
causticNoise = max(-.2, causticNoise);
|
|
102
|
+
|
|
103
|
+
float hightlight = .025 * u_highlights * causticNoise;
|
|
104
|
+
hightlight *= u_highlightColor.a;
|
|
105
|
+
color = mix(color, u_highlightColor.rgb, .05 * u_highlights * causticNoise);
|
|
106
|
+
opacity += hightlight;
|
|
107
|
+
|
|
108
|
+
color += hightlight * (.5 + .5 * wavesNoise);
|
|
109
|
+
opacity += hightlight * (.5 + .5 * wavesNoise);
|
|
110
|
+
|
|
111
|
+
opacity = clamp(opacity, 0., 1.);
|
|
112
|
+
|
|
113
|
+
fragColor = vec4(color, opacity);
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
116
|
+
export {
|
|
117
|
+
waterFragmentShader
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=water.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shaders/water.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, rotation2, simplexNoise } from '../shader-utils.js';\n\n/**\n * Mimicking water surface distortion with a combination of noises;\n * Can be applied over the texture or just be used as an animated pattern\n *\n * Uniforms:\n * - u_colorBack, u_highlightColor (RGBA)\n * - u_effectScale: pattern scale relative to the image\n * - u_caustic: power of caustic distortion\n * - u_layering: the power of 2nd layer of caustic distortion\n * - u_edges: caustic distortion power on the image edges\n * - u_waves: additional distortion based in Simplex noise, independent from caustic\n * - u_highlights: a coloring added over the image/background, following the caustic shape\n *\n */\n\n// language=GLSL\nexport const waterFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_highlightColor;\n\nuniform sampler2D u_image;\nuniform float u_imageAspectRatio;\n\nuniform float u_effectScale;\nuniform float u_highlights;\nuniform float u_layering;\nuniform float u_edges;\nuniform float u_caustic;\nuniform float u_waves;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${rotation2}\n${simplexNoise}\n\nfloat getUvFrame(vec2 uv) {\n float aax = 2. * fwidth(uv.x);\n float aay = 2. * fwidth(uv.y);\n\n float left = smoothstep(0., aax, uv.x);\n float right = smoothstep(1., 1. - aax, uv.x);\n float bottom = smoothstep(0., aay, uv.y);\n float top = smoothstep(1., 1. - aay, uv.y);\n\n return left * right * bottom * top;\n}\n\nmat2 rotate2D(float r) {\n return mat2(cos(r), sin(r), -sin(r), cos(r));\n}\n\nfloat getCausticNoise(vec2 uv, float t, float scale) {\n vec2 n = vec2(.1);\n vec2 N = vec2(.1);\n mat2 m = rotate2D(.5);\n for (int j = 0; j < 6; j++) {\n uv *= m;\n n *= m;\n vec2 q = uv * scale + float(j) + n + (.5 + .5 * float(j)) * (mod(float(j), 2.) - 1.) * t;\n n += sin(q);\n N += cos(q) / scale;\n scale *= 1.1;\n }\n return (N.x + N.y + 1.);\n}\n\nvoid main() {\n vec2 imageUV = v_imageUV;\n vec2 patternUV = v_imageUV - .5;\n patternUV = 10. * u_effectScale * (patternUV * vec2(u_imageAspectRatio, 1.));\n \n float t = u_time;\n \n float wavesNoise = snoise((.3 + .1 * sin(t)) * .1 * patternUV + vec2(0., .4 * t));\n\n float causticNoise = getCausticNoise(patternUV + u_waves * vec2(1., -1.) * wavesNoise, 2. * t, 1.5);\n\n causticNoise += u_layering * getCausticNoise(patternUV + 2. * u_waves * vec2(1., -1.) * wavesNoise, 1.5 * t, 2.);\n causticNoise = pow(causticNoise, 2.);\n \n float edgesDistortion = smoothstep(0., .1, imageUV.x);\n edgesDistortion *= smoothstep(0., .1, imageUV.y);\n edgesDistortion *= (smoothstep(1., 1.1, imageUV.x) + smoothstep(.95, .8, imageUV.x));\n edgesDistortion *= smoothstep(1., .9, imageUV.y);\n edgesDistortion = mix(edgesDistortion, 1., u_edges);\n \n float causticNoiseDistortion = .02 * causticNoise * edgesDistortion;\n \n float wavesDistortion = .1 * u_waves * wavesNoise;\n \n imageUV += vec2(wavesDistortion, -wavesDistortion);\n imageUV += (u_caustic * causticNoiseDistortion);\n\n float frame = getUvFrame(imageUV);\n\n vec4 image = texture(u_image, imageUV);\n vec4 backColor = u_colorBack;\n backColor.rgb *= backColor.a;\n \n vec3 color = mix(backColor.rgb, image.rgb, image.a * frame);\n float opacity = backColor.a + image.a * frame;\n\n causticNoise = max(-.2, causticNoise);\n \n float hightlight = .025 * u_highlights * causticNoise;\n hightlight *= u_highlightColor.a;\n color = mix(color, u_highlightColor.rgb, .05 * u_highlights * causticNoise);\n opacity += hightlight;\n \n color += hightlight * (.5 + .5 * wavesNoise);\n opacity += hightlight * (.5 + .5 * wavesNoise);\n \n opacity = clamp(opacity, 0., 1.);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface WaterUniforms extends ShaderSizingUniforms {\n u_image: HTMLImageElement | string | undefined;\n u_colorBack: [number, number, number, number];\n u_highlightColor: [number, number, number, number];\n u_highlights: number;\n u_layering: number;\n u_edges: number;\n u_caustic: number;\n u_waves: number;\n u_effectScale: number;\n}\n\nexport interface WaterParams extends ShaderSizingParams, ShaderMotionParams {\n image?: HTMLImageElement | string | undefined;\n colorBack?: string;\n highlightColor?: string;\n highlights?: number;\n layering?: number;\n edges?: number;\n caustic?: number;\n waves?: number;\n effectScale?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AACA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,WAAW,oBAAoB;AAkB5C,MAAM,sBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBzC,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Vertex shader for the shader mount */
|
|
2
|
+
export declare const vertexShaderSource = "#version 300 es\nprecision mediump float;\n\nlayout(location = 0) in vec4 a_position;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_imageAspectRatio;\n\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\n\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;\n\nuniform float u_pxSize;\n\nout vec2 v_objectUV;\nout vec2 v_objectBoxSize;\nout vec2 v_objectHelperBox;\n\nout vec2 v_responsiveUV;\nout vec2 v_responsiveBoxSize;\nout vec2 v_responsiveHelperBox;\nout vec2 v_responsiveBoxGivenSize;\n\nout vec2 v_patternUV;\nout vec2 v_patternBoxSize;\nout vec2 v_patternHelperBox;\n\nout vec2 v_imageUV;\n\n// #define ADD_HELPERS\n\nvec3 getBoxSize(float boxRatio, vec2 givenBoxSize, vec2 maxBoxSize) {\n vec2 box = vec2(0.);\n // fit = none\n box.x = boxRatio * min(givenBoxSize.x / boxRatio, givenBoxSize.y);\n float noFitBoxWidth = box.x;\n if (u_fit == 1.) { // fit = contain\n box.x = boxRatio * min(maxBoxSize[0] / boxRatio, maxBoxSize[1]);\n } else if (u_fit == 2.) { // fit = cover\n box.x = boxRatio * max(maxBoxSize[0] / boxRatio, maxBoxSize[1]);\n }\n box.y = box.x / boxRatio;\n return vec3(box, noFitBoxWidth);\n}\n\nvoid main() {\n gl_Position = a_position;\n\n vec2 uv = gl_Position.xy * .5;\n vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);\n vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);\n givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;\n vec2 maxBoxSize = vec2(max(u_resolution.x, givenBoxSize.x), max(u_resolution.y, givenBoxSize.y));\n float r = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n\n\n // ===================================================\n // Sizing api for graphic objects with fixed ratio\n // (currently supports only ratio = 1)\n\n float fixedRatio = 1.;\n vec2 fixedRatioBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n\n v_objectBoxSize = getBoxSize(fixedRatio, fixedRatioBoxGivenSize, maxBoxSize).xy;\n vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;\n\n #ifdef ADD_HELPERS\n v_objectHelperBox = uv;\n v_objectHelperBox *= objectWorldScale;\n v_objectHelperBox += boxOrigin * (objectWorldScale - 1.);\n #endif\n\n v_objectUV = uv;\n v_objectUV *= objectWorldScale;\n v_objectUV += boxOrigin * (objectWorldScale - 1.);\n v_objectUV += graphicOffset;\n v_objectUV /= u_scale;\n v_objectUV = graphicRotation * v_objectUV;\n\n\n // ===================================================\n\n\n // ===================================================\n // Sizing api for graphic objects with either givenBoxSize ratio or canvas ratio.\n // Full-screen mode available with u_worldWidth = u_worldHeight = 0\n\n v_responsiveBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n float responsiveRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;\n v_responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize, maxBoxSize).xy;\n vec2 responsiveBoxScale = u_resolution.xy / v_responsiveBoxSize;\n\n #ifdef ADD_HELPERS\n v_responsiveHelperBox = uv;\n v_responsiveHelperBox *= responsiveBoxScale;\n v_responsiveHelperBox += boxOrigin * (responsiveBoxScale - 1.);\n #endif\n\n v_responsiveUV = uv;\n v_responsiveUV *= responsiveBoxScale;\n v_responsiveUV += boxOrigin * (responsiveBoxScale - 1.);\n v_responsiveUV += graphicOffset;\n v_responsiveUV /= u_scale;\n v_responsiveUV.x *= responsiveRatio;\n v_responsiveUV = graphicRotation * v_responsiveUV;\n v_responsiveUV.x /= responsiveRatio;\n\n // ===================================================\n\n\n // ===================================================\n // Sizing api for patterns\n // (treating graphics as a image u_worldWidth x u_worldHeight size)\n\n float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;\n vec2 patternBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y;\n\n vec3 boxSizeData = getBoxSize(patternBoxRatio, patternBoxGivenSize, maxBoxSize);\n v_patternBoxSize = boxSizeData.xy;\n float patternBoxNoFitBoxWidth = boxSizeData.z;\n vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;\n\n #ifdef ADD_HELPERS\n v_patternHelperBox = uv;\n v_patternHelperBox *= patternBoxScale;\n v_patternHelperBox += boxOrigin * (patternBoxScale - 1.);\n #endif\n\n v_patternUV = uv;\n v_patternUV += graphicOffset / patternBoxScale;\n v_patternUV += boxOrigin;\n v_patternUV -= boxOrigin / patternBoxScale;\n v_patternUV *= u_resolution.xy;\n v_patternUV /= u_pixelRatio;\n if (u_fit > 0.) {\n v_patternUV *= (patternBoxNoFitBoxWidth / v_patternBoxSize.x);\n }\n v_patternUV /= u_scale;\n v_patternUV = graphicRotation * v_patternUV;\n v_patternUV += boxOrigin / patternBoxScale;\n v_patternUV -= boxOrigin;\n // x100 is a default multiplier between vertex and fragmant shaders\n // we use it to avoid UV presision issues\n v_patternUV *= .01;\n\n // ===================================================\n\n\n // ===================================================\n // Sizing api for images\n\n vec2 imageBoxSize;\n if (u_fit == 1.) { // contain\n imageBoxSize.x = min(maxBoxSize.x / u_imageAspectRatio, maxBoxSize.y) * u_imageAspectRatio;\n } else if (u_fit == 2.) { // cover\n imageBoxSize.x = max(maxBoxSize.x / u_imageAspectRatio, maxBoxSize.y) * u_imageAspectRatio;\n } else {\n imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);\n }\n imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;\n vec2 imageBoxScale = u_resolution.xy / imageBoxSize;\n\n #ifdef ADD_HELPERS\n vec2 imageHelperBox = uv;\n imageHelperBox *= imageBoxScale;\n imageHelperBox += boxOrigin * (imageBoxScale - 1.);\n #endif\n\n v_imageUV = uv;\n v_imageUV *= imageBoxScale;\n v_imageUV += boxOrigin * (imageBoxScale - 1.);\n v_imageUV += graphicOffset;\n v_imageUV /= u_scale;\n v_imageUV.x *= u_imageAspectRatio;\n v_imageUV = graphicRotation * v_imageUV;\n v_imageUV.x /= u_imageAspectRatio;\n\n v_imageUV += .5;\n v_imageUV.y = 1. - v_imageUV.y;\n\n // ===================================================\n\n}";
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
const vertexShaderSource = `#version 300 es
|
|
7
|
+
precision mediump float;
|
|
8
|
+
|
|
9
|
+
layout(location = 0) in vec4 a_position;
|
|
10
|
+
|
|
11
|
+
uniform vec2 u_resolution;
|
|
12
|
+
uniform float u_pixelRatio;
|
|
13
|
+
uniform float u_imageAspectRatio;
|
|
14
|
+
|
|
15
|
+
uniform float u_originX;
|
|
16
|
+
uniform float u_originY;
|
|
17
|
+
uniform float u_worldWidth;
|
|
18
|
+
uniform float u_worldHeight;
|
|
19
|
+
uniform float u_fit;
|
|
20
|
+
|
|
21
|
+
uniform float u_scale;
|
|
22
|
+
uniform float u_rotation;
|
|
23
|
+
uniform float u_offsetX;
|
|
24
|
+
uniform float u_offsetY;
|
|
25
|
+
|
|
26
|
+
uniform float u_pxSize;
|
|
27
|
+
|
|
28
|
+
out vec2 v_objectUV;
|
|
29
|
+
out vec2 v_objectBoxSize;
|
|
30
|
+
out vec2 v_objectHelperBox;
|
|
31
|
+
|
|
32
|
+
out vec2 v_responsiveUV;
|
|
33
|
+
out vec2 v_responsiveBoxSize;
|
|
34
|
+
out vec2 v_responsiveHelperBox;
|
|
35
|
+
out vec2 v_responsiveBoxGivenSize;
|
|
36
|
+
|
|
37
|
+
out vec2 v_patternUV;
|
|
38
|
+
out vec2 v_patternBoxSize;
|
|
39
|
+
out vec2 v_patternHelperBox;
|
|
40
|
+
|
|
41
|
+
out vec2 v_imageUV;
|
|
42
|
+
|
|
43
|
+
// #define ADD_HELPERS
|
|
44
|
+
|
|
45
|
+
vec3 getBoxSize(float boxRatio, vec2 givenBoxSize, vec2 maxBoxSize) {
|
|
46
|
+
vec2 box = vec2(0.);
|
|
47
|
+
// fit = none
|
|
48
|
+
box.x = boxRatio * min(givenBoxSize.x / boxRatio, givenBoxSize.y);
|
|
49
|
+
float noFitBoxWidth = box.x;
|
|
50
|
+
if (u_fit == 1.) { // fit = contain
|
|
51
|
+
box.x = boxRatio * min(maxBoxSize[0] / boxRatio, maxBoxSize[1]);
|
|
52
|
+
} else if (u_fit == 2.) { // fit = cover
|
|
53
|
+
box.x = boxRatio * max(maxBoxSize[0] / boxRatio, maxBoxSize[1]);
|
|
54
|
+
}
|
|
55
|
+
box.y = box.x / boxRatio;
|
|
56
|
+
return vec3(box, noFitBoxWidth);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void main() {
|
|
60
|
+
gl_Position = a_position;
|
|
61
|
+
|
|
62
|
+
vec2 uv = gl_Position.xy * .5;
|
|
63
|
+
vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);
|
|
64
|
+
vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);
|
|
65
|
+
givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;
|
|
66
|
+
vec2 maxBoxSize = vec2(max(u_resolution.x, givenBoxSize.x), max(u_resolution.y, givenBoxSize.y));
|
|
67
|
+
float r = u_rotation * 3.14159265358979323846 / 180.;
|
|
68
|
+
mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));
|
|
69
|
+
vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// ===================================================
|
|
73
|
+
// Sizing api for graphic objects with fixed ratio
|
|
74
|
+
// (currently supports only ratio = 1)
|
|
75
|
+
|
|
76
|
+
float fixedRatio = 1.;
|
|
77
|
+
vec2 fixedRatioBoxGivenSize = vec2(
|
|
78
|
+
(u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
|
|
79
|
+
(u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
v_objectBoxSize = getBoxSize(fixedRatio, fixedRatioBoxGivenSize, maxBoxSize).xy;
|
|
83
|
+
vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;
|
|
84
|
+
|
|
85
|
+
#ifdef ADD_HELPERS
|
|
86
|
+
v_objectHelperBox = uv;
|
|
87
|
+
v_objectHelperBox *= objectWorldScale;
|
|
88
|
+
v_objectHelperBox += boxOrigin * (objectWorldScale - 1.);
|
|
89
|
+
#endif
|
|
90
|
+
|
|
91
|
+
v_objectUV = uv;
|
|
92
|
+
v_objectUV *= objectWorldScale;
|
|
93
|
+
v_objectUV += boxOrigin * (objectWorldScale - 1.);
|
|
94
|
+
v_objectUV += graphicOffset;
|
|
95
|
+
v_objectUV /= u_scale;
|
|
96
|
+
v_objectUV = graphicRotation * v_objectUV;
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
// ===================================================
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// ===================================================
|
|
103
|
+
// Sizing api for graphic objects with either givenBoxSize ratio or canvas ratio.
|
|
104
|
+
// Full-screen mode available with u_worldWidth = u_worldHeight = 0
|
|
105
|
+
|
|
106
|
+
v_responsiveBoxGivenSize = vec2(
|
|
107
|
+
(u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
|
|
108
|
+
(u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
|
|
109
|
+
);
|
|
110
|
+
float responsiveRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;
|
|
111
|
+
v_responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize, maxBoxSize).xy;
|
|
112
|
+
vec2 responsiveBoxScale = u_resolution.xy / v_responsiveBoxSize;
|
|
113
|
+
|
|
114
|
+
#ifdef ADD_HELPERS
|
|
115
|
+
v_responsiveHelperBox = uv;
|
|
116
|
+
v_responsiveHelperBox *= responsiveBoxScale;
|
|
117
|
+
v_responsiveHelperBox += boxOrigin * (responsiveBoxScale - 1.);
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
v_responsiveUV = uv;
|
|
121
|
+
v_responsiveUV *= responsiveBoxScale;
|
|
122
|
+
v_responsiveUV += boxOrigin * (responsiveBoxScale - 1.);
|
|
123
|
+
v_responsiveUV += graphicOffset;
|
|
124
|
+
v_responsiveUV /= u_scale;
|
|
125
|
+
v_responsiveUV.x *= responsiveRatio;
|
|
126
|
+
v_responsiveUV = graphicRotation * v_responsiveUV;
|
|
127
|
+
v_responsiveUV.x /= responsiveRatio;
|
|
128
|
+
|
|
129
|
+
// ===================================================
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
// ===================================================
|
|
133
|
+
// Sizing api for patterns
|
|
134
|
+
// (treating graphics as a image u_worldWidth x u_worldHeight size)
|
|
135
|
+
|
|
136
|
+
float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;
|
|
137
|
+
vec2 patternBoxGivenSize = vec2(
|
|
138
|
+
(u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
|
|
139
|
+
(u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
|
|
140
|
+
);
|
|
141
|
+
patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y;
|
|
142
|
+
|
|
143
|
+
vec3 boxSizeData = getBoxSize(patternBoxRatio, patternBoxGivenSize, maxBoxSize);
|
|
144
|
+
v_patternBoxSize = boxSizeData.xy;
|
|
145
|
+
float patternBoxNoFitBoxWidth = boxSizeData.z;
|
|
146
|
+
vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;
|
|
147
|
+
|
|
148
|
+
#ifdef ADD_HELPERS
|
|
149
|
+
v_patternHelperBox = uv;
|
|
150
|
+
v_patternHelperBox *= patternBoxScale;
|
|
151
|
+
v_patternHelperBox += boxOrigin * (patternBoxScale - 1.);
|
|
152
|
+
#endif
|
|
153
|
+
|
|
154
|
+
v_patternUV = uv;
|
|
155
|
+
v_patternUV += graphicOffset / patternBoxScale;
|
|
156
|
+
v_patternUV += boxOrigin;
|
|
157
|
+
v_patternUV -= boxOrigin / patternBoxScale;
|
|
158
|
+
v_patternUV *= u_resolution.xy;
|
|
159
|
+
v_patternUV /= u_pixelRatio;
|
|
160
|
+
if (u_fit > 0.) {
|
|
161
|
+
v_patternUV *= (patternBoxNoFitBoxWidth / v_patternBoxSize.x);
|
|
162
|
+
}
|
|
163
|
+
v_patternUV /= u_scale;
|
|
164
|
+
v_patternUV = graphicRotation * v_patternUV;
|
|
165
|
+
v_patternUV += boxOrigin / patternBoxScale;
|
|
166
|
+
v_patternUV -= boxOrigin;
|
|
167
|
+
// x100 is a default multiplier between vertex and fragmant shaders
|
|
168
|
+
// we use it to avoid UV presision issues
|
|
169
|
+
v_patternUV *= .01;
|
|
170
|
+
|
|
171
|
+
// ===================================================
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
// ===================================================
|
|
175
|
+
// Sizing api for images
|
|
176
|
+
|
|
177
|
+
vec2 imageBoxSize;
|
|
178
|
+
if (u_fit == 1.) { // contain
|
|
179
|
+
imageBoxSize.x = min(maxBoxSize.x / u_imageAspectRatio, maxBoxSize.y) * u_imageAspectRatio;
|
|
180
|
+
} else if (u_fit == 2.) { // cover
|
|
181
|
+
imageBoxSize.x = max(maxBoxSize.x / u_imageAspectRatio, maxBoxSize.y) * u_imageAspectRatio;
|
|
182
|
+
} else {
|
|
183
|
+
imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);
|
|
184
|
+
}
|
|
185
|
+
imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;
|
|
186
|
+
vec2 imageBoxScale = u_resolution.xy / imageBoxSize;
|
|
187
|
+
|
|
188
|
+
#ifdef ADD_HELPERS
|
|
189
|
+
vec2 imageHelperBox = uv;
|
|
190
|
+
imageHelperBox *= imageBoxScale;
|
|
191
|
+
imageHelperBox += boxOrigin * (imageBoxScale - 1.);
|
|
192
|
+
#endif
|
|
193
|
+
|
|
194
|
+
v_imageUV = uv;
|
|
195
|
+
v_imageUV *= imageBoxScale;
|
|
196
|
+
v_imageUV += boxOrigin * (imageBoxScale - 1.);
|
|
197
|
+
v_imageUV += graphicOffset;
|
|
198
|
+
v_imageUV /= u_scale;
|
|
199
|
+
v_imageUV.x *= u_imageAspectRatio;
|
|
200
|
+
v_imageUV = graphicRotation * v_imageUV;
|
|
201
|
+
v_imageUV.x /= u_imageAspectRatio;
|
|
202
|
+
|
|
203
|
+
v_imageUV += .5;
|
|
204
|
+
v_imageUV.y = 1. - v_imageUV.y;
|
|
205
|
+
|
|
206
|
+
// ===================================================
|
|
207
|
+
|
|
208
|
+
}`;
|
|
209
|
+
export {
|
|
210
|
+
vertexShaderSource
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=vertex-shader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/vertex-shader.ts"],
|
|
4
|
+
"sourcesContent": ["/** Vertex shader for the shader mount */\n// language=GLSL\nexport const vertexShaderSource = `#version 300 es\nprecision mediump float;\n\nlayout(location = 0) in vec4 a_position;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_imageAspectRatio;\n\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\n\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;\n\nuniform float u_pxSize;\n\nout vec2 v_objectUV;\nout vec2 v_objectBoxSize;\nout vec2 v_objectHelperBox;\n\nout vec2 v_responsiveUV;\nout vec2 v_responsiveBoxSize;\nout vec2 v_responsiveHelperBox;\nout vec2 v_responsiveBoxGivenSize;\n\nout vec2 v_patternUV;\nout vec2 v_patternBoxSize;\nout vec2 v_patternHelperBox;\n\nout vec2 v_imageUV;\n\n// #define ADD_HELPERS\n\nvec3 getBoxSize(float boxRatio, vec2 givenBoxSize, vec2 maxBoxSize) {\n vec2 box = vec2(0.);\n // fit = none\n box.x = boxRatio * min(givenBoxSize.x / boxRatio, givenBoxSize.y);\n float noFitBoxWidth = box.x;\n if (u_fit == 1.) { // fit = contain\n box.x = boxRatio * min(maxBoxSize[0] / boxRatio, maxBoxSize[1]);\n } else if (u_fit == 2.) { // fit = cover\n box.x = boxRatio * max(maxBoxSize[0] / boxRatio, maxBoxSize[1]);\n }\n box.y = box.x / boxRatio;\n return vec3(box, noFitBoxWidth);\n}\n\nvoid main() {\n gl_Position = a_position;\n\n vec2 uv = gl_Position.xy * .5;\n vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);\n vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);\n givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;\n vec2 maxBoxSize = vec2(max(u_resolution.x, givenBoxSize.x), max(u_resolution.y, givenBoxSize.y));\n float r = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n\n\n // ===================================================\n // Sizing api for graphic objects with fixed ratio\n // (currently supports only ratio = 1)\n\n float fixedRatio = 1.;\n vec2 fixedRatioBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n\n v_objectBoxSize = getBoxSize(fixedRatio, fixedRatioBoxGivenSize, maxBoxSize).xy;\n vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;\n\n #ifdef ADD_HELPERS\n v_objectHelperBox = uv;\n v_objectHelperBox *= objectWorldScale;\n v_objectHelperBox += boxOrigin * (objectWorldScale - 1.);\n #endif\n\n v_objectUV = uv;\n v_objectUV *= objectWorldScale;\n v_objectUV += boxOrigin * (objectWorldScale - 1.);\n v_objectUV += graphicOffset;\n v_objectUV /= u_scale;\n v_objectUV = graphicRotation * v_objectUV;\n\n\n // ===================================================\n\n\n // ===================================================\n // Sizing api for graphic objects with either givenBoxSize ratio or canvas ratio.\n // Full-screen mode available with u_worldWidth = u_worldHeight = 0\n\n v_responsiveBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n float responsiveRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;\n v_responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize, maxBoxSize).xy;\n vec2 responsiveBoxScale = u_resolution.xy / v_responsiveBoxSize;\n\n #ifdef ADD_HELPERS\n v_responsiveHelperBox = uv;\n v_responsiveHelperBox *= responsiveBoxScale;\n v_responsiveHelperBox += boxOrigin * (responsiveBoxScale - 1.);\n #endif\n\n v_responsiveUV = uv;\n v_responsiveUV *= responsiveBoxScale;\n v_responsiveUV += boxOrigin * (responsiveBoxScale - 1.);\n v_responsiveUV += graphicOffset;\n v_responsiveUV /= u_scale;\n v_responsiveUV.x *= responsiveRatio;\n v_responsiveUV = graphicRotation * v_responsiveUV;\n v_responsiveUV.x /= responsiveRatio;\n\n // ===================================================\n\n\n // ===================================================\n // Sizing api for patterns\n // (treating graphics as a image u_worldWidth x u_worldHeight size)\n\n float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;\n vec2 patternBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y;\n\n vec3 boxSizeData = getBoxSize(patternBoxRatio, patternBoxGivenSize, maxBoxSize);\n v_patternBoxSize = boxSizeData.xy;\n float patternBoxNoFitBoxWidth = boxSizeData.z;\n vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;\n\n #ifdef ADD_HELPERS\n v_patternHelperBox = uv;\n v_patternHelperBox *= patternBoxScale;\n v_patternHelperBox += boxOrigin * (patternBoxScale - 1.);\n #endif\n\n v_patternUV = uv;\n v_patternUV += graphicOffset / patternBoxScale;\n v_patternUV += boxOrigin;\n v_patternUV -= boxOrigin / patternBoxScale;\n v_patternUV *= u_resolution.xy;\n v_patternUV /= u_pixelRatio;\n if (u_fit > 0.) {\n v_patternUV *= (patternBoxNoFitBoxWidth / v_patternBoxSize.x);\n }\n v_patternUV /= u_scale;\n v_patternUV = graphicRotation * v_patternUV;\n v_patternUV += boxOrigin / patternBoxScale;\n v_patternUV -= boxOrigin;\n // x100 is a default multiplier between vertex and fragmant shaders\n // we use it to avoid UV presision issues\n v_patternUV *= .01;\n\n // ===================================================\n\n\n // ===================================================\n // Sizing api for images\n\n vec2 imageBoxSize;\n if (u_fit == 1.) { // contain\n imageBoxSize.x = min(maxBoxSize.x / u_imageAspectRatio, maxBoxSize.y) * u_imageAspectRatio;\n } else if (u_fit == 2.) { // cover\n imageBoxSize.x = max(maxBoxSize.x / u_imageAspectRatio, maxBoxSize.y) * u_imageAspectRatio;\n } else {\n imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);\n }\n imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;\n vec2 imageBoxScale = u_resolution.xy / imageBoxSize;\n\n #ifdef ADD_HELPERS\n vec2 imageHelperBox = uv;\n imageHelperBox *= imageBoxScale;\n imageHelperBox += boxOrigin * (imageBoxScale - 1.);\n #endif\n\n v_imageUV = uv;\n v_imageUV *= imageBoxScale;\n v_imageUV += boxOrigin * (imageBoxScale - 1.);\n v_imageUV += graphicOffset;\n v_imageUV /= u_scale;\n v_imageUV.x *= u_imageAspectRatio;\n v_imageUV = graphicRotation * v_imageUV;\n v_imageUV.x /= u_imageAspectRatio;\n\n v_imageUV += .5;\n v_imageUV.y = 1. - v_imageUV.y;\n\n // ===================================================\n\n}`;\n"],
|
|
5
|
+
"mappings": ";;;;;AAEO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|