@3driseai/3drise-core 1.0.9 → 1.0.11

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.
Files changed (52) hide show
  1. package/dist/data/effectsDefaults.d.ts.map +1 -1
  2. package/dist/data/effectsDefaults.js +32 -8
  3. package/dist/shaders/ChladniGridMaterial.d.ts +77 -0
  4. package/dist/shaders/ChladniGridMaterial.d.ts.map +1 -0
  5. package/dist/shaders/ChladniGridMaterial.js +301 -0
  6. package/dist/shaders/FlowNetGridMaterial.d.ts +74 -0
  7. package/dist/shaders/FlowNetGridMaterial.d.ts.map +1 -0
  8. package/dist/shaders/FlowNetGridMaterial.js +269 -0
  9. package/dist/shaders/GirihGridMaterial.d.ts +77 -0
  10. package/dist/shaders/GirihGridMaterial.d.ts.map +1 -0
  11. package/dist/shaders/GirihGridMaterial.js +464 -0
  12. package/dist/shaders/GravWaveGridMaterial.d.ts +77 -0
  13. package/dist/shaders/GravWaveGridMaterial.d.ts.map +1 -0
  14. package/dist/shaders/GravWaveGridMaterial.js +479 -0
  15. package/dist/shaders/HyperbolicGridMaterial.d.ts +74 -0
  16. package/dist/shaders/HyperbolicGridMaterial.d.ts.map +1 -0
  17. package/dist/shaders/HyperbolicGridMaterial.js +298 -0
  18. package/dist/shaders/ReactionDiffusionGridMaterial.d.ts +80 -0
  19. package/dist/shaders/ReactionDiffusionGridMaterial.d.ts.map +1 -0
  20. package/dist/shaders/ReactionDiffusionGridMaterial.js +247 -0
  21. package/dist/shaders/WallpaperGridMaterial.d.ts +134 -0
  22. package/dist/shaders/WallpaperGridMaterial.d.ts.map +1 -0
  23. package/dist/shaders/WallpaperGridMaterial.js +433 -0
  24. package/dist/shaders/index.d.ts +7 -0
  25. package/dist/shaders/index.d.ts.map +1 -1
  26. package/dist/shaders/index.js +7 -0
  27. package/dist/types/gallery.d.ts +21 -0
  28. package/dist/types/gallery.d.ts.map +1 -1
  29. package/dist/types/generativeEffects.d.ts +270 -2
  30. package/dist/types/generativeEffects.d.ts.map +1 -1
  31. package/dist/types/mesh.d.ts +3 -0
  32. package/dist/types/mesh.d.ts.map +1 -1
  33. package/dist/utils/GalleryCreator.d.ts +4 -75
  34. package/dist/utils/GalleryCreator.d.ts.map +1 -1
  35. package/dist/utils/GalleryCreator.js +12 -461
  36. package/dist/utils/LayoutCreator.d.ts +125 -0
  37. package/dist/utils/LayoutCreator.d.ts.map +1 -0
  38. package/dist/utils/LayoutCreator.js +521 -0
  39. package/dist/utils/galleriesUtils.d.ts.map +1 -1
  40. package/dist/utils/galleriesUtils.js +3 -2
  41. package/dist/utils/handleTransformEffects.d.ts.map +1 -1
  42. package/dist/utils/handleTransformEffects.js +5 -3
  43. package/dist/utils/index.d.ts +2 -0
  44. package/dist/utils/index.d.ts.map +1 -1
  45. package/dist/utils/index.js +2 -0
  46. package/dist/utils/modelCache.d.ts +78 -0
  47. package/dist/utils/modelCache.d.ts.map +1 -0
  48. package/dist/utils/modelCache.js +164 -0
  49. package/dist/utils/utils.d.ts +8 -0
  50. package/dist/utils/utils.d.ts.map +1 -1
  51. package/dist/utils/utils.js +17 -3
  52. package/package.json +1 -1
