@matboks/utilities 0.0.1 → 0.0.2
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/constants 2.js +1 -0
- package/dist/constants 3.js +1 -0
- package/dist/constants.d 2.ts +1 -0
- package/dist/constants.d 3.ts +1 -0
- package/dist/index 2.js +11 -0
- package/dist/index 3.js +11 -0
- package/dist/index.d 2.ts +11 -0
- package/dist/index.d 3.ts +11 -0
- package/dist/shader-modules/modules/camera.js +42 -42
- package/dist/shader-modules/modules/color/blend.js +107 -107
- package/dist/shader-modules/modules/color/index.js +134 -134
- package/dist/shader-modules/modules/constants.js +13 -13
- package/dist/shader-modules/modules/geometry.js +109 -109
- package/dist/shader-modules/modules/math.js +18 -18
- package/dist/shader-modules/modules/noise.d.ts +1 -1
- package/dist/shader-modules/modules/noise.js +449 -409
- package/dist/shader-modules/modules/random.d.ts +1 -1
- package/dist/shader-modules/modules/random.js +172 -146
- package/dist/shader-modules/modules/ray-marching.js +53 -53
- package/dist/shader-modules/modules/sdf/index.js +182 -182
- package/dist/shader-modules/modules/sdf/operations.js +76 -76
- package/dist/shader-modules/modules/sdf.d.ts +1 -0
- package/dist/shader-modules/modules/sdf.js +126 -0
- package/dist/shader-modules/modules/utils.js +114 -114
- package/dist/shader-modules/shaders.js +107 -107
- package/dist/shader-renderer/pixel-vertex-shader.js +13 -13
- package/dist/tilings/tiler.d.ts +1 -0
- package/dist/tilings/tiler.js +4 -0
- package/dist/types 2.js +1 -0
- package/dist/types 3.js +1 -0
- package/dist/types.d 2.ts +1 -0
- package/dist/types.d 3.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const EPS = 1e-9;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const EPS = 1e-9;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const EPS = 1e-9;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const EPS = 1e-9;
|
package/dist/index 2.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./geometry/index.js";
|
|
2
|
+
export * from "./math/index.js";
|
|
3
|
+
export * from "./utilities/index.js";
|
|
4
|
+
export * from "./noise/index.js";
|
|
5
|
+
export * from "./constants.js";
|
|
6
|
+
export * from "./tilings/index.js";
|
|
7
|
+
export * from "./transformations/index.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./shader-renderer/index.js";
|
|
10
|
+
export * from "./shader-modules/index.js";
|
|
11
|
+
export * from "./constants.js";
|
package/dist/index 3.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./geometry/index.js";
|
|
2
|
+
export * from "./math/index.js";
|
|
3
|
+
export * from "./utilities/index.js";
|
|
4
|
+
export * from "./noise/index.js";
|
|
5
|
+
export * from "./constants.js";
|
|
6
|
+
export * from "./tilings/index.js";
|
|
7
|
+
export * from "./transforms/index.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./shader-renderer/index.js";
|
|
10
|
+
export * from "./shader-modules/index.js";
|
|
11
|
+
export * from "./constants.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./geometry/index.js";
|
|
2
|
+
export * from "./math/index.js";
|
|
3
|
+
export * from "./utilities/index.js";
|
|
4
|
+
export * from "./noise/index.js";
|
|
5
|
+
export * from "./constants.js";
|
|
6
|
+
export * from "./tilings/index.js";
|
|
7
|
+
export * from "./transformations/index.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./shader-renderer/index.js";
|
|
10
|
+
export * from "./shader-modules/index.js";
|
|
11
|
+
export * from "./constants.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./geometry/index.js";
|
|
2
|
+
export * from "./math/index.js";
|
|
3
|
+
export * from "./utilities/index.js";
|
|
4
|
+
export * from "./noise/index.js";
|
|
5
|
+
export * from "./constants.js";
|
|
6
|
+
export * from "./tilings/index.js";
|
|
7
|
+
export * from "./transforms/index.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./shader-renderer/index.js";
|
|
10
|
+
export * from "./shader-modules/index.js";
|
|
11
|
+
export * from "./constants.js";
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
export const cameraDefinition = /*glsl*/ `
|
|
2
|
-
|
|
3
|
-
import { create2DBasisVectors } from "@/geometry";
|
|
4
|
-
import { Ray } from "@/ray-marching";
|
|
5
|
-
export {
|
|
6
|
-
orthographicCamera,
|
|
7
|
-
perspectiveCamera
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
Ray orthographicCamera(vec2 uv, vec3 cameraPosition, vec3 lookAt, float viewport, float aspectRatio, float rotation) {
|
|
11
|
-
vec3 normal = normalize(lookAt - cameraPosition);
|
|
12
|
-
|
|
13
|
-
mat2x3 basis = create2DBasisVectors(normal, rotation);
|
|
14
|
-
|
|
15
|
-
// The basis forms a RHS system, but uv coordinates from NDC are left-handed.
|
|
16
|
-
// To make rendered image as expected, the j vector is flipped
|
|
17
|
-
basis[1] = -basis[1];
|
|
18
|
-
|
|
19
|
-
vec2 offset = (uv - 0.5) * viewport * vec2(max(aspectRatio, 1.0), max(1.0 / aspectRatio, 1.0));
|
|
20
|
-
|
|
21
|
-
vec3 origin = cameraPosition + basis*offset;
|
|
22
|
-
|
|
23
|
-
return Ray(origin, normal);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
Ray perspectiveCamera(vec2 uv, vec3 cameraPosition, vec3 lookAt, float fov, float aspectRatio, float rotation) {
|
|
27
|
-
vec3 normal = normalize(lookAt - cameraPosition);
|
|
28
|
-
|
|
29
|
-
mat2x3 basis = create2DBasisVectors(normal, rotation);
|
|
30
|
-
|
|
31
|
-
// The basis forms a RHS system, but uv coordinates from NDC are left-handed.
|
|
32
|
-
// To make rendered image as expected, the j vector is flipped
|
|
33
|
-
basis[1] = -basis[1];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
vec2 offset = 2.0 * (uv - 0.5) * tan(0.5*fov) * vec2(max(aspectRatio, 1.0), max(1.0 / aspectRatio, 1.0));
|
|
37
|
-
|
|
38
|
-
vec3 direction = normalize(normal + basis*offset);
|
|
39
|
-
|
|
40
|
-
return Ray(cameraPosition, direction);
|
|
41
|
-
}
|
|
42
|
-
|
|
1
|
+
export const cameraDefinition = /*glsl*/ `
|
|
2
|
+
|
|
3
|
+
import { create2DBasisVectors } from "@/geometry";
|
|
4
|
+
import { Ray } from "@/ray-marching";
|
|
5
|
+
export {
|
|
6
|
+
orthographicCamera,
|
|
7
|
+
perspectiveCamera
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
Ray orthographicCamera(vec2 uv, vec3 cameraPosition, vec3 lookAt, float viewport, float aspectRatio, float rotation) {
|
|
11
|
+
vec3 normal = normalize(lookAt - cameraPosition);
|
|
12
|
+
|
|
13
|
+
mat2x3 basis = create2DBasisVectors(normal, rotation);
|
|
14
|
+
|
|
15
|
+
// The basis forms a RHS system, but uv coordinates from NDC are left-handed.
|
|
16
|
+
// To make rendered image as expected, the j vector is flipped
|
|
17
|
+
basis[1] = -basis[1];
|
|
18
|
+
|
|
19
|
+
vec2 offset = (uv - 0.5) * viewport * vec2(max(aspectRatio, 1.0), max(1.0 / aspectRatio, 1.0));
|
|
20
|
+
|
|
21
|
+
vec3 origin = cameraPosition + basis*offset;
|
|
22
|
+
|
|
23
|
+
return Ray(origin, normal);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Ray perspectiveCamera(vec2 uv, vec3 cameraPosition, vec3 lookAt, float fov, float aspectRatio, float rotation) {
|
|
27
|
+
vec3 normal = normalize(lookAt - cameraPosition);
|
|
28
|
+
|
|
29
|
+
mat2x3 basis = create2DBasisVectors(normal, rotation);
|
|
30
|
+
|
|
31
|
+
// The basis forms a RHS system, but uv coordinates from NDC are left-handed.
|
|
32
|
+
// To make rendered image as expected, the j vector is flipped
|
|
33
|
+
basis[1] = -basis[1];
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
vec2 offset = 2.0 * (uv - 0.5) * tan(0.5*fov) * vec2(max(aspectRatio, 1.0), max(1.0 / aspectRatio, 1.0));
|
|
37
|
+
|
|
38
|
+
vec3 direction = normalize(normal + basis*offset);
|
|
39
|
+
|
|
40
|
+
return Ray(cameraPosition, direction);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
43
|
`;
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
export const blendDefinition = /*glsl*/ `
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
multiply, screen, overlay, hardLight, softLight, colorDodge, linearDodge, divide, colorBurn, linearBurn, vividLight, linearLight, subtract, difference, darken, lighten, blendById
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
vec3 multiply(vec3 a, vec3 b) {
|
|
8
|
-
return a*b;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
vec3 screen(vec3 a, vec3 b) {
|
|
12
|
-
return 1.0 - (1.0 - a)*(1.0 - b);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
vec3 overlay(vec3 a, vec3 b) {
|
|
16
|
-
return mix(2.0*a*b, 1.0 - 2.0*(1.0 - a)*(1.0 - b), step(0.5, a));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
vec3 hardLight(vec3 a, vec3 b) {
|
|
20
|
-
return mix(2.0*a*b, 1.0 - 2.0*(1.0 - a)*(1.0 - b), step(0.5, b));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
vec3 softLight(vec3 a, vec3 b) {
|
|
24
|
-
return (1.0 - 2.0*b)*a*a + 2.0*b*a;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
vec3 colorDodge(vec3 a, vec3 b) {
|
|
28
|
-
return min(a / (1.0 - b), 1.0);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
vec3 linearDodge(vec3 a, vec3 b) {
|
|
32
|
-
return min(a + b, 1.0);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
vec3 divide(vec3 a, vec3 b) {
|
|
36
|
-
return min(a / b, 1.0);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
vec3 colorBurn(vec3 a, vec3 b) {
|
|
40
|
-
return clamp(1.0 - (1.0 - a) / b, 0.0, 1.0);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
vec3 linearBurn(vec3 a, vec3 b) {
|
|
44
|
-
return clamp(a + b - 1.0, 0.0, 1.0);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
vec3 vividLight(vec3 a, vec3 b) {
|
|
48
|
-
return mix(colorBurn(a, b), colorDodge(a, b), step(0.5, b));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
vec3 linearLight(vec3 a, vec3 b) {
|
|
52
|
-
return clamp(a + 2.0*b - 1.0, 0.0, 1.0);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
vec3 subtract(vec3 a, vec3 b) {
|
|
56
|
-
return clamp(a - b, 0.0, 1.0);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
vec3 difference(vec3 a, vec3 b) {
|
|
60
|
-
return abs(b - a);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
vec3 darken(vec3 a, vec3 b) {
|
|
64
|
-
return min(a, b);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
vec3 lighten(vec3 a, vec3 b) {
|
|
68
|
-
return max(a, b);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
vec3 blendById(vec3 a, vec3 b, int id) {
|
|
72
|
-
id = max(0, min(id, 15));
|
|
73
|
-
if (id == 0) {
|
|
74
|
-
return multiply(a, b);
|
|
75
|
-
} else if (id == 1) {
|
|
76
|
-
return screen(a, b);
|
|
77
|
-
} else if (id == 2) {
|
|
78
|
-
return overlay(a, b);
|
|
79
|
-
} else if (id == 3) {
|
|
80
|
-
return hardLight(a, b);
|
|
81
|
-
} else if (id == 4) {
|
|
82
|
-
return softLight(a, b);
|
|
83
|
-
} else if (id == 5) {
|
|
84
|
-
return colorDodge(a, b);
|
|
85
|
-
} else if (id == 6) {
|
|
86
|
-
return linearDodge(a, b);
|
|
87
|
-
} else if (id == 7) {
|
|
88
|
-
return divide(a, b);
|
|
89
|
-
} else if (id == 8) {
|
|
90
|
-
return colorBurn(a, b);
|
|
91
|
-
} else if (id == 9) {
|
|
92
|
-
return linearBurn(a, b);
|
|
93
|
-
} else if (id == 10) {
|
|
94
|
-
return vividLight(a, b);
|
|
95
|
-
} else if (id == 11) {
|
|
96
|
-
return linearLight(a, b);
|
|
97
|
-
} else if (id == 12) {
|
|
98
|
-
return subtract(a, b);
|
|
99
|
-
} else if (id == 13) {
|
|
100
|
-
return difference(a, b);
|
|
101
|
-
} else if (id == 14) {
|
|
102
|
-
return darken(a, b);
|
|
103
|
-
} else if (id == 15) {
|
|
104
|
-
return lighten(a, b);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
1
|
+
export const blendDefinition = /*glsl*/ `
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
multiply, screen, overlay, hardLight, softLight, colorDodge, linearDodge, divide, colorBurn, linearBurn, vividLight, linearLight, subtract, difference, darken, lighten, blendById
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
vec3 multiply(vec3 a, vec3 b) {
|
|
8
|
+
return a*b;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
vec3 screen(vec3 a, vec3 b) {
|
|
12
|
+
return 1.0 - (1.0 - a)*(1.0 - b);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
vec3 overlay(vec3 a, vec3 b) {
|
|
16
|
+
return mix(2.0*a*b, 1.0 - 2.0*(1.0 - a)*(1.0 - b), step(0.5, a));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
vec3 hardLight(vec3 a, vec3 b) {
|
|
20
|
+
return mix(2.0*a*b, 1.0 - 2.0*(1.0 - a)*(1.0 - b), step(0.5, b));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
vec3 softLight(vec3 a, vec3 b) {
|
|
24
|
+
return (1.0 - 2.0*b)*a*a + 2.0*b*a;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
vec3 colorDodge(vec3 a, vec3 b) {
|
|
28
|
+
return min(a / (1.0 - b), 1.0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
vec3 linearDodge(vec3 a, vec3 b) {
|
|
32
|
+
return min(a + b, 1.0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
vec3 divide(vec3 a, vec3 b) {
|
|
36
|
+
return min(a / b, 1.0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
vec3 colorBurn(vec3 a, vec3 b) {
|
|
40
|
+
return clamp(1.0 - (1.0 - a) / b, 0.0, 1.0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
vec3 linearBurn(vec3 a, vec3 b) {
|
|
44
|
+
return clamp(a + b - 1.0, 0.0, 1.0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
vec3 vividLight(vec3 a, vec3 b) {
|
|
48
|
+
return mix(colorBurn(a, b), colorDodge(a, b), step(0.5, b));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
vec3 linearLight(vec3 a, vec3 b) {
|
|
52
|
+
return clamp(a + 2.0*b - 1.0, 0.0, 1.0);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
vec3 subtract(vec3 a, vec3 b) {
|
|
56
|
+
return clamp(a - b, 0.0, 1.0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
vec3 difference(vec3 a, vec3 b) {
|
|
60
|
+
return abs(b - a);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
vec3 darken(vec3 a, vec3 b) {
|
|
64
|
+
return min(a, b);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
vec3 lighten(vec3 a, vec3 b) {
|
|
68
|
+
return max(a, b);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
vec3 blendById(vec3 a, vec3 b, int id) {
|
|
72
|
+
id = max(0, min(id, 15));
|
|
73
|
+
if (id == 0) {
|
|
74
|
+
return multiply(a, b);
|
|
75
|
+
} else if (id == 1) {
|
|
76
|
+
return screen(a, b);
|
|
77
|
+
} else if (id == 2) {
|
|
78
|
+
return overlay(a, b);
|
|
79
|
+
} else if (id == 3) {
|
|
80
|
+
return hardLight(a, b);
|
|
81
|
+
} else if (id == 4) {
|
|
82
|
+
return softLight(a, b);
|
|
83
|
+
} else if (id == 5) {
|
|
84
|
+
return colorDodge(a, b);
|
|
85
|
+
} else if (id == 6) {
|
|
86
|
+
return linearDodge(a, b);
|
|
87
|
+
} else if (id == 7) {
|
|
88
|
+
return divide(a, b);
|
|
89
|
+
} else if (id == 8) {
|
|
90
|
+
return colorBurn(a, b);
|
|
91
|
+
} else if (id == 9) {
|
|
92
|
+
return linearBurn(a, b);
|
|
93
|
+
} else if (id == 10) {
|
|
94
|
+
return vividLight(a, b);
|
|
95
|
+
} else if (id == 11) {
|
|
96
|
+
return linearLight(a, b);
|
|
97
|
+
} else if (id == 12) {
|
|
98
|
+
return subtract(a, b);
|
|
99
|
+
} else if (id == 13) {
|
|
100
|
+
return difference(a, b);
|
|
101
|
+
} else if (id == 14) {
|
|
102
|
+
return darken(a, b);
|
|
103
|
+
} else if (id == 15) {
|
|
104
|
+
return lighten(a, b);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
108
|
`;
|
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
export const colorDefinition = /*glsl*/ `
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
hslToRgb, rgbToHsl, shiftRgbInHsl,
|
|
5
|
-
hsvToRgb, rgbToHsv
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
vec3 hslToRgb(vec3 hsl) {
|
|
9
|
-
float h = mod(hsl.r, 360.0);
|
|
10
|
-
float s = clamp(hsl.g, 0.0, 1.0);
|
|
11
|
-
float l = clamp(hsl.b, 0.0, 1.0);
|
|
12
|
-
|
|
13
|
-
float c = s*(1.0 - abs(2.0*l - 1.0));
|
|
14
|
-
float x = c*(1.0 - abs(mod(h / 60.0, 2.0) - 1.0));
|
|
15
|
-
float m = l - c / 2.0;
|
|
16
|
-
|
|
17
|
-
float r = 0.0;
|
|
18
|
-
float g = 0.0;
|
|
19
|
-
float b = 0.0;
|
|
20
|
-
|
|
21
|
-
if (h < 60.0) {
|
|
22
|
-
r = c;
|
|
23
|
-
g = x;
|
|
24
|
-
} else if (h < 120.0) {
|
|
25
|
-
r = x;
|
|
26
|
-
g = c;
|
|
27
|
-
} else if (h < 180.0) {
|
|
28
|
-
g = c;
|
|
29
|
-
b = x;
|
|
30
|
-
} else if (h < 240.0) {
|
|
31
|
-
g = x;
|
|
32
|
-
b = c;
|
|
33
|
-
} else if (h < 300.0) {
|
|
34
|
-
r = x;
|
|
35
|
-
b = c;
|
|
36
|
-
} else {
|
|
37
|
-
r = c;
|
|
38
|
-
b = x;
|
|
39
|
-
}
|
|
40
|
-
return vec3(r, g, b) + m;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
vec3 hslToRgb(float h, float s, float l) {
|
|
44
|
-
return hslToRgb(vec3(h, s, l));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
vec3 rgbToHsl(vec3 rgb) {
|
|
48
|
-
float r = rgb.r;
|
|
49
|
-
float g = rgb.g;
|
|
50
|
-
float b = rgb.b;
|
|
51
|
-
|
|
52
|
-
float cMax = max(r, max(g, b));
|
|
53
|
-
float cMin = min(r, min(g, b));
|
|
54
|
-
float delta = cMax - cMin;
|
|
55
|
-
|
|
56
|
-
float h;
|
|
57
|
-
|
|
58
|
-
if (delta == 0.0) {
|
|
59
|
-
h = 0.0;
|
|
60
|
-
} else if (r == cMax) {
|
|
61
|
-
h = mod((g - b)/delta, 6.0);
|
|
62
|
-
} else if (g == cMax) {
|
|
63
|
-
h = (b - r)/delta + 2.0;
|
|
64
|
-
} else if (b == cMax) {
|
|
65
|
-
h = (r - g)/delta + 4.0;
|
|
66
|
-
}
|
|
67
|
-
h *= 60.0;
|
|
68
|
-
h = mod(h, 360.0);
|
|
69
|
-
|
|
70
|
-
float l = (cMax + cMin)/2.0;
|
|
71
|
-
|
|
72
|
-
float s = 0.0;
|
|
73
|
-
if (delta > 0.0) {
|
|
74
|
-
s = delta/(1.0 - abs(2.0*l - 1.0));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return vec3(h, s, l);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
vec3 rgbToHsl(float r, float g, float b) {
|
|
81
|
-
return rgbToHsl(vec3(r, g, b));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
vec3 shiftRgbInHsl(vec3 rgb, vec3 shift) {
|
|
85
|
-
if (shift.z > 0.0) {
|
|
86
|
-
rgb = mix(rgb, vec3(1.0), shift.z);
|
|
87
|
-
} else {
|
|
88
|
-
rgb = mix(rgb, vec3(0.0), -shift.z);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
vec3 hsl = rgbToHsl(rgb);
|
|
92
|
-
|
|
93
|
-
hsl.x += shift.x;
|
|
94
|
-
|
|
95
|
-
float sShift = shift.y;
|
|
96
|
-
if (sShift > 0.0) {
|
|
97
|
-
hsl.y = (1.0 - sShift)*hsl.y + sShift;
|
|
98
|
-
} else {
|
|
99
|
-
hsl.y = (1.0 + sShift)*hsl.y;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
vec3 res = hslToRgb(hsl);
|
|
103
|
-
|
|
104
|
-
return res;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
vec3 rgbToHsv(vec3 c)
|
|
108
|
-
{
|
|
109
|
-
vec4 K = vec4(0.0, -1.0/3.0, 2.0/3.0, -1.0);
|
|
110
|
-
vec4 p = mix(vec4(c.bg, K.wz),
|
|
111
|
-
vec4(c.gb, K.xy),
|
|
112
|
-
step(c.b, c.g));
|
|
113
|
-
vec4 q = mix(vec4(p.xyw, c.r),
|
|
114
|
-
vec4(c.r, p.yzx),
|
|
115
|
-
step(p.x, c.r));
|
|
116
|
-
|
|
117
|
-
float d = q.x - min(q.w, q.y);
|
|
118
|
-
float e = 1.0e-10;
|
|
119
|
-
|
|
120
|
-
return vec3(
|
|
121
|
-
abs(q.z + (q.w - q.y) / (6.0 * d + e)),
|
|
122
|
-
d / (q.x + e),
|
|
123
|
-
q.x
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
vec3 hsv2Rgb(vec3 c)
|
|
128
|
-
{
|
|
129
|
-
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
|
|
130
|
-
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
131
|
-
|
|
132
|
-
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
133
|
-
}
|
|
134
|
-
|
|
1
|
+
export const colorDefinition = /*glsl*/ `
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
hslToRgb, rgbToHsl, shiftRgbInHsl,
|
|
5
|
+
hsvToRgb, rgbToHsv
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
vec3 hslToRgb(vec3 hsl) {
|
|
9
|
+
float h = mod(hsl.r, 360.0);
|
|
10
|
+
float s = clamp(hsl.g, 0.0, 1.0);
|
|
11
|
+
float l = clamp(hsl.b, 0.0, 1.0);
|
|
12
|
+
|
|
13
|
+
float c = s*(1.0 - abs(2.0*l - 1.0));
|
|
14
|
+
float x = c*(1.0 - abs(mod(h / 60.0, 2.0) - 1.0));
|
|
15
|
+
float m = l - c / 2.0;
|
|
16
|
+
|
|
17
|
+
float r = 0.0;
|
|
18
|
+
float g = 0.0;
|
|
19
|
+
float b = 0.0;
|
|
20
|
+
|
|
21
|
+
if (h < 60.0) {
|
|
22
|
+
r = c;
|
|
23
|
+
g = x;
|
|
24
|
+
} else if (h < 120.0) {
|
|
25
|
+
r = x;
|
|
26
|
+
g = c;
|
|
27
|
+
} else if (h < 180.0) {
|
|
28
|
+
g = c;
|
|
29
|
+
b = x;
|
|
30
|
+
} else if (h < 240.0) {
|
|
31
|
+
g = x;
|
|
32
|
+
b = c;
|
|
33
|
+
} else if (h < 300.0) {
|
|
34
|
+
r = x;
|
|
35
|
+
b = c;
|
|
36
|
+
} else {
|
|
37
|
+
r = c;
|
|
38
|
+
b = x;
|
|
39
|
+
}
|
|
40
|
+
return vec3(r, g, b) + m;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
vec3 hslToRgb(float h, float s, float l) {
|
|
44
|
+
return hslToRgb(vec3(h, s, l));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
vec3 rgbToHsl(vec3 rgb) {
|
|
48
|
+
float r = rgb.r;
|
|
49
|
+
float g = rgb.g;
|
|
50
|
+
float b = rgb.b;
|
|
51
|
+
|
|
52
|
+
float cMax = max(r, max(g, b));
|
|
53
|
+
float cMin = min(r, min(g, b));
|
|
54
|
+
float delta = cMax - cMin;
|
|
55
|
+
|
|
56
|
+
float h;
|
|
57
|
+
|
|
58
|
+
if (delta == 0.0) {
|
|
59
|
+
h = 0.0;
|
|
60
|
+
} else if (r == cMax) {
|
|
61
|
+
h = mod((g - b)/delta, 6.0);
|
|
62
|
+
} else if (g == cMax) {
|
|
63
|
+
h = (b - r)/delta + 2.0;
|
|
64
|
+
} else if (b == cMax) {
|
|
65
|
+
h = (r - g)/delta + 4.0;
|
|
66
|
+
}
|
|
67
|
+
h *= 60.0;
|
|
68
|
+
h = mod(h, 360.0);
|
|
69
|
+
|
|
70
|
+
float l = (cMax + cMin)/2.0;
|
|
71
|
+
|
|
72
|
+
float s = 0.0;
|
|
73
|
+
if (delta > 0.0) {
|
|
74
|
+
s = delta/(1.0 - abs(2.0*l - 1.0));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return vec3(h, s, l);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
vec3 rgbToHsl(float r, float g, float b) {
|
|
81
|
+
return rgbToHsl(vec3(r, g, b));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
vec3 shiftRgbInHsl(vec3 rgb, vec3 shift) {
|
|
85
|
+
if (shift.z > 0.0) {
|
|
86
|
+
rgb = mix(rgb, vec3(1.0), shift.z);
|
|
87
|
+
} else {
|
|
88
|
+
rgb = mix(rgb, vec3(0.0), -shift.z);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
vec3 hsl = rgbToHsl(rgb);
|
|
92
|
+
|
|
93
|
+
hsl.x += shift.x;
|
|
94
|
+
|
|
95
|
+
float sShift = shift.y;
|
|
96
|
+
if (sShift > 0.0) {
|
|
97
|
+
hsl.y = (1.0 - sShift)*hsl.y + sShift;
|
|
98
|
+
} else {
|
|
99
|
+
hsl.y = (1.0 + sShift)*hsl.y;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
vec3 res = hslToRgb(hsl);
|
|
103
|
+
|
|
104
|
+
return res;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
vec3 rgbToHsv(vec3 c)
|
|
108
|
+
{
|
|
109
|
+
vec4 K = vec4(0.0, -1.0/3.0, 2.0/3.0, -1.0);
|
|
110
|
+
vec4 p = mix(vec4(c.bg, K.wz),
|
|
111
|
+
vec4(c.gb, K.xy),
|
|
112
|
+
step(c.b, c.g));
|
|
113
|
+
vec4 q = mix(vec4(p.xyw, c.r),
|
|
114
|
+
vec4(c.r, p.yzx),
|
|
115
|
+
step(p.x, c.r));
|
|
116
|
+
|
|
117
|
+
float d = q.x - min(q.w, q.y);
|
|
118
|
+
float e = 1.0e-10;
|
|
119
|
+
|
|
120
|
+
return vec3(
|
|
121
|
+
abs(q.z + (q.w - q.y) / (6.0 * d + e)),
|
|
122
|
+
d / (q.x + e),
|
|
123
|
+
q.x
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
vec3 hsv2Rgb(vec3 c)
|
|
128
|
+
{
|
|
129
|
+
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
|
|
130
|
+
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
131
|
+
|
|
132
|
+
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
135
|
`;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export const constantsDefinition = /*glsl*/ `
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
PI, TWO_PI, SQRT_2, INV_SQRT_2, EPS
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const float PI = 3.14159265;
|
|
8
|
-
const float TWO_PI = 2.*PI;
|
|
9
|
-
const float SQRT_2 = sqrt(2.0);
|
|
10
|
-
const float INV_SQRT_2 = 0.5*SQRT_2;
|
|
11
|
-
const float EPS = 1e-9;
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
export const constantsDefinition = /*glsl*/ `
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
PI, TWO_PI, SQRT_2, INV_SQRT_2, EPS
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const float PI = 3.14159265;
|
|
8
|
+
const float TWO_PI = 2.*PI;
|
|
9
|
+
const float SQRT_2 = sqrt(2.0);
|
|
10
|
+
const float INV_SQRT_2 = 0.5*SQRT_2;
|
|
11
|
+
const float EPS = 1e-9;
|
|
12
|
+
|
|
13
|
+
|
|
14
14
|
`;
|