@3driseai/3drise-core 1.0.10 → 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.
- package/dist/data/effectsDefaults.d.ts.map +1 -1
- package/dist/data/effectsDefaults.js +32 -8
- package/dist/shaders/ChladniGridMaterial.d.ts +77 -0
- package/dist/shaders/ChladniGridMaterial.d.ts.map +1 -0
- package/dist/shaders/ChladniGridMaterial.js +301 -0
- package/dist/shaders/FlowNetGridMaterial.d.ts +74 -0
- package/dist/shaders/FlowNetGridMaterial.d.ts.map +1 -0
- package/dist/shaders/FlowNetGridMaterial.js +269 -0
- package/dist/shaders/GirihGridMaterial.d.ts +77 -0
- package/dist/shaders/GirihGridMaterial.d.ts.map +1 -0
- package/dist/shaders/GirihGridMaterial.js +464 -0
- package/dist/shaders/GravWaveGridMaterial.d.ts +77 -0
- package/dist/shaders/GravWaveGridMaterial.d.ts.map +1 -0
- package/dist/shaders/GravWaveGridMaterial.js +479 -0
- package/dist/shaders/HyperbolicGridMaterial.d.ts +74 -0
- package/dist/shaders/HyperbolicGridMaterial.d.ts.map +1 -0
- package/dist/shaders/HyperbolicGridMaterial.js +298 -0
- package/dist/shaders/ReactionDiffusionGridMaterial.d.ts +80 -0
- package/dist/shaders/ReactionDiffusionGridMaterial.d.ts.map +1 -0
- package/dist/shaders/ReactionDiffusionGridMaterial.js +247 -0
- package/dist/shaders/WallpaperGridMaterial.d.ts +134 -0
- package/dist/shaders/WallpaperGridMaterial.d.ts.map +1 -0
- package/dist/shaders/WallpaperGridMaterial.js +433 -0
- package/dist/shaders/index.d.ts +7 -0
- package/dist/shaders/index.d.ts.map +1 -1
- package/dist/shaders/index.js +7 -0
- package/dist/types/gallery.d.ts +21 -0
- package/dist/types/gallery.d.ts.map +1 -1
- package/dist/types/generativeEffects.d.ts +270 -2
- package/dist/types/generativeEffects.d.ts.map +1 -1
- package/dist/types/mesh.d.ts +3 -0
- package/dist/types/mesh.d.ts.map +1 -1
- package/dist/utils/GalleryCreator.d.ts +4 -75
- package/dist/utils/GalleryCreator.d.ts.map +1 -1
- package/dist/utils/GalleryCreator.js +12 -461
- package/dist/utils/LayoutCreator.d.ts +125 -0
- package/dist/utils/LayoutCreator.d.ts.map +1 -0
- package/dist/utils/LayoutCreator.js +521 -0
- package/dist/utils/galleriesUtils.d.ts.map +1 -1
- package/dist/utils/galleriesUtils.js +3 -2
- package/dist/utils/handleTransformEffects.d.ts.map +1 -1
- package/dist/utils/handleTransformEffects.js +5 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { shaderMaterial } from '@react-three/drei';
|
|
3
|
+
import { extend } from '@react-three/fiber';
|
|
4
|
+
export const girihGridMaterialDefaults = {
|
|
5
|
+
u_time: 0,
|
|
6
|
+
u_cellSize: 4,
|
|
7
|
+
u_lineWidth: 1.2,
|
|
8
|
+
u_sectionSize: 3,
|
|
9
|
+
u_sectionWidth: 0.8,
|
|
10
|
+
u_lineColor: new THREE.Color('#f2c469'),
|
|
11
|
+
u_sectionColor: new THREE.Color('#3f6fc4'),
|
|
12
|
+
u_cellColor: new THREE.Color('#12616f'),
|
|
13
|
+
u_glowColor: new THREE.Color('#38c4c8'),
|
|
14
|
+
u_bgColor: new THREE.Color('#05070a'),
|
|
15
|
+
u_bgOpacity: 0,
|
|
16
|
+
u_lineMode: 2,
|
|
17
|
+
u_cellMode: 2,
|
|
18
|
+
u_animSpeed: 1,
|
|
19
|
+
u_animScale: 0.5,
|
|
20
|
+
u_animIntensity: 0.25,
|
|
21
|
+
u_fadeDistance: 25,
|
|
22
|
+
u_fadeStrength: 0.65,
|
|
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_tiling: 0,
|
|
28
|
+
u_contactAngle: 67.5,
|
|
29
|
+
u_strapWidth: 0.07,
|
|
30
|
+
u_angleDrift: 5,
|
|
31
|
+
};
|
|
32
|
+
const vertex = /* glsl */ `
|
|
33
|
+
|
|
34
|
+
uniform float u_time;
|
|
35
|
+
uniform float u_cellSize;
|
|
36
|
+
uniform float u_displace;
|
|
37
|
+
uniform float u_animSpeed;
|
|
38
|
+
uniform float u_animScale;
|
|
39
|
+
|
|
40
|
+
varying vec2 vGridPos;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const float PI = 3.14159265359;
|
|
44
|
+
const float TAU = 6.28318530718;
|
|
45
|
+
|
|
46
|
+
float hash21(vec2 p){
|
|
47
|
+
p = fract(p * vec2(123.34, 456.21));
|
|
48
|
+
p += dot(p, p + 45.32);
|
|
49
|
+
return fract(p.x * p.y);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
uniform float u_tiling;
|
|
54
|
+
uniform float u_contactAngle;
|
|
55
|
+
uniform float u_strapWidth;
|
|
56
|
+
uniform float u_angleDrift;
|
|
57
|
+
|
|
58
|
+
const float SQ3 = 1.7320508;
|
|
59
|
+
const float SQ3H = 0.8660254;
|
|
60
|
+
|
|
61
|
+
vec2 girihRot(vec2 v, float a){
|
|
62
|
+
float c = cos(a), s = sin(a);
|
|
63
|
+
return vec2(c * v.x - s * v.y, s * v.x + c * v.y);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
float girihSeg(vec2 p, vec2 a, vec2 b){
|
|
67
|
+
vec2 pa = p - a, ba = b - a;
|
|
68
|
+
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-9), 0.0, 1.0);
|
|
69
|
+
return length(pa - ba * h);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// nearest centre of the unit triangular lattice (neighbours at 0, 60, ... degrees)
|
|
73
|
+
vec2 girihHex(vec2 p){
|
|
74
|
+
vec2 s = vec2(1.0, SQ3);
|
|
75
|
+
vec4 hc = floor(vec4(p, p - vec2(0.5, SQ3H)) / s.xyxy) + 0.5;
|
|
76
|
+
vec2 a = p - hc.xy * s;
|
|
77
|
+
vec2 b = p - (hc.zw + 0.5) * s;
|
|
78
|
+
return dot(a, a) < dot(b, b) ? p - a : p - b;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Which polygon of the base tiling covers p, and the Hankin strands in it.
|
|
82
|
+
// dU, dL distance to the strand passing over / under at the edge midpoint
|
|
83
|
+
// inStar signed distance into the star interior (positive inside)
|
|
84
|
+
// dEdge distance to the polygon edge (the construction line)
|
|
85
|
+
// pc polygon centre, cellId lattice index of the cell it belongs to
|
|
86
|
+
// sAlong distance travelled along the strand from the edge midpoint
|
|
87
|
+
void girihPattern(vec2 p, float th, out float dU, out float dL, out float inStar,
|
|
88
|
+
out float dEdge, out vec2 pc, out vec2 cellId, out float sAlong){
|
|
89
|
+
float n = 8.0, apo = 0.5, rot = 0.0;
|
|
90
|
+
vec2 local = vec2(0.0);
|
|
91
|
+
if (u_tiling < 0.5){
|
|
92
|
+
// 4.8.8: octagons on the integers, 45-degree squares at the half integers
|
|
93
|
+
vec2 c = floor(p + 0.5);
|
|
94
|
+
vec2 d = p - c;
|
|
95
|
+
if ((abs(d.x) + abs(d.y)) * 0.70710678 <= 0.5){
|
|
96
|
+
pc = c; local = d; n = 8.0; apo = 0.5; rot = 0.0;
|
|
97
|
+
} else {
|
|
98
|
+
pc = floor(p) + 0.5; local = p - pc; n = 4.0; apo = 0.20710678; rot = PI * 0.25;
|
|
99
|
+
}
|
|
100
|
+
cellId = floor(pc);
|
|
101
|
+
} else if (u_tiling < 1.5){
|
|
102
|
+
// regular hexagons: the Voronoi cells of the triangular lattice
|
|
103
|
+
pc = girihHex(p); local = p - pc; n = 6.0; apo = 0.5; rot = 0.0;
|
|
104
|
+
float j = floor(pc.y / SQ3H + 0.5);
|
|
105
|
+
cellId = vec2(floor(pc.x - 0.5 * j + 0.5), j);
|
|
106
|
+
} else {
|
|
107
|
+
// 3.6.3.6: smaller hexagons on the same lattice, triangles in the gaps
|
|
108
|
+
vec2 hc = girihHex(p);
|
|
109
|
+
vec2 hl = p - hc;
|
|
110
|
+
float j = floor(hc.y / SQ3H + 0.5);
|
|
111
|
+
cellId = vec2(floor(hc.x - 0.5 * j + 0.5), j);
|
|
112
|
+
vec2 qh = girihRot(hl, -PI / 6.0);
|
|
113
|
+
float kh = floor(atan(qh.y, qh.x) / (PI / 3.0) + 0.5);
|
|
114
|
+
float inHex = girihRot(qh, -kh * PI / 3.0).x;
|
|
115
|
+
if (inHex <= SQ3 * 0.25){
|
|
116
|
+
pc = hc; local = hl; n = 6.0; apo = SQ3 * 0.25; rot = PI / 6.0;
|
|
117
|
+
} else {
|
|
118
|
+
// the triangle sits on the Voronoi vertex of the sector the point is in
|
|
119
|
+
float b = PI / 6.0 + floor(mod(atan(hl.y, hl.x), TAU) / (PI / 3.0)) * (PI / 3.0);
|
|
120
|
+
pc = hc + vec2(cos(b), sin(b)) / SQ3;
|
|
121
|
+
local = p - pc; n = 3.0; apo = SQ3 / 12.0; rot = b + PI;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// fold into the sector of the nearest edge: midpoint at (apo, 0)
|
|
126
|
+
float alpha = PI / n;
|
|
127
|
+
vec2 q = girihRot(local, -rot);
|
|
128
|
+
float k = floor(atan(q.y, q.x) / (2.0 * alpha) + 0.5);
|
|
129
|
+
q = girihRot(q, -k * 2.0 * alpha);
|
|
130
|
+
|
|
131
|
+
float t2 = clamp(th, radians(12.0), alpha + radians(78.0));
|
|
132
|
+
vec2 M = vec2(apo, 0.0);
|
|
133
|
+
vec2 dir = vec2(-sin(t2), cos(t2));
|
|
134
|
+
float s = apo * sin(alpha) / max(cos(t2 - alpha), 0.04);
|
|
135
|
+
vec2 P = M + s * dir;
|
|
136
|
+
dU = girihSeg(q, M, P);
|
|
137
|
+
dL = girihSeg(q, M, vec2(P.x, -P.y));
|
|
138
|
+
// the star interior is the centre side of the strand line
|
|
139
|
+
vec2 qa = vec2(q.x, abs(q.y));
|
|
140
|
+
inStar = -dir.y * (qa.x - apo) + dir.x * qa.y;
|
|
141
|
+
dEdge = apo - q.x;
|
|
142
|
+
sAlong = clamp(dot(qa - M, dir), 0.0, s);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
void main(){
|
|
147
|
+
vGridPos = position.xy;
|
|
148
|
+
vec3 pos = position;
|
|
149
|
+
if (u_displace > 0.0){
|
|
150
|
+
float cs = max(u_cellSize, 1e-4);
|
|
151
|
+
float t = u_time * u_animSpeed;
|
|
152
|
+
float th = radians(u_contactAngle + u_angleDrift * sin(t * 0.21));
|
|
153
|
+
float dU, dL, inStar, dEdge, sAlong;
|
|
154
|
+
vec2 pc, cellId;
|
|
155
|
+
girihPattern(position.xy / cs, th, dU, dL, inStar, dEdge, pc, cellId, sAlong);
|
|
156
|
+
// carved relief: the star interiors stand proud of the strapwork, with a
|
|
157
|
+
// transition wide enough for the mesh to resolve smoothly
|
|
158
|
+
float hw = max(u_strapWidth, 0.01) * 0.5;
|
|
159
|
+
float relief = smoothstep(-0.02, hw + 0.12, inStar);
|
|
160
|
+
float breath = 0.5 + 0.5 * sin(length(position.xy) / cs * u_animScale - t);
|
|
161
|
+
pos.z += u_displace * (0.6 * relief + 0.4 * breath);
|
|
162
|
+
}
|
|
163
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
const fragment = /* glsl */ `
|
|
167
|
+
|
|
168
|
+
precision highp float;
|
|
169
|
+
|
|
170
|
+
uniform float u_time;
|
|
171
|
+
uniform float u_cellSize;
|
|
172
|
+
uniform float u_lineWidth;
|
|
173
|
+
uniform float u_sectionSize;
|
|
174
|
+
uniform float u_sectionWidth;
|
|
175
|
+
uniform vec3 u_lineColor;
|
|
176
|
+
uniform vec3 u_sectionColor;
|
|
177
|
+
uniform vec3 u_cellColor;
|
|
178
|
+
uniform vec3 u_glowColor;
|
|
179
|
+
uniform vec3 u_bgColor;
|
|
180
|
+
uniform float u_bgOpacity;
|
|
181
|
+
uniform float u_lineMode;
|
|
182
|
+
uniform float u_cellMode;
|
|
183
|
+
uniform float u_animSpeed;
|
|
184
|
+
uniform float u_animScale;
|
|
185
|
+
uniform float u_animIntensity;
|
|
186
|
+
uniform float u_fadeDistance;
|
|
187
|
+
uniform float u_fadeStrength;
|
|
188
|
+
uniform vec2 u_focus;
|
|
189
|
+
uniform float u_reveal;
|
|
190
|
+
|
|
191
|
+
varying vec2 vGridPos;
|
|
192
|
+
|
|
193
|
+
float lineAt(float c, float width, float fp){
|
|
194
|
+
float d = abs(fract(c - 0.5) - 0.5);
|
|
195
|
+
return 1.0 - clamp(d / max(fp * max(width, 0.05), 1e-6), 0.0, 1.0);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
const float PI = 3.14159265359;
|
|
200
|
+
const float TAU = 6.28318530718;
|
|
201
|
+
|
|
202
|
+
float hash21(vec2 p){
|
|
203
|
+
p = fract(p * vec2(123.34, 456.21));
|
|
204
|
+
p += dot(p, p + 45.32);
|
|
205
|
+
return fract(p.x * p.y);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
uniform float u_tiling;
|
|
210
|
+
uniform float u_contactAngle;
|
|
211
|
+
uniform float u_strapWidth;
|
|
212
|
+
uniform float u_angleDrift;
|
|
213
|
+
|
|
214
|
+
const float SQ3 = 1.7320508;
|
|
215
|
+
const float SQ3H = 0.8660254;
|
|
216
|
+
|
|
217
|
+
vec2 girihRot(vec2 v, float a){
|
|
218
|
+
float c = cos(a), s = sin(a);
|
|
219
|
+
return vec2(c * v.x - s * v.y, s * v.x + c * v.y);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
float girihSeg(vec2 p, vec2 a, vec2 b){
|
|
223
|
+
vec2 pa = p - a, ba = b - a;
|
|
224
|
+
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-9), 0.0, 1.0);
|
|
225
|
+
return length(pa - ba * h);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// nearest centre of the unit triangular lattice (neighbours at 0, 60, ... degrees)
|
|
229
|
+
vec2 girihHex(vec2 p){
|
|
230
|
+
vec2 s = vec2(1.0, SQ3);
|
|
231
|
+
vec4 hc = floor(vec4(p, p - vec2(0.5, SQ3H)) / s.xyxy) + 0.5;
|
|
232
|
+
vec2 a = p - hc.xy * s;
|
|
233
|
+
vec2 b = p - (hc.zw + 0.5) * s;
|
|
234
|
+
return dot(a, a) < dot(b, b) ? p - a : p - b;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Which polygon of the base tiling covers p, and the Hankin strands in it.
|
|
238
|
+
// dU, dL distance to the strand passing over / under at the edge midpoint
|
|
239
|
+
// inStar signed distance into the star interior (positive inside)
|
|
240
|
+
// dEdge distance to the polygon edge (the construction line)
|
|
241
|
+
// pc polygon centre, cellId lattice index of the cell it belongs to
|
|
242
|
+
// sAlong distance travelled along the strand from the edge midpoint
|
|
243
|
+
void girihPattern(vec2 p, float th, out float dU, out float dL, out float inStar,
|
|
244
|
+
out float dEdge, out vec2 pc, out vec2 cellId, out float sAlong){
|
|
245
|
+
float n = 8.0, apo = 0.5, rot = 0.0;
|
|
246
|
+
vec2 local = vec2(0.0);
|
|
247
|
+
if (u_tiling < 0.5){
|
|
248
|
+
// 4.8.8: octagons on the integers, 45-degree squares at the half integers
|
|
249
|
+
vec2 c = floor(p + 0.5);
|
|
250
|
+
vec2 d = p - c;
|
|
251
|
+
if ((abs(d.x) + abs(d.y)) * 0.70710678 <= 0.5){
|
|
252
|
+
pc = c; local = d; n = 8.0; apo = 0.5; rot = 0.0;
|
|
253
|
+
} else {
|
|
254
|
+
pc = floor(p) + 0.5; local = p - pc; n = 4.0; apo = 0.20710678; rot = PI * 0.25;
|
|
255
|
+
}
|
|
256
|
+
cellId = floor(pc);
|
|
257
|
+
} else if (u_tiling < 1.5){
|
|
258
|
+
// regular hexagons: the Voronoi cells of the triangular lattice
|
|
259
|
+
pc = girihHex(p); local = p - pc; n = 6.0; apo = 0.5; rot = 0.0;
|
|
260
|
+
float j = floor(pc.y / SQ3H + 0.5);
|
|
261
|
+
cellId = vec2(floor(pc.x - 0.5 * j + 0.5), j);
|
|
262
|
+
} else {
|
|
263
|
+
// 3.6.3.6: smaller hexagons on the same lattice, triangles in the gaps
|
|
264
|
+
vec2 hc = girihHex(p);
|
|
265
|
+
vec2 hl = p - hc;
|
|
266
|
+
float j = floor(hc.y / SQ3H + 0.5);
|
|
267
|
+
cellId = vec2(floor(hc.x - 0.5 * j + 0.5), j);
|
|
268
|
+
vec2 qh = girihRot(hl, -PI / 6.0);
|
|
269
|
+
float kh = floor(atan(qh.y, qh.x) / (PI / 3.0) + 0.5);
|
|
270
|
+
float inHex = girihRot(qh, -kh * PI / 3.0).x;
|
|
271
|
+
if (inHex <= SQ3 * 0.25){
|
|
272
|
+
pc = hc; local = hl; n = 6.0; apo = SQ3 * 0.25; rot = PI / 6.0;
|
|
273
|
+
} else {
|
|
274
|
+
// the triangle sits on the Voronoi vertex of the sector the point is in
|
|
275
|
+
float b = PI / 6.0 + floor(mod(atan(hl.y, hl.x), TAU) / (PI / 3.0)) * (PI / 3.0);
|
|
276
|
+
pc = hc + vec2(cos(b), sin(b)) / SQ3;
|
|
277
|
+
local = p - pc; n = 3.0; apo = SQ3 / 12.0; rot = b + PI;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// fold into the sector of the nearest edge: midpoint at (apo, 0)
|
|
282
|
+
float alpha = PI / n;
|
|
283
|
+
vec2 q = girihRot(local, -rot);
|
|
284
|
+
float k = floor(atan(q.y, q.x) / (2.0 * alpha) + 0.5);
|
|
285
|
+
q = girihRot(q, -k * 2.0 * alpha);
|
|
286
|
+
|
|
287
|
+
float t2 = clamp(th, radians(12.0), alpha + radians(78.0));
|
|
288
|
+
vec2 M = vec2(apo, 0.0);
|
|
289
|
+
vec2 dir = vec2(-sin(t2), cos(t2));
|
|
290
|
+
float s = apo * sin(alpha) / max(cos(t2 - alpha), 0.04);
|
|
291
|
+
vec2 P = M + s * dir;
|
|
292
|
+
dU = girihSeg(q, M, P);
|
|
293
|
+
dL = girihSeg(q, M, vec2(P.x, -P.y));
|
|
294
|
+
// the star interior is the centre side of the strand line
|
|
295
|
+
vec2 qa = vec2(q.x, abs(q.y));
|
|
296
|
+
inStar = -dir.y * (qa.x - apo) + dir.x * qa.y;
|
|
297
|
+
dEdge = apo - q.x;
|
|
298
|
+
sAlong = clamp(dot(qa - M, dir), 0.0, s);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
void main(){
|
|
303
|
+
float cs = max(u_cellSize, 1e-4);
|
|
304
|
+
vec2 coord = vGridPos / cs;
|
|
305
|
+
vec2 focus = u_focus / cs;
|
|
306
|
+
float t = u_time * u_animSpeed;
|
|
307
|
+
vec2 fw = fwidth(coord);
|
|
308
|
+
float pix = length(fw) * 0.7071; // cell units per pixel
|
|
309
|
+
float pixMax = max(fw.x, fw.y);
|
|
310
|
+
|
|
311
|
+
// the contact angle drifts slowly, morphing the stars between patterns
|
|
312
|
+
float th = radians(u_contactAngle + u_angleDrift * sin(t * 0.21));
|
|
313
|
+
float dU, dL, inStar, dEdge, sAlong;
|
|
314
|
+
vec2 pc, cellId;
|
|
315
|
+
girihPattern(coord, th, dU, dL, inStar, dEdge, pc, cellId, sAlong);
|
|
316
|
+
|
|
317
|
+
// --- strapwork: a band with two thin edge lines, drawn in pixels -------
|
|
318
|
+
float hw = max(u_strapWidth, 0.01) * 0.5 / pix; // half band width, px
|
|
319
|
+
float ow = max(u_lineWidth, 0.1) * 0.9; // outline half width, px
|
|
320
|
+
float du = dU / pix;
|
|
321
|
+
float dl = dL / pix;
|
|
322
|
+
// interlace: the strand on the +y side of an edge midpoint passes over,
|
|
323
|
+
// so the other one is cut where it runs under the band
|
|
324
|
+
float gap = max(0.2 * hw, 1.0); // the over strand casts a clear gap
|
|
325
|
+
float under = smoothstep(hw + gap, hw + gap + 1.0, du);
|
|
326
|
+
float outU = 1.0 - smoothstep(ow - 0.5, ow + 0.5, abs(du - hw));
|
|
327
|
+
float outL = (1.0 - smoothstep(ow - 0.5, ow + 0.5, abs(dl - hw))) * under;
|
|
328
|
+
float fillU = 1.0 - smoothstep(hw - 0.5, hw + 0.5, du);
|
|
329
|
+
float fillL = (1.0 - smoothstep(hw - 0.5, hw + 0.5, dl)) * under;
|
|
330
|
+
float lines = max(max(outU, outL), max(fillU, fillL) * 0.36);
|
|
331
|
+
|
|
332
|
+
// --- the tiling underneath: faint construction lines ------------------
|
|
333
|
+
float accent = 0.0;
|
|
334
|
+
if (u_sectionWidth > 0.0){
|
|
335
|
+
float aw = u_sectionWidth * 0.5;
|
|
336
|
+
float con = 1.0 - smoothstep(aw - 0.5, aw + 0.5, dEdge / pix);
|
|
337
|
+
float band = 1.0;
|
|
338
|
+
if (u_sectionSize > 0.5){
|
|
339
|
+
float ss = floor(u_sectionSize + 0.5);
|
|
340
|
+
band = max(step(mod(cellId.x, ss), 0.5), step(mod(cellId.y, ss), 0.5));
|
|
341
|
+
}
|
|
342
|
+
accent = con * mix(0.3, 1.0, band);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// once a strand is finer than about 1.5 px the pattern can only alias,
|
|
346
|
+
// so its contrast falls away into the distance instead
|
|
347
|
+
float res = 1.0 - 0.85 * smoothstep(0.045, 0.14, pixMax);
|
|
348
|
+
lines *= res;
|
|
349
|
+
accent *= res;
|
|
350
|
+
|
|
351
|
+
// --- the tilework between the straps ----------------------------------
|
|
352
|
+
// The strands cut every polygon into the star interior and the kite-shaped
|
|
353
|
+
// regions around it; the two take different glazes, as they would in zellij.
|
|
354
|
+
float off = smoothstep(0.0, 1.5, min(du, dl) - hw);
|
|
355
|
+
float star = off * step(0.0, inStar);
|
|
356
|
+
float kite = off - star;
|
|
357
|
+
|
|
358
|
+
float cellH = hash21(pc * 3.7 + 0.21);
|
|
359
|
+
float edgeKeep = star * res;
|
|
360
|
+
float cellDist = length(coord - focus) * 3.0;
|
|
361
|
+
float flowCoord = sAlong * 20.0; // light runs out from every crossing
|
|
362
|
+
float scanCoord = (coord.x + coord.y) * 6.0;
|
|
363
|
+
float fadeR = length(vGridPos) / max(u_fadeDistance, 1e-4);
|
|
364
|
+
|
|
365
|
+
vec3 extraCol = (u_cellColor * star * 0.8 + u_sectionColor * kite * 0.3) * res;
|
|
366
|
+
float extraA = (star * 0.6 + kite * 0.3) * res;
|
|
367
|
+
float regionMask = 1.0;
|
|
368
|
+
|
|
369
|
+
// ---- line animation --------------------------------------------------
|
|
370
|
+
float lineAnim = 1.0;
|
|
371
|
+
if (u_lineMode > 0.5){
|
|
372
|
+
if (u_lineMode < 1.5){
|
|
373
|
+
lineAnim = 0.5 + 0.5 * sin(cellDist * u_animScale - t);
|
|
374
|
+
} else if (u_lineMode < 2.5){
|
|
375
|
+
lineAnim = 0.5 + 0.5 * sin(flowCoord * u_animScale - t);
|
|
376
|
+
} else if (u_lineMode < 3.5){
|
|
377
|
+
float s = fract(scanCoord * 0.05 * u_animScale - t * 0.15);
|
|
378
|
+
lineAnim = 0.25 + smoothstep(0.0, 0.15, s) * (1.0 - smoothstep(0.15, 0.35, s));
|
|
379
|
+
} else {
|
|
380
|
+
lineAnim = 0.5 + 0.5 * sin(t);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
lineAnim = mix(1.0, lineAnim, u_animIntensity);
|
|
384
|
+
|
|
385
|
+
// ---- cell fill -------------------------------------------------------
|
|
386
|
+
float cell = 0.0;
|
|
387
|
+
if (u_cellMode > 0.5){
|
|
388
|
+
if (u_cellMode < 1.5){
|
|
389
|
+
cell = 0.5 + 0.5 * sin(flowCoord * 0.5 * u_animScale - t);
|
|
390
|
+
} else if (u_cellMode < 2.5){
|
|
391
|
+
cell = 0.5 + 0.5 * sin(t * (0.6 + cellH) + cellH * TAU);
|
|
392
|
+
} else if (u_cellMode < 3.5){
|
|
393
|
+
cell = smoothstep(0.6, 1.0, sin(cellDist * u_animScale - t));
|
|
394
|
+
} else {
|
|
395
|
+
cell = step(0.5, cellH) * (0.5 + 0.5 * sin(t));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
cell *= u_animIntensity * edgeKeep;
|
|
399
|
+
|
|
400
|
+
float tone = step(0.55, cellH);
|
|
401
|
+
|
|
402
|
+
vec3 col = u_bgColor * u_bgOpacity;
|
|
403
|
+
float a = u_bgOpacity;
|
|
404
|
+
|
|
405
|
+
col += mix(u_cellColor, u_cellColor * 2.2, tone) * cell;
|
|
406
|
+
a = max(a, cell * 0.9);
|
|
407
|
+
float linesI = lines * lineAnim;
|
|
408
|
+
col += u_lineColor * linesI; a = max(a, linesI);
|
|
409
|
+
float accentI = accent * lineAnim;
|
|
410
|
+
col += u_sectionColor * accentI; a = max(a, accentI);
|
|
411
|
+
col += u_glowColor * (linesI * 0.2 + cell * 0.35) * u_animIntensity;
|
|
412
|
+
|
|
413
|
+
col = col * regionMask + extraCol;
|
|
414
|
+
a = max(a * regionMask, extraA);
|
|
415
|
+
|
|
416
|
+
float fade = 1.0 - smoothstep(1.0 - u_fadeStrength, 1.0, fadeR);
|
|
417
|
+
col *= fade;
|
|
418
|
+
a *= fade;
|
|
419
|
+
|
|
420
|
+
// ---- reveal ----------------------------------------------------------
|
|
421
|
+
// The build boundary sweeps outward from the focus point with a bright
|
|
422
|
+
// leading edge, so the grid reads as assembling itself.
|
|
423
|
+
if (u_reveal < 0.999){
|
|
424
|
+
float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
|
|
425
|
+
float edge = u_reveal * 1.1;
|
|
426
|
+
float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
|
|
427
|
+
float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
|
|
428
|
+
col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
|
|
429
|
+
a = max(a * mask, front * 0.10);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (a < 0.002) discard;
|
|
433
|
+
gl_FragColor = vec4(col, a);
|
|
434
|
+
}
|
|
435
|
+
`;
|
|
436
|
+
export const GirihGridMaterial = shaderMaterial({
|
|
437
|
+
u_time: girihGridMaterialDefaults.u_time,
|
|
438
|
+
u_cellSize: girihGridMaterialDefaults.u_cellSize,
|
|
439
|
+
u_lineWidth: girihGridMaterialDefaults.u_lineWidth,
|
|
440
|
+
u_sectionSize: girihGridMaterialDefaults.u_sectionSize,
|
|
441
|
+
u_sectionWidth: girihGridMaterialDefaults.u_sectionWidth,
|
|
442
|
+
u_lineColor: girihGridMaterialDefaults.u_lineColor.clone(),
|
|
443
|
+
u_sectionColor: girihGridMaterialDefaults.u_sectionColor.clone(),
|
|
444
|
+
u_cellColor: girihGridMaterialDefaults.u_cellColor.clone(),
|
|
445
|
+
u_glowColor: girihGridMaterialDefaults.u_glowColor.clone(),
|
|
446
|
+
u_bgColor: girihGridMaterialDefaults.u_bgColor.clone(),
|
|
447
|
+
u_bgOpacity: girihGridMaterialDefaults.u_bgOpacity,
|
|
448
|
+
u_lineMode: girihGridMaterialDefaults.u_lineMode,
|
|
449
|
+
u_cellMode: girihGridMaterialDefaults.u_cellMode,
|
|
450
|
+
u_animSpeed: girihGridMaterialDefaults.u_animSpeed,
|
|
451
|
+
u_animScale: girihGridMaterialDefaults.u_animScale,
|
|
452
|
+
u_animIntensity: girihGridMaterialDefaults.u_animIntensity,
|
|
453
|
+
u_fadeDistance: girihGridMaterialDefaults.u_fadeDistance,
|
|
454
|
+
u_fadeStrength: girihGridMaterialDefaults.u_fadeStrength,
|
|
455
|
+
u_focus: girihGridMaterialDefaults.u_focus.clone(),
|
|
456
|
+
u_mouse: girihGridMaterialDefaults.u_mouse.clone(),
|
|
457
|
+
u_displace: girihGridMaterialDefaults.u_displace,
|
|
458
|
+
u_reveal: girihGridMaterialDefaults.u_reveal,
|
|
459
|
+
u_tiling: girihGridMaterialDefaults.u_tiling,
|
|
460
|
+
u_contactAngle: girihGridMaterialDefaults.u_contactAngle,
|
|
461
|
+
u_strapWidth: girihGridMaterialDefaults.u_strapWidth,
|
|
462
|
+
u_angleDrift: girihGridMaterialDefaults.u_angleDrift,
|
|
463
|
+
}, vertex, fragment);
|
|
464
|
+
extend({ GirihGridMaterial });
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* A spacetime lattice around a binary black-hole inspiral. The Newtonian wells pinch the lines, and quadrupole waves, evaluated at the retarded time, spiral outward and chirp toward the merger before the remnant rings down.
|
|
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 GravWaveGridMaterialUniforms {
|
|
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
|
+
/** wave amplitude multiplier; 0 leaves only the static wells */
|
|
33
|
+
u_strain: number;
|
|
34
|
+
/** seconds per inspiral-merger-ringdown cycle (clamped to at least 4 in the shader) */
|
|
35
|
+
u_chirpTime: number;
|
|
36
|
+
/** wave speed c in cells per second; sets the wavelength and the retardation delay */
|
|
37
|
+
u_waveSpeed: number;
|
|
38
|
+
/** mass ratio q = m2/m1 in 0.1..1; sets the orbit offsets, well depths and wave strength */
|
|
39
|
+
u_massRatio: number;
|
|
40
|
+
}
|
|
41
|
+
declare module '@react-three/fiber' {
|
|
42
|
+
interface ThreeElements {
|
|
43
|
+
gravWaveGridMaterial: ThreeElements['shaderMaterial'] & Partial<GravWaveGridMaterialUniforms>;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export declare const gravWaveGridMaterialDefaults: GravWaveGridMaterialUniforms;
|
|
47
|
+
export declare const GravWaveGridMaterial: import("@react-three/fiber").ConstructorRepresentation<THREE.ShaderMaterial & {
|
|
48
|
+
u_time: number;
|
|
49
|
+
u_cellSize: number;
|
|
50
|
+
u_lineWidth: number;
|
|
51
|
+
u_sectionSize: number;
|
|
52
|
+
u_sectionWidth: number;
|
|
53
|
+
u_lineColor: THREE.Color;
|
|
54
|
+
u_sectionColor: THREE.Color;
|
|
55
|
+
u_cellColor: THREE.Color;
|
|
56
|
+
u_glowColor: THREE.Color;
|
|
57
|
+
u_bgColor: THREE.Color;
|
|
58
|
+
u_bgOpacity: number;
|
|
59
|
+
u_lineMode: number;
|
|
60
|
+
u_cellMode: number;
|
|
61
|
+
u_animSpeed: number;
|
|
62
|
+
u_animScale: number;
|
|
63
|
+
u_animIntensity: number;
|
|
64
|
+
u_fadeDistance: number;
|
|
65
|
+
u_fadeStrength: number;
|
|
66
|
+
u_focus: THREE.Vector2;
|
|
67
|
+
u_mouse: THREE.Vector2;
|
|
68
|
+
u_displace: number;
|
|
69
|
+
u_reveal: number;
|
|
70
|
+
u_strain: number;
|
|
71
|
+
u_chirpTime: number;
|
|
72
|
+
u_waveSpeed: number;
|
|
73
|
+
u_massRatio: number;
|
|
74
|
+
}> & {
|
|
75
|
+
key: string;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=GravWaveGridMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GravWaveGridMaterial.d.ts","sourceRoot":"","sources":["../../src/shaders/GravWaveGridMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B;;;;;GAKG;AACH,MAAM,WAAW,4BAA4B;IACzC,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,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,WAAW,EAAE,MAAM,CAAC;IACpB,sFAAsF;IACtF,WAAW,EAAE,MAAM,CAAC;IACpB,4FAA4F;IAC5F,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,OAAO,QAAQ,oBAAoB,CAAC;IAChC,UAAU,aAAa;QACnB,oBAAoB,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;KACjG;CACJ;AAED,eAAO,MAAM,4BAA4B,EAAE,4BA2B1C,CAAC;AAuaF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BhC,CAAC"}
|