@@ -0,0 +1,298 @@
1
+ import * as THREE from 'three';
2
+ import { shaderMaterial } from '@react-three/drei';
3
+ import { extend } from '@react-three/fiber';
4
+ export const hyperbolicGridMaterialDefaults = {
5
+ u_time: 0,
6
+ u_cellSize: 22,
7
+ u_lineWidth: 1.4,
8
+ u_sectionSize: 3,
9
+ u_sectionWidth: 1,
10
+ u_lineColor: new THREE.Color('#c9a4ff'),
11
+ u_sectionColor: new THREE.Color('#ffd9f2'),
12
+ u_cellColor: new THREE.Color('#2a1446'),
13
+ u_glowColor: new THREE.Color('#b07cff'),
14
+ u_bgColor: new THREE.Color('#07030c'),
15
+ u_bgOpacity: 0,
16
+ u_lineMode: 1,
17
+ u_cellMode: 2,
18
+ u_animSpeed: 1,
19
+ u_animScale: 1.2,
20
+ u_animIntensity: 0.7,
21
+ u_fadeDistance: 25,
22
+ u_fadeStrength: 0.2,
23
+ u_focus: new THREE.Vector2(0, 0),
24
+ u_mouse: new THREE.Vector2(0, 0),
25
+ u_displace: 0,
26
+ u_reveal: 1.0,
27
+ u_sides: 7,
28
+ u_valence: 3,
29
+ u_drift: 0.5,
30
+ };
31
+ const vertex = /* glsl */ `
32
+
33
+ uniform float u_time;
34
+ uniform float u_cellSize;
35
+ uniform float u_displace;
36
+ uniform float u_animSpeed;
37
+ uniform float u_animScale;
38
+
39
+ varying vec2 vGridPos;
40
+
41
+
42
+ const float PI = 3.14159265359;
43
+ const float TAU = 6.28318530718;
44
+
45
+ float hash21(vec2 p){
46
+ p = fract(p * vec2(123.34, 456.21));
47
+ p += dot(p, p + 45.32);
48
+ return fract(p.x * p.y);
49
+ }
50
+
51
+
52
+ void main(){
53
+ vGridPos = position.xy;
54
+ vec3 pos = position;
55
+ if (u_displace > 0.0){
56
+ float t = u_time * u_animSpeed;
57
+ float d = length(position.xy) / max(u_cellSize, 1e-4);
58
+ pos.z += sin(d * 6.0 * u_animScale - t) * u_displace * smoothstep(1.0, 0.6, d);
59
+ }
60
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
61
+ }
62
+ `;
63
+ const fragment = /* glsl */ `
64
+
65
+ precision highp float;
66
+
67
+ uniform float u_time;
68
+ uniform float u_cellSize;
69
+ uniform float u_lineWidth;
70
+ uniform float u_sectionSize;
71
+ uniform float u_sectionWidth;
72
+ uniform vec3 u_lineColor;
73
+ uniform vec3 u_sectionColor;
74
+ uniform vec3 u_cellColor;
75
+ uniform vec3 u_glowColor;
76
+ uniform vec3 u_bgColor;
77
+ uniform float u_bgOpacity;
78
+ uniform float u_lineMode;
79
+ uniform float u_cellMode;
80
+ uniform float u_animSpeed;
81
+ uniform float u_animScale;
82
+ uniform float u_animIntensity;
83
+ uniform float u_fadeDistance;
84
+ uniform float u_fadeStrength;
85
+ uniform vec2 u_focus;
86
+ uniform float u_reveal;
87
+
88
+ varying vec2 vGridPos;
89
+
90
+ float lineAt(float c, float width, float fp){
91
+ float d = abs(fract(c - 0.5) - 0.5);
92
+ return 1.0 - clamp(d / max(fp * max(width, 0.05), 1e-6), 0.0, 1.0);
93
+ }
94
+
95
+
96
+ const float PI = 3.14159265359;
97
+ const float TAU = 6.28318530718;
98
+
99
+ float hash21(vec2 p){
100
+ p = fract(p * vec2(123.34, 456.21));
101
+ p += dot(p, p + 45.32);
102
+ return fract(p.x * p.y);
103
+ }
104
+
105
+
106
+ uniform float u_sides;
107
+ uniform float u_valence;
108
+ uniform float u_drift;
109
+
110
+ vec2 cmul(vec2 a, vec2 b){ return vec2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
111
+ vec2 cdiv(vec2 a, vec2 b){ return vec2(a.x * b.x + a.y * b.y, a.y * b.x - a.x * b.y) / max(dot(b, b), 1e-12); }
112
+ vec2 rot2(vec2 v, float an){ float c = cos(an), s = sin(an); return vec2(c * v.x - s * v.y, s * v.x + c * v.y); }
113
+
114
+ void main(){
115
+ float Rd = max(u_cellSize, 1e-3); // Poincare disk radius, world units
116
+ float t = u_time * u_animSpeed;
117
+ vec2 zw = vGridPos / Rd;
118
+ float rr = length(zw);
119
+ float pixD = length(fwidth(vGridPos)) * 0.7071 / Rd; // one pixel, in disk units
120
+ float inDisk = 1.0 - smoothstep(1.0 - pixD, 1.0, rr);
121
+
122
+ // {p,q}: regular p-gons, q of them around every vertex. The tiling is
123
+ // hyperbolic only when (p-2)(q-2) > 4, so q is raised until it is.
124
+ float p = floor(clamp(u_sides, 3.0, 12.0) + 0.5);
125
+ float q = floor(clamp(u_valence, 3.0, 12.0) + 0.5);
126
+ q = max(q, floor(4.0 / (p - 2.0)) + 3.0);
127
+
128
+ // Fundamental triangle: angle pi/p at the centre, pi/q at a polygon
129
+ // vertex, a right angle at an edge midpoint. Its third side is a geodesic,
130
+ // a circle orthogonal to the unit circle (d^2 = 1 + r^2) that meets the
131
+ // ray at angle pi/p at angle pi/q.
132
+ float al = PI / p;
133
+ float sa = sin(al), cb = cos(PI / q);
134
+ float rc = 1.0 / sqrt(max(cb * cb / (sa * sa) - 1.0, 1e-4));
135
+ vec2 C = vec2(rc * cb / sa, 0.0);
136
+
137
+ // A Mobius translation is a hyperbolic isometry: it glides the whole
138
+ // tiling through itself without distorting a single tile.
139
+ vec2 mob = u_focus / Rd * 0.9 + u_drift * 0.45 * vec2(cos(t * 0.11), sin(t * 0.07));
140
+ mob *= min(1.0, 0.92 / max(length(mob), 1e-6));
141
+ vec2 den = vec2(1.0, 0.0) - cmul(vec2(mob.x, -mob.y), zw);
142
+ vec2 z = rot2(cdiv(zw - mob, den), t * 0.02 * u_drift);
143
+ // |dz/dzw|, carried through every fold so widths can be measured in pixels
144
+ float scale = (1.0 - dot(mob, mob)) / max(dot(den, den), 1e-9);
145
+
146
+ // Fold into the central polygon: reflect into the fundamental sector, and
147
+ // whenever the point lies beyond the polygon's edge, invert it through
148
+ // that edge's circle, which steps one polygon closer to the centre.
149
+ float depth = 0.0;
150
+ float idAcc = 0.0;
151
+ for (int i = 0; i < 48; i++){
152
+ float k = floor(atan(z.y, z.x) / (2.0 * al) + 0.5);
153
+ z = rot2(z, -k * 2.0 * al);
154
+ float mir = step(z.y, 0.0);
155
+ z.y = abs(z.y);
156
+ vec2 v = z - C;
157
+ float l2 = dot(v, v);
158
+ if (l2 >= rc * rc) break;
159
+ z = C + v * (rc * rc / l2);
160
+ scale *= rc * rc / l2;
161
+ depth += 1.0;
162
+ // the fold choices made before each inversion name the polygon
163
+ idAcc = fract(idAcc * 1.6180339 + (k + p) * 0.0731 + mir * 0.3713);
164
+ }
165
+
166
+ float toPx = 1.0 / max(scale * pixD, 1e-9); // folded units -> pixels
167
+
168
+ // Widths are constant in hyperbolic length, so tiles thin out towards the
169
+ // rim exactly as the tiling does. Coverage fades once a line is sub-pixel.
170
+ float dEdge = (length(z - C) - rc) * toPx;
171
+ float wEdge = u_lineWidth * 0.0045 * toPx;
172
+ float hw = max(wEdge, 1.0) * 0.5;
173
+ float edgeLine = min(wEdge, 1.0) * (1.0 - smoothstep(hw, hw + 1.0, dEdge));
174
+
175
+ // the polygon's mirror axes: radii to its vertices and edge midpoints
176
+ float spoke = 0.0;
177
+ if (u_sectionWidth > 0.0){
178
+ float dSpoke = min(z.y, abs(dot(z, vec2(-sin(al), cos(al))))) * toPx;
179
+ float wSpoke = u_sectionWidth * 0.0025 * toPx;
180
+ float hs = max(wSpoke, 1.0) * 0.5;
181
+ spoke = min(wSpoke, 1.0) * (1.0 - smoothstep(hs, hs + 1.0, dSpoke));
182
+ }
183
+ // every Nth generation of polygons draws its edges as accents
184
+ float isSection = u_sectionSize > 0.0 ? step(mod(depth, max(floor(u_sectionSize + 0.5), 1.0)), 0.5) : 0.0;
185
+
186
+ float lines = edgeLine;
187
+ float accent = max(spoke * 0.5, edgeLine * isSection);
188
+
189
+ float cellH = hash21(vec2(idAcc * 91.7, depth + 0.5));
190
+ float cellDist = depth;
191
+ float flowCoord = depth + atan(zw.y, zw.x) * 0.95;
192
+ float scanCoord = rr * 40.0;
193
+ float edgeKeep = smoothstep(0.0, 3.0, dEdge - wEdge);
194
+ float fadeR = rr * Rd / max(u_fadeDistance, 1e-4);
195
+
196
+ // The boundary circle is infinitely far away; a thin rim and a faint
197
+ // glow mark where the plane ends.
198
+ float rim = 1.0 - smoothstep(0.0, pixD * 1.5, abs(rr - 1.0));
199
+ float halo = smoothstep(0.7, 1.0, rr) * inDisk * 0.06;
200
+ vec3 extraCol = u_sectionColor * rim * 0.9 + u_glowColor * halo;
201
+ float extraA = max(rim * 0.9, halo);
202
+ float regionMask = inDisk;
203
+
204
+ // ---- line animation --------------------------------------------------
205
+ float lineAnim = 1.0;
206
+ if (u_lineMode > 0.5){
207
+ if (u_lineMode < 1.5){
208
+ lineAnim = 0.5 + 0.5 * sin(cellDist * u_animScale - t);
209
+ } else if (u_lineMode < 2.5){
210
+ lineAnim = 0.5 + 0.5 * sin(flowCoord * u_animScale - t);
211
+ } else if (u_lineMode < 3.5){
212
+ float s = fract(scanCoord * 0.05 * u_animScale - t * 0.15);
213
+ lineAnim = 0.25 + smoothstep(0.0, 0.15, s) * (1.0 - smoothstep(0.15, 0.35, s));
214
+ } else {
215
+ lineAnim = 0.5 + 0.5 * sin(t);
216
+ }
217
+ }
218
+ lineAnim = mix(1.0, lineAnim, u_animIntensity);
219
+
220
+ // ---- cell fill -------------------------------------------------------
221
+ float cell = 0.0;
222
+ if (u_cellMode > 0.5){
223
+ if (u_cellMode < 1.5){
224
+ cell = 0.5 + 0.5 * sin(flowCoord * 0.5 * u_animScale - t);
225
+ } else if (u_cellMode < 2.5){
226
+ cell = 0.5 + 0.5 * sin(t * (0.6 + cellH) + cellH * TAU);
227
+ } else if (u_cellMode < 3.5){
228
+ cell = smoothstep(0.6, 1.0, sin(cellDist * u_animScale - t));
229
+ } else {
230
+ cell = step(0.5, cellH) * (0.5 + 0.5 * sin(t));
231
+ }
232
+ }
233
+ cell *= u_animIntensity * edgeKeep;
234
+
235
+ float tone = step(0.55, cellH);
236
+
237
+ vec3 col = u_bgColor * u_bgOpacity;
238
+ float a = u_bgOpacity;
239
+
240
+ col += mix(u_cellColor, u_cellColor * 2.2, tone) * cell;
241
+ a = max(a, cell * 0.9);
242
+ float linesI = lines * lineAnim;
243
+ col += u_lineColor * linesI; a = max(a, linesI);
244
+ float accentI = accent * lineAnim;
245
+ col += u_sectionColor * accentI; a = max(a, accentI);
246
+ col += u_glowColor * (linesI * 0.2 + cell * 0.35) * u_animIntensity;
247
+
248
+ col = col * regionMask + extraCol;
249
+ a = max(a * regionMask, extraA);
250
+
251
+ float fade = 1.0 - smoothstep(1.0 - u_fadeStrength, 1.0, fadeR);
252
+ col *= fade;
253
+ a *= fade;
254
+
255
+ // ---- reveal ----------------------------------------------------------
256
+ // The build boundary sweeps outward from the focus point with a bright
257
+ // leading edge, so the grid reads as assembling itself.
258
+ if (u_reveal < 0.999){
259
+ float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
260
+ float edge = u_reveal * 1.1;
261
+ float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
262
+ float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
263
+ col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
264
+ a = max(a * mask, front * 0.10);
265
+ }
266
+
267
+ if (a < 0.002) discard;
268
+ gl_FragColor = vec4(col, a);
269
+ }
270
+ `;
271
+ export const HyperbolicGridMaterial = shaderMaterial({
272
+ u_time: hyperbolicGridMaterialDefaults.u_time,
273
+ u_cellSize: hyperbolicGridMaterialDefaults.u_cellSize,
274
+ u_lineWidth: hyperbolicGridMaterialDefaults.u_lineWidth,
275
+ u_sectionSize: hyperbolicGridMaterialDefaults.u_sectionSize,
276
+ u_sectionWidth: hyperbolicGridMaterialDefaults.u_sectionWidth,
277
+ u_lineColor: hyperbolicGridMaterialDefaults.u_lineColor.clone(),
278
+ u_sectionColor: hyperbolicGridMaterialDefaults.u_sectionColor.clone(),
279
+ u_cellColor: hyperbolicGridMaterialDefaults.u_cellColor.clone(),
280
+ u_glowColor: hyperbolicGridMaterialDefaults.u_glowColor.clone(),
281
+ u_bgColor: hyperbolicGridMaterialDefaults.u_bgColor.clone(),
282
+ u_bgOpacity: hyperbolicGridMaterialDefaults.u_bgOpacity,
283
+ u_lineMode: hyperbolicGridMaterialDefaults.u_lineMode,
284
+ u_cellMode: hyperbolicGridMaterialDefaults.u_cellMode,
285
+ u_animSpeed: hyperbolicGridMaterialDefaults.u_animSpeed,
286
+ u_animScale: hyperbolicGridMaterialDefaults.u_animScale,
287
+ u_animIntensity: hyperbolicGridMaterialDefaults.u_animIntensity,
288
+ u_fadeDistance: hyperbolicGridMaterialDefaults.u_fadeDistance,
289
+ u_fadeStrength: hyperbolicGridMaterialDefaults.u_fadeStrength,
290
+ u_focus: hyperbolicGridMaterialDefaults.u_focus.clone(),
291
+ u_mouse: hyperbolicGridMaterialDefaults.u_mouse.clone(),
292
+ u_displace: hyperbolicGridMaterialDefaults.u_displace,
293
+ u_reveal: hyperbolicGridMaterialDefaults.u_reveal,
294
+ u_sides: hyperbolicGridMaterialDefaults.u_sides,
295
+ u_valence: hyperbolicGridMaterialDefaults.u_valence,
296
+ u_drift: hyperbolicGridMaterialDefaults.u_drift,
297
+ }, vertex, fragment);
298
+ extend({ HyperbolicGridMaterial });
@@ -0,0 +1,80 @@
1
+ import * as THREE from 'three';
2
+ /**
3
+ * A Gray-Scott reaction-diffusion field simulated on the GPU and sampled by the plane: coral, labyrinths and dividing spots grow, merge and keep evolving, wrapped seamlessly as a torus.
4
+ *
5
+ * Shares the grid vocabulary with the other shader-plane grids (lineMode /
6
+ * cellMode 0..4, fade, reveal, focus), so the same controller drives it.
7
+ */
8
+ export interface ReactionDiffusionGridMaterialUniforms {
9
+ u_time: number;
10
+ u_cellSize: number;
11
+ u_lineWidth: number;
12
+ u_sectionSize: number;
13
+ u_sectionWidth: number;
14
+ u_lineColor: THREE.Color;
15
+ u_sectionColor: THREE.Color;
16
+ u_cellColor: THREE.Color;
17
+ u_glowColor: THREE.Color;
18
+ u_bgColor: THREE.Color;
19
+ u_bgOpacity: number;
20
+ u_lineMode: number;
21
+ u_cellMode: number;
22
+ u_animSpeed: number;
23
+ u_animScale: number;
24
+ u_animIntensity: number;
25
+ u_fadeDistance: number;
26
+ u_fadeStrength: number;
27
+ u_focus: THREE.Vector2;
28
+ u_mouse: THREE.Vector2;
29
+ u_displace: number;
30
+ /** 0..1 assemble/dissolve. The build boundary sweeps outward from u_focus with a bright leading edge; 1 is fully built, 0 is gone. */
31
+ u_reveal: number;
32
+ /** Gray-Scott feed rate F. */
33
+ u_feed: number;
34
+ /** Gray-Scott kill rate k. */
35
+ u_kill: number;
36
+ /** Periodic spatial spread of F and k across the tile, so several morphologies coexist. */
37
+ u_variation: number;
38
+ /** Cells covered by one simulation tile before it repeats. */
39
+ u_tileCells: number;
40
+ /** Latest simulation state; r = u, g = v. Written by the simulation each frame. */
41
+ u_field: THREE.Texture | null;
42
+ }
43
+ declare module '@react-three/fiber' {
44
+ interface ThreeElements {
45
+ reactionDiffusionGridMaterial: ThreeElements['shaderMaterial'] & Partial<ReactionDiffusionGridMaterialUniforms>;
46
+ }
47
+ }
48
+ export declare const reactionDiffusionGridMaterialDefaults: ReactionDiffusionGridMaterialUniforms;
49
+ export declare const ReactionDiffusionGridMaterial: import("@react-three/fiber").ConstructorRepresentation<THREE.ShaderMaterial & {
50
+ u_time: number;
51
+ u_cellSize: number;
52
+ u_lineWidth: number;
53
+ u_sectionSize: number;
54
+ u_sectionWidth: number;
55
+ u_lineColor: THREE.Color;
56
+ u_sectionColor: THREE.Color;
57
+ u_cellColor: THREE.Color;
58
+ u_glowColor: THREE.Color;
59
+ u_bgColor: THREE.Color;
60
+ u_bgOpacity: number;
61
+ u_lineMode: number;
62
+ u_cellMode: number;
63
+ u_animSpeed: number;
64
+ u_animScale: number;
65
+ u_animIntensity: number;
66
+ u_fadeDistance: number;
67
+ u_fadeStrength: number;
68
+ u_focus: THREE.Vector2;
69
+ u_mouse: THREE.Vector2;
70
+ u_displace: number;
71
+ u_reveal: number;
72
+ u_feed: number;
73
+ u_kill: number;
74
+ u_variation: number;
75
+ u_tileCells: number;
76
+ u_field: THREE.Texture<unknown, THREE.TextureEventMap>;
77
+ }> & {
78
+ key: string;
79
+ };
80
+ //# sourceMappingURL=ReactionDiffusionGridMaterial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactionDiffusionGridMaterial.d.ts","sourceRoot":"","sources":["../../src/shaders/ReactionDiffusionGridMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B;;;;;GAKG;AACH,MAAM,WAAW,qCAAqC;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC;IACzB,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC;IAC5B,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC;IACzB,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC;IACzB,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;IACvB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,sIAAsI;IACtI,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,2FAA2F;IAC3F,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,mFAAmF;IACnF,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;CACjC;AAED,OAAO,QAAQ,oBAAoB,CAAC;IAChC,UAAU,aAAa;QACnB,6BAA6B,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC;KACnH;CACJ;AAED,eAAO,MAAM,qCAAqC,EAAE,qCA4BnD,CAAC;AA6LF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCzC,CAAC"}
@@ -0,0 +1,247 @@
1
+ import * as THREE from 'three';
2
+ import { shaderMaterial } from '@react-three/drei';
3
+ import { extend } from '@react-three/fiber';
4
+ export const reactionDiffusionGridMaterialDefaults = {
5
+ u_time: 0,
6
+ u_cellSize: 3,
7
+ u_lineWidth: 1.1,
8
+ u_sectionSize: 5,
9
+ u_sectionWidth: 1.2,
10
+ u_lineColor: new THREE.Color('#7ff0d4'),
11
+ u_sectionColor: new THREE.Color('#f0a26a'),
12
+ u_cellColor: new THREE.Color('#0d4b52'),
13
+ u_glowColor: new THREE.Color('#2fd9c8'),
14
+ u_bgColor: new THREE.Color('#03080a'),
15
+ u_bgOpacity: 0,
16
+ u_lineMode: 0,
17
+ u_cellMode: 0,
18
+ u_animSpeed: 1,
19
+ u_animScale: 0.5,
20
+ u_animIntensity: 0.6,
21
+ u_fadeDistance: 25,
22
+ u_fadeStrength: 0.7,
23
+ u_focus: new THREE.Vector2(0, 0),
24
+ u_mouse: new THREE.Vector2(0, 0),
25
+ u_displace: 0,
26
+ u_reveal: 1.0,
27
+ u_feed: 0.037,
28
+ u_kill: 0.06,
29
+ u_variation: 0.55,
30
+ u_tileCells: 7,
31
+ u_field: null,
32
+ };
33
+ const vertex = /* glsl */ `
34
+
35
+ uniform float u_time;
36
+ uniform float u_cellSize;
37
+ uniform float u_displace;
38
+ uniform float u_animSpeed;
39
+ uniform float u_animScale;
40
+
41
+ varying vec2 vGridPos;
42
+
43
+
44
+ const float PI = 3.14159265359;
45
+ const float TAU = 6.28318530718;
46
+
47
+ float hash21(vec2 p){
48
+ p = fract(p * vec2(123.34, 456.21));
49
+ p += dot(p, p + 45.32);
50
+ return fract(p.x * p.y);
51
+ }
52
+
53
+
54
+ uniform sampler2D u_field;
55
+ uniform float u_tileCells;
56
+
57
+ void main(){
58
+ vGridPos = position.xy;
59
+ vec3 pos = position;
60
+ if (u_displace > 0.0){
61
+ // the relief is the pattern: v stands proud of the substrate
62
+ vec2 uv = position.xy / max(u_cellSize, 1e-4) / max(u_tileCells, 1.0);
63
+ float v = texture2D(u_field, uv).g;
64
+ pos.z += smoothstep(0.08, 0.45, v) * u_displace;
65
+ }
66
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
67
+ }
68
+ `;
69
+ const fragment = /* glsl */ `
70
+
71
+ precision highp float;
72
+
73
+ uniform float u_time;
74
+ uniform float u_cellSize;
75
+ uniform float u_lineWidth;
76
+ uniform float u_sectionSize;
77
+ uniform float u_sectionWidth;
78
+ uniform vec3 u_lineColor;
79
+ uniform vec3 u_sectionColor;
80
+ uniform vec3 u_cellColor;
81
+ uniform vec3 u_glowColor;
82
+ uniform vec3 u_bgColor;
83
+ uniform float u_bgOpacity;
84
+ uniform float u_lineMode;
85
+ uniform float u_cellMode;
86
+ uniform float u_animSpeed;
87
+ uniform float u_animScale;
88
+ uniform float u_animIntensity;
89
+ uniform float u_fadeDistance;
90
+ uniform float u_fadeStrength;
91
+ uniform vec2 u_focus;
92
+ uniform float u_reveal;
93
+
94
+ varying vec2 vGridPos;
95
+
96
+ float lineAt(float c, float width, float fp){
97
+ float d = abs(fract(c - 0.5) - 0.5);
98
+ return 1.0 - clamp(d / max(fp * max(width, 0.05), 1e-6), 0.0, 1.0);
99
+ }
100
+
101
+
102
+ const float PI = 3.14159265359;
103
+ const float TAU = 6.28318530718;
104
+
105
+ float hash21(vec2 p){
106
+ p = fract(p * vec2(123.34, 456.21));
107
+ p += dot(p, p + 45.32);
108
+ return fract(p.x * p.y);
109
+ }
110
+
111
+
112
+ uniform sampler2D u_field;
113
+ uniform float u_tileCells;
114
+
115
+ void main(){
116
+ float cs = max(u_cellSize, 1e-4);
117
+ vec2 coord = vGridPos / cs;
118
+ vec2 focus = u_focus / cs;
119
+ float t = u_time * u_animSpeed;
120
+
121
+ vec2 uv = coord / max(u_tileCells, 1.0);
122
+ float v = texture2D(u_field, uv).g;
123
+ float fw = max(length(vec2(dFdx(v), dFdy(v))), 1e-5);
124
+
125
+ // the fronts: the contour where the autocatalyst takes over
126
+ float lines = 1.0 - clamp(abs(v - 0.25) / (fw * max(u_lineWidth, 0.05) * 1.6), 0.0, 1.0);
127
+ // dissolve the contour into its average coverage before it gets thinner than a pixel
128
+ lines = mix(lines, clamp(u_lineWidth * 0.5, 0.0, 1.0) * 0.5, smoothstep(0.08, 0.3, fw));
129
+
130
+ float accent = 0.0;
131
+ if (u_sectionWidth > 0.0 && u_sectionSize > 0.0){
132
+ // a second contour deeper inside each front, so the fronts read as ridges
133
+ float level = clamp(0.25 + 0.035 * u_sectionSize, 0.28, 0.62);
134
+ accent = 1.0 - clamp(abs(v - level) / (fw * max(u_sectionWidth, 0.05) * 1.6), 0.0, 1.0);
135
+ accent *= 1.0 - smoothstep(0.08, 0.3, fw);
136
+ }
137
+
138
+ float cellH = hash21(floor(coord) + 0.31);
139
+ float cellDist = length(coord - focus);
140
+ float flowCoord = (coord.x + coord.y) * 0.7071;
141
+ float scanCoord = coord.x + coord.y;
142
+ float edgeKeep = smoothstep(0.02, 0.14, abs(v - 0.25));
143
+ float fadeR = length(vGridPos) / max(u_fadeDistance, 1e-4);
144
+
145
+ // the pattern body itself, so it is visible whatever cellMode is set to
146
+ float body = smoothstep(0.06, 0.42, v);
147
+ vec3 extraCol = mix(u_cellColor, u_glowColor, smoothstep(0.18, 0.5, v)) * body * 1.1;
148
+ float extraA = body * 0.7;
149
+ float regionMask = 1.0;
150
+
151
+ // ---- line animation --------------------------------------------------
152
+ float lineAnim = 1.0;
153
+ if (u_lineMode > 0.5){
154
+ if (u_lineMode < 1.5){
155
+ lineAnim = 0.5 + 0.5 * sin(cellDist * u_animScale - t);
156
+ } else if (u_lineMode < 2.5){
157
+ lineAnim = 0.5 + 0.5 * sin(flowCoord * u_animScale - t);
158
+ } else if (u_lineMode < 3.5){
159
+ float s = fract(scanCoord * 0.05 * u_animScale - t * 0.15);
160
+ lineAnim = 0.25 + smoothstep(0.0, 0.15, s) * (1.0 - smoothstep(0.15, 0.35, s));
161
+ } else {
162
+ lineAnim = 0.5 + 0.5 * sin(t);
163
+ }
164
+ }
165
+ lineAnim = mix(1.0, lineAnim, u_animIntensity);
166
+
167
+ // ---- cell fill -------------------------------------------------------
168
+ float cell = 0.0;
169
+ if (u_cellMode > 0.5){
170
+ if (u_cellMode < 1.5){
171
+ cell = 0.5 + 0.5 * sin(flowCoord * 0.5 * u_animScale - t);
172
+ } else if (u_cellMode < 2.5){
173
+ cell = 0.5 + 0.5 * sin(t * (0.6 + cellH) + cellH * TAU);
174
+ } else if (u_cellMode < 3.5){
175
+ cell = smoothstep(0.6, 1.0, sin(cellDist * u_animScale - t));
176
+ } else {
177
+ cell = step(0.5, cellH) * (0.5 + 0.5 * sin(t));
178
+ }
179
+ }
180
+ cell *= u_animIntensity * edgeKeep;
181
+
182
+ float tone = step(0.55, cellH);
183
+
184
+ vec3 col = u_bgColor * u_bgOpacity;
185
+ float a = u_bgOpacity;
186
+
187
+ col += mix(u_cellColor, u_cellColor * 2.2, tone) * cell;
188
+ a = max(a, cell * 0.9);
189
+ float linesI = lines * lineAnim;
190
+ col += u_lineColor * linesI; a = max(a, linesI);
191
+ float accentI = accent * lineAnim;
192
+ col += u_sectionColor * accentI; a = max(a, accentI);
193
+ col += u_glowColor * (linesI * 0.2 + cell * 0.35) * u_animIntensity;
194
+
195
+ col = col * regionMask + extraCol;
196
+ a = max(a * regionMask, extraA);
197
+
198
+ float fade = 1.0 - smoothstep(1.0 - u_fadeStrength, 1.0, fadeR);
199
+ col *= fade;
200
+ a *= fade;
201
+
202
+ // ---- reveal ----------------------------------------------------------
203
+ // The build boundary sweeps outward from the focus point with a bright
204
+ // leading edge, so the grid reads as assembling itself.
205
+ if (u_reveal < 0.999){
206
+ float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
207
+ float edge = u_reveal * 1.1;
208
+ float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
209
+ float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
210
+ col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
211
+ a = max(a * mask, front * 0.10);
212
+ }
213
+
214
+ if (a < 0.002) discard;
215
+ gl_FragColor = vec4(col, a);
216
+ }
217
+ `;
218
+ export const ReactionDiffusionGridMaterial = shaderMaterial({
219
+ u_time: reactionDiffusionGridMaterialDefaults.u_time,
220
+ u_cellSize: reactionDiffusionGridMaterialDefaults.u_cellSize,
221
+ u_lineWidth: reactionDiffusionGridMaterialDefaults.u_lineWidth,
222
+ u_sectionSize: reactionDiffusionGridMaterialDefaults.u_sectionSize,
223
+ u_sectionWidth: reactionDiffusionGridMaterialDefaults.u_sectionWidth,
224
+ u_lineColor: reactionDiffusionGridMaterialDefaults.u_lineColor.clone(),
225
+ u_sectionColor: reactionDiffusionGridMaterialDefaults.u_sectionColor.clone(),
226
+ u_cellColor: reactionDiffusionGridMaterialDefaults.u_cellColor.clone(),
227
+ u_glowColor: reactionDiffusionGridMaterialDefaults.u_glowColor.clone(),
228
+ u_bgColor: reactionDiffusionGridMaterialDefaults.u_bgColor.clone(),
229
+ u_bgOpacity: reactionDiffusionGridMaterialDefaults.u_bgOpacity,
230
+ u_lineMode: reactionDiffusionGridMaterialDefaults.u_lineMode,
231
+ u_cellMode: reactionDiffusionGridMaterialDefaults.u_cellMode,
232
+ u_animSpeed: reactionDiffusionGridMaterialDefaults.u_animSpeed,
233
+ u_animScale: reactionDiffusionGridMaterialDefaults.u_animScale,
234
+ u_animIntensity: reactionDiffusionGridMaterialDefaults.u_animIntensity,
235
+ u_fadeDistance: reactionDiffusionGridMaterialDefaults.u_fadeDistance,
236
+ u_fadeStrength: reactionDiffusionGridMaterialDefaults.u_fadeStrength,
237
+ u_focus: reactionDiffusionGridMaterialDefaults.u_focus.clone(),
238
+ u_mouse: reactionDiffusionGridMaterialDefaults.u_mouse.clone(),
239
+ u_displace: reactionDiffusionGridMaterialDefaults.u_displace,
240
+ u_reveal: reactionDiffusionGridMaterialDefaults.u_reveal,
241
+ u_feed: reactionDiffusionGridMaterialDefaults.u_feed,
242
+ u_kill: reactionDiffusionGridMaterialDefaults.u_kill,
243
+ u_variation: reactionDiffusionGridMaterialDefaults.u_variation,
244
+ u_tileCells: reactionDiffusionGridMaterialDefaults.u_tileCells,
245
+ u_field: reactionDiffusionGridMaterialDefaults.u_field,
246
+ }, vertex, fragment);
247
+ extend({ ReactionDiffusionGridMaterial });