@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,479 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { shaderMaterial } from '@react-three/drei';
|
|
3
|
+
import { extend } from '@react-three/fiber';
|
|
4
|
+
export const gravWaveGridMaterialDefaults = {
|
|
5
|
+
u_time: 0,
|
|
6
|
+
u_cellSize: 1,
|
|
7
|
+
u_lineWidth: 1,
|
|
8
|
+
u_sectionSize: 5,
|
|
9
|
+
u_sectionWidth: 1.4,
|
|
10
|
+
u_lineColor: new THREE.Color('#3d6fc9'),
|
|
11
|
+
u_sectionColor: new THREE.Color('#9cc2ff'),
|
|
12
|
+
u_cellColor: new THREE.Color('#1b3a7a'),
|
|
13
|
+
u_glowColor: new THREE.Color('#8fd8ff'),
|
|
14
|
+
u_bgColor: new THREE.Color('#03050b'),
|
|
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.7,
|
|
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_strain: 1,
|
|
28
|
+
u_chirpTime: 14,
|
|
29
|
+
u_waveSpeed: 6.5,
|
|
30
|
+
u_massRatio: 0.6,
|
|
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
|
+
uniform vec2 u_focus;
|
|
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 float u_strain;
|
|
55
|
+
uniform float u_chirpTime;
|
|
56
|
+
uniform float u_waveSpeed;
|
|
57
|
+
uniform float u_massRatio;
|
|
58
|
+
|
|
59
|
+
const float GW_A0 = 3.2; // separation when a cycle starts, cells
|
|
60
|
+
const float GW_R = 0.0256; // tau at merger / tau at start = (a_merge / a0)^4, a_merge = 0.4 a0
|
|
61
|
+
const float GW_W0 = 1.3; // orbital angular frequency at the start, rad/s
|
|
62
|
+
const float GW_QNM = 1.3; // ringdown frequency / orbital frequency at merger
|
|
63
|
+
const float GW_TD = 0.4; // ringdown e-folding time, s
|
|
64
|
+
const float GW_H0 = 0.24; // strain at the source at the start (strain knob = 1)
|
|
65
|
+
const float GW_RF = 10.0; // softening of the 1/r fall-off, cells
|
|
66
|
+
const float GW_G = 0.45; // well strength (G M), cells^3; folds only past ~5 eps^3
|
|
67
|
+
const float GW_EPS = 0.6; // well softening, cells
|
|
68
|
+
|
|
69
|
+
float gwCycle(){ return max(u_chirpTime, 4.0); }
|
|
70
|
+
|
|
71
|
+
// State of the binary s seconds into a cycle: orbital phase, orbital
|
|
72
|
+
// angular frequency, separation, wave envelope (~ omega^(2/3)), and how
|
|
73
|
+
// present the new binary is (it fades in while the old remnant fades out).
|
|
74
|
+
void gwState(float s, out float phi, out float w, out float a, out float env, out float live){
|
|
75
|
+
float T = gwCycle();
|
|
76
|
+
float Ti = 0.7 * T; // inspiral; merger at Ti
|
|
77
|
+
float ts = Ti / (1.0 - GW_R); // tau when the cycle starts
|
|
78
|
+
float fadeIn = smoothstep(0.0, 0.12 * T, s);
|
|
79
|
+
if (s < Ti){
|
|
80
|
+
float u = (ts - s) / ts; // tau / tau_start, 1 -> GW_R
|
|
81
|
+
a = GW_A0 * pow(u, 0.25);
|
|
82
|
+
w = GW_W0 * pow(u, -0.375);
|
|
83
|
+
phi = 1.6 * GW_W0 * ts * (1.0 - pow(u, 0.625));
|
|
84
|
+
env = pow(u, -0.25) * fadeIn;
|
|
85
|
+
live = fadeIn;
|
|
86
|
+
} else {
|
|
87
|
+
// ringdown: the remnant's quadrupole mode, frequency easing up to the
|
|
88
|
+
// quasi-normal value and decaying exponentially
|
|
89
|
+
float x = s - Ti;
|
|
90
|
+
float wm = GW_W0 * pow(GW_R, -0.375);
|
|
91
|
+
float wq = wm * GW_QNM;
|
|
92
|
+
float e = 1.0 - exp(-x / 0.15);
|
|
93
|
+
phi = 1.6 * GW_W0 * ts * (1.0 - pow(GW_R, 0.625)) + wq * x - (wq - wm) * 0.15 * e;
|
|
94
|
+
w = mix(wm, wq, e);
|
|
95
|
+
a = GW_A0 * pow(GW_R, 0.25) * exp(-x / 0.12);
|
|
96
|
+
env = pow(GW_R, -0.25) * exp(-x / GW_TD) * (1.0 - smoothstep(0.9 * T, T, s));
|
|
97
|
+
live = 1.0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void gwMasses(out float m1, out float m2){
|
|
102
|
+
float q = clamp(u_massRatio, 0.1, 1.0);
|
|
103
|
+
m1 = 1.0 / (1.0 + q);
|
|
104
|
+
m2 = q / (1.0 + q);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Outgoing wave at x (cells from the binary) and time t.
|
|
108
|
+
// Returns the displacement in xy, the signed strain in z, and the
|
|
109
|
+
// brightness of the two spiral arms (the crests of h+) in w.
|
|
110
|
+
vec4 gwWave(vec2 x, float t, float pix){
|
|
111
|
+
float T = gwCycle();
|
|
112
|
+
float c = max(u_waveSpeed, 0.5);
|
|
113
|
+
float r = length(x);
|
|
114
|
+
float phi, w, a, env, live;
|
|
115
|
+
gwState(mod(t - r / c, T), phi, w, a, env, live);
|
|
116
|
+
float m1, m2;
|
|
117
|
+
gwMasses(m1, m2);
|
|
118
|
+
float k = 2.0 * w / c;
|
|
119
|
+
float h = u_strain * GW_H0 * 4.0 * m1 * m2 * env * GW_RF / (r + GW_RF);
|
|
120
|
+
h *= smoothstep(0.4, 2.2, r); // no wave inside the near zone
|
|
121
|
+
h /= sqrt(1.0 + h * h / 0.42); // soft limit keeps the lattice from folding
|
|
122
|
+
// a wavelength shorter than a few pixels would only alias: let it go
|
|
123
|
+
h *= smoothstep(3.0, 8.0, (TAU / k) / max(pix, 1e-5));
|
|
124
|
+
vec2 rh = x / max(r, 1e-4);
|
|
125
|
+
float psi = 2.0 * (phi - atan(x.y, x.x));
|
|
126
|
+
float cp = cos(psi);
|
|
127
|
+
vec2 D = (h / k) * (cp * rh + sin(psi) * vec2(-rh.y, rh.x));
|
|
128
|
+
// the crests of h+ drawn as light: the two trailing arms of the
|
|
129
|
+
// quadrupole emission pattern, kept legible far from the source
|
|
130
|
+
float amp = clamp(u_strain, 0.0, 2.0) * 4.0 * m1 * m2 * env
|
|
131
|
+
* pow(GW_RF / (r + GW_RF), 0.75) * smoothstep(0.4, 2.2, r);
|
|
132
|
+
float cpp = max(cp, 0.0);
|
|
133
|
+
cpp *= cpp; // a narrow ridge along each crest
|
|
134
|
+
return vec4(D, h * sin(psi), amp * cpp * cpp * cpp);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// pull of a softened point mass: grad of m / sqrt(r^2 + eps^2)
|
|
138
|
+
vec2 gwPull(vec2 x, vec2 p, float m){
|
|
139
|
+
vec2 d = x - p;
|
|
140
|
+
float q = dot(d, d) + GW_EPS * GW_EPS;
|
|
141
|
+
return d * (GW_G * m / (q * sqrt(q)));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
float gwWell(vec2 x, vec2 p, float m){
|
|
146
|
+
return m * 1.2 / sqrt(dot(x - p, x - p) + 1.44);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
void main(){
|
|
150
|
+
vGridPos = position.xy;
|
|
151
|
+
vec3 pos = position;
|
|
152
|
+
if (u_displace > 0.0){
|
|
153
|
+
float cs = max(u_cellSize, 1e-4);
|
|
154
|
+
float t = u_time * u_animSpeed;
|
|
155
|
+
vec2 x = (position.xy - u_focus) / cs;
|
|
156
|
+
float phi, w, a, env, live;
|
|
157
|
+
gwState(mod(t, gwCycle()), phi, w, a, env, live);
|
|
158
|
+
float m1, m2;
|
|
159
|
+
gwMasses(m1, m2);
|
|
160
|
+
vec2 e = vec2(cos(phi), sin(phi)) * a;
|
|
161
|
+
// the wells sink the sheet (rubber-sheet picture of the potential)
|
|
162
|
+
float depth = live * (gwWell(x, -e * m2, m1) + gwWell(x, e * m1, m2))
|
|
163
|
+
+ (1.0 - live) * gwWell(x, vec2(0.0), 1.0);
|
|
164
|
+
vec4 wave = gwWave(x, t, 0.02);
|
|
165
|
+
pos.z += u_displace * (-depth + wave.z * 0.6);
|
|
166
|
+
}
|
|
167
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
|
|
168
|
+
}
|
|
169
|
+
`;
|
|
170
|
+
const fragment = /* glsl */ `
|
|
171
|
+
|
|
172
|
+
precision highp float;
|
|
173
|
+
|
|
174
|
+
uniform float u_time;
|
|
175
|
+
uniform float u_cellSize;
|
|
176
|
+
uniform float u_lineWidth;
|
|
177
|
+
uniform float u_sectionSize;
|
|
178
|
+
uniform float u_sectionWidth;
|
|
179
|
+
uniform vec3 u_lineColor;
|
|
180
|
+
uniform vec3 u_sectionColor;
|
|
181
|
+
uniform vec3 u_cellColor;
|
|
182
|
+
uniform vec3 u_glowColor;
|
|
183
|
+
uniform vec3 u_bgColor;
|
|
184
|
+
uniform float u_bgOpacity;
|
|
185
|
+
uniform float u_lineMode;
|
|
186
|
+
uniform float u_cellMode;
|
|
187
|
+
uniform float u_animSpeed;
|
|
188
|
+
uniform float u_animScale;
|
|
189
|
+
uniform float u_animIntensity;
|
|
190
|
+
uniform float u_fadeDistance;
|
|
191
|
+
uniform float u_fadeStrength;
|
|
192
|
+
uniform vec2 u_focus;
|
|
193
|
+
uniform float u_reveal;
|
|
194
|
+
|
|
195
|
+
varying vec2 vGridPos;
|
|
196
|
+
|
|
197
|
+
float lineAt(float c, float width, float fp){
|
|
198
|
+
float d = abs(fract(c - 0.5) - 0.5);
|
|
199
|
+
return 1.0 - clamp(d / max(fp * max(width, 0.05), 1e-6), 0.0, 1.0);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
const float PI = 3.14159265359;
|
|
204
|
+
const float TAU = 6.28318530718;
|
|
205
|
+
|
|
206
|
+
float hash21(vec2 p){
|
|
207
|
+
p = fract(p * vec2(123.34, 456.21));
|
|
208
|
+
p += dot(p, p + 45.32);
|
|
209
|
+
return fract(p.x * p.y);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
uniform float u_strain;
|
|
214
|
+
uniform float u_chirpTime;
|
|
215
|
+
uniform float u_waveSpeed;
|
|
216
|
+
uniform float u_massRatio;
|
|
217
|
+
|
|
218
|
+
const float GW_A0 = 3.2; // separation when a cycle starts, cells
|
|
219
|
+
const float GW_R = 0.0256; // tau at merger / tau at start = (a_merge / a0)^4, a_merge = 0.4 a0
|
|
220
|
+
const float GW_W0 = 1.3; // orbital angular frequency at the start, rad/s
|
|
221
|
+
const float GW_QNM = 1.3; // ringdown frequency / orbital frequency at merger
|
|
222
|
+
const float GW_TD = 0.4; // ringdown e-folding time, s
|
|
223
|
+
const float GW_H0 = 0.24; // strain at the source at the start (strain knob = 1)
|
|
224
|
+
const float GW_RF = 10.0; // softening of the 1/r fall-off, cells
|
|
225
|
+
const float GW_G = 0.45; // well strength (G M), cells^3; folds only past ~5 eps^3
|
|
226
|
+
const float GW_EPS = 0.6; // well softening, cells
|
|
227
|
+
|
|
228
|
+
float gwCycle(){ return max(u_chirpTime, 4.0); }
|
|
229
|
+
|
|
230
|
+
// State of the binary s seconds into a cycle: orbital phase, orbital
|
|
231
|
+
// angular frequency, separation, wave envelope (~ omega^(2/3)), and how
|
|
232
|
+
// present the new binary is (it fades in while the old remnant fades out).
|
|
233
|
+
void gwState(float s, out float phi, out float w, out float a, out float env, out float live){
|
|
234
|
+
float T = gwCycle();
|
|
235
|
+
float Ti = 0.7 * T; // inspiral; merger at Ti
|
|
236
|
+
float ts = Ti / (1.0 - GW_R); // tau when the cycle starts
|
|
237
|
+
float fadeIn = smoothstep(0.0, 0.12 * T, s);
|
|
238
|
+
if (s < Ti){
|
|
239
|
+
float u = (ts - s) / ts; // tau / tau_start, 1 -> GW_R
|
|
240
|
+
a = GW_A0 * pow(u, 0.25);
|
|
241
|
+
w = GW_W0 * pow(u, -0.375);
|
|
242
|
+
phi = 1.6 * GW_W0 * ts * (1.0 - pow(u, 0.625));
|
|
243
|
+
env = pow(u, -0.25) * fadeIn;
|
|
244
|
+
live = fadeIn;
|
|
245
|
+
} else {
|
|
246
|
+
// ringdown: the remnant's quadrupole mode, frequency easing up to the
|
|
247
|
+
// quasi-normal value and decaying exponentially
|
|
248
|
+
float x = s - Ti;
|
|
249
|
+
float wm = GW_W0 * pow(GW_R, -0.375);
|
|
250
|
+
float wq = wm * GW_QNM;
|
|
251
|
+
float e = 1.0 - exp(-x / 0.15);
|
|
252
|
+
phi = 1.6 * GW_W0 * ts * (1.0 - pow(GW_R, 0.625)) + wq * x - (wq - wm) * 0.15 * e;
|
|
253
|
+
w = mix(wm, wq, e);
|
|
254
|
+
a = GW_A0 * pow(GW_R, 0.25) * exp(-x / 0.12);
|
|
255
|
+
env = pow(GW_R, -0.25) * exp(-x / GW_TD) * (1.0 - smoothstep(0.9 * T, T, s));
|
|
256
|
+
live = 1.0;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
void gwMasses(out float m1, out float m2){
|
|
261
|
+
float q = clamp(u_massRatio, 0.1, 1.0);
|
|
262
|
+
m1 = 1.0 / (1.0 + q);
|
|
263
|
+
m2 = q / (1.0 + q);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Outgoing wave at x (cells from the binary) and time t.
|
|
267
|
+
// Returns the displacement in xy, the signed strain in z, and the
|
|
268
|
+
// brightness of the two spiral arms (the crests of h+) in w.
|
|
269
|
+
vec4 gwWave(vec2 x, float t, float pix){
|
|
270
|
+
float T = gwCycle();
|
|
271
|
+
float c = max(u_waveSpeed, 0.5);
|
|
272
|
+
float r = length(x);
|
|
273
|
+
float phi, w, a, env, live;
|
|
274
|
+
gwState(mod(t - r / c, T), phi, w, a, env, live);
|
|
275
|
+
float m1, m2;
|
|
276
|
+
gwMasses(m1, m2);
|
|
277
|
+
float k = 2.0 * w / c;
|
|
278
|
+
float h = u_strain * GW_H0 * 4.0 * m1 * m2 * env * GW_RF / (r + GW_RF);
|
|
279
|
+
h *= smoothstep(0.4, 2.2, r); // no wave inside the near zone
|
|
280
|
+
h /= sqrt(1.0 + h * h / 0.42); // soft limit keeps the lattice from folding
|
|
281
|
+
// a wavelength shorter than a few pixels would only alias: let it go
|
|
282
|
+
h *= smoothstep(3.0, 8.0, (TAU / k) / max(pix, 1e-5));
|
|
283
|
+
vec2 rh = x / max(r, 1e-4);
|
|
284
|
+
float psi = 2.0 * (phi - atan(x.y, x.x));
|
|
285
|
+
float cp = cos(psi);
|
|
286
|
+
vec2 D = (h / k) * (cp * rh + sin(psi) * vec2(-rh.y, rh.x));
|
|
287
|
+
// the crests of h+ drawn as light: the two trailing arms of the
|
|
288
|
+
// quadrupole emission pattern, kept legible far from the source
|
|
289
|
+
float amp = clamp(u_strain, 0.0, 2.0) * 4.0 * m1 * m2 * env
|
|
290
|
+
* pow(GW_RF / (r + GW_RF), 0.75) * smoothstep(0.4, 2.2, r);
|
|
291
|
+
float cpp = max(cp, 0.0);
|
|
292
|
+
cpp *= cpp; // a narrow ridge along each crest
|
|
293
|
+
return vec4(D, h * sin(psi), amp * cpp * cpp * cpp);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// pull of a softened point mass: grad of m / sqrt(r^2 + eps^2)
|
|
297
|
+
vec2 gwPull(vec2 x, vec2 p, float m){
|
|
298
|
+
vec2 d = x - p;
|
|
299
|
+
float q = dot(d, d) + GW_EPS * GW_EPS;
|
|
300
|
+
return d * (GW_G * m / (q * sqrt(q)));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
// a lattice line that dissolves into its average coverage before it gets
|
|
305
|
+
// finer than about 1.5 px, so the far field never turns into moire
|
|
306
|
+
float gwLine(float c, float width, float fp){
|
|
307
|
+
float l = lineAt(c, width, fp);
|
|
308
|
+
return mix(l, min(width * fp, 1.0) * 0.45, smoothstep(0.3, 0.65, fp));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
void main(){
|
|
312
|
+
float cs = max(u_cellSize, 1e-4);
|
|
313
|
+
vec2 coord = vGridPos / cs;
|
|
314
|
+
vec2 focus = u_focus / cs;
|
|
315
|
+
float t = u_time * u_animSpeed;
|
|
316
|
+
float pix = length(fwidth(coord)) * 0.7071;
|
|
317
|
+
float T = gwCycle();
|
|
318
|
+
|
|
319
|
+
vec2 x = coord - focus; // cells from the binary's centre of mass
|
|
320
|
+
float r = length(x);
|
|
321
|
+
|
|
322
|
+
float phi, w, sep, env, live;
|
|
323
|
+
float s = mod(t, T);
|
|
324
|
+
gwState(s, phi, w, sep, env, live);
|
|
325
|
+
float m1, m2;
|
|
326
|
+
gwMasses(m1, m2);
|
|
327
|
+
vec2 e = vec2(cos(phi), sin(phi)) * sep;
|
|
328
|
+
vec2 p1 = -e * m2;
|
|
329
|
+
vec2 p2 = e * m1;
|
|
330
|
+
|
|
331
|
+
// Lattice coordinates: the wells pull the lines in, the wave displaces them.
|
|
332
|
+
vec4 wave = gwWave(x, t, pix);
|
|
333
|
+
vec2 pull = live * (gwPull(x, p1, m1) + gwPull(x, p2, m2))
|
|
334
|
+
+ (1.0 - live) * gwPull(x, vec2(0.0), 1.0);
|
|
335
|
+
vec2 g = coord + pull - wave.xy;
|
|
336
|
+
vec2 fw = max(fwidth(g), vec2(1e-5));
|
|
337
|
+
|
|
338
|
+
float lx = gwLine(g.x, u_lineWidth, fw.x);
|
|
339
|
+
float ly = gwLine(g.y, u_lineWidth, fw.y);
|
|
340
|
+
float lines = max(lx, ly);
|
|
341
|
+
|
|
342
|
+
float accent = 0.0;
|
|
343
|
+
if (u_sectionWidth > 0.0 && u_sectionSize > 0.0){
|
|
344
|
+
float ss = u_sectionSize;
|
|
345
|
+
accent = max(gwLine(g.x / ss, u_sectionWidth, fw.x / ss),
|
|
346
|
+
gwLine(g.y / ss, u_sectionWidth, fw.y / ss));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
vec2 fr = abs(fract(g - 0.5) - 0.5);
|
|
350
|
+
float cellH = hash21(floor(g) + 0.37);
|
|
351
|
+
float edgeKeep = smoothstep(0.02, 0.16, min(fr.x, fr.y));
|
|
352
|
+
float cellDist = length(x + pull - wave.xy); // ripples bend into the wells
|
|
353
|
+
float flowCoord = (g.x + g.y) * 0.7071;
|
|
354
|
+
float scanCoord = r * 2.0;
|
|
355
|
+
float fadeR = length(vGridPos) / max(u_fadeDistance, 1e-4);
|
|
356
|
+
|
|
357
|
+
// The masses: white-hot cores that stay at least a pixel wide, with a
|
|
358
|
+
// faint accretion glow, and a soft flash as they merge.
|
|
359
|
+
float core = 0.0;
|
|
360
|
+
float halo = 0.0;
|
|
361
|
+
float d1 = length(x - p1), d2 = length(x - p2), d0 = r;
|
|
362
|
+
float r1 = max(0.18 * pow(m1, 0.333), pix * 1.4);
|
|
363
|
+
float r2 = max(0.18 * pow(m2, 0.333), pix * 1.4);
|
|
364
|
+
float r0 = max(0.18, pix * 1.4);
|
|
365
|
+
core += live * (exp(-d1 * d1 / (r1 * r1)) + exp(-d2 * d2 / (r2 * r2)));
|
|
366
|
+
core += (1.0 - live) * exp(-d0 * d0 / (r0 * r0));
|
|
367
|
+
halo += live * (m1 * exp(-d1 / 0.6) + m2 * exp(-d2 / 0.6));
|
|
368
|
+
halo += (1.0 - live) * exp(-d0 / 0.6);
|
|
369
|
+
float xm = s - 0.7 * T;
|
|
370
|
+
float flash = xm > 0.0 ? exp(-xm / 0.5) : exp(xm / 0.6) * 0.25;
|
|
371
|
+
float bloom = flash * exp(-r * r / 6.0);
|
|
372
|
+
|
|
373
|
+
// The crests of h+ are the two trailing arms of the emission pattern;
|
|
374
|
+
// they glow, the lines light up where the strain is large, and the
|
|
375
|
+
// stretched strips take a faint tint, so the spiral reads between lines.
|
|
376
|
+
float arms = wave.w;
|
|
377
|
+
vec3 extraCol = u_glowColor * (arms * 0.7 + lines * arms * 0.8)
|
|
378
|
+
+ u_cellColor * max(wave.z, 0.0) * 1.6 * edgeKeep
|
|
379
|
+
+ mix(u_glowColor, vec3(1.0), 0.75) * core * 1.8
|
|
380
|
+
+ u_glowColor * (halo * 0.4 + bloom * 0.4);
|
|
381
|
+
float extraA = clamp(max(max(core, arms * 0.75), halo * 0.4 + bloom * 0.3), 0.0, 1.0);
|
|
382
|
+
float regionMask = 1.0;
|
|
383
|
+
|
|
384
|
+
// ---- line animation --------------------------------------------------
|
|
385
|
+
float lineAnim = 1.0;
|
|
386
|
+
if (u_lineMode > 0.5){
|
|
387
|
+
if (u_lineMode < 1.5){
|
|
388
|
+
lineAnim = 0.5 + 0.5 * sin(cellDist * u_animScale - t);
|
|
389
|
+
} else if (u_lineMode < 2.5){
|
|
390
|
+
lineAnim = 0.5 + 0.5 * sin(flowCoord * u_animScale - t);
|
|
391
|
+
} else if (u_lineMode < 3.5){
|
|
392
|
+
float s = fract(scanCoord * 0.05 * u_animScale - t * 0.15);
|
|
393
|
+
lineAnim = 0.25 + smoothstep(0.0, 0.15, s) * (1.0 - smoothstep(0.15, 0.35, s));
|
|
394
|
+
} else {
|
|
395
|
+
lineAnim = 0.5 + 0.5 * sin(t);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
lineAnim = mix(1.0, lineAnim, u_animIntensity);
|
|
399
|
+
|
|
400
|
+
// ---- cell fill -------------------------------------------------------
|
|
401
|
+
float cell = 0.0;
|
|
402
|
+
if (u_cellMode > 0.5){
|
|
403
|
+
if (u_cellMode < 1.5){
|
|
404
|
+
cell = 0.5 + 0.5 * sin(flowCoord * 0.5 * u_animScale - t);
|
|
405
|
+
} else if (u_cellMode < 2.5){
|
|
406
|
+
cell = 0.5 + 0.5 * sin(t * (0.6 + cellH) + cellH * TAU);
|
|
407
|
+
} else if (u_cellMode < 3.5){
|
|
408
|
+
cell = smoothstep(0.6, 1.0, sin(cellDist * u_animScale - t));
|
|
409
|
+
} else {
|
|
410
|
+
cell = step(0.5, cellH) * (0.5 + 0.5 * sin(t));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
cell *= u_animIntensity * edgeKeep;
|
|
414
|
+
|
|
415
|
+
float tone = step(0.55, cellH);
|
|
416
|
+
|
|
417
|
+
vec3 col = u_bgColor * u_bgOpacity;
|
|
418
|
+
float a = u_bgOpacity;
|
|
419
|
+
|
|
420
|
+
col += mix(u_cellColor, u_cellColor * 2.2, tone) * cell;
|
|
421
|
+
a = max(a, cell * 0.9);
|
|
422
|
+
float linesI = lines * lineAnim;
|
|
423
|
+
col += u_lineColor * linesI; a = max(a, linesI);
|
|
424
|
+
float accentI = accent * lineAnim;
|
|
425
|
+
col += u_sectionColor * accentI; a = max(a, accentI);
|
|
426
|
+
col += u_glowColor * (linesI * 0.2 + cell * 0.35) * u_animIntensity;
|
|
427
|
+
|
|
428
|
+
col = col * regionMask + extraCol;
|
|
429
|
+
a = max(a * regionMask, extraA);
|
|
430
|
+
|
|
431
|
+
float fade = 1.0 - smoothstep(1.0 - u_fadeStrength, 1.0, fadeR);
|
|
432
|
+
col *= fade;
|
|
433
|
+
a *= fade;
|
|
434
|
+
|
|
435
|
+
// ---- reveal ----------------------------------------------------------
|
|
436
|
+
// The build boundary sweeps outward from the focus point with a bright
|
|
437
|
+
// leading edge, so the grid reads as assembling itself.
|
|
438
|
+
if (u_reveal < 0.999){
|
|
439
|
+
float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
|
|
440
|
+
float edge = u_reveal * 1.1;
|
|
441
|
+
float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
|
|
442
|
+
float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
|
|
443
|
+
col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
|
|
444
|
+
a = max(a * mask, front * 0.10);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (a < 0.002) discard;
|
|
448
|
+
gl_FragColor = vec4(col, a);
|
|
449
|
+
}
|
|
450
|
+
`;
|
|
451
|
+
export const GravWaveGridMaterial = shaderMaterial({
|
|
452
|
+
u_time: gravWaveGridMaterialDefaults.u_time,
|
|
453
|
+
u_cellSize: gravWaveGridMaterialDefaults.u_cellSize,
|
|
454
|
+
u_lineWidth: gravWaveGridMaterialDefaults.u_lineWidth,
|
|
455
|
+
u_sectionSize: gravWaveGridMaterialDefaults.u_sectionSize,
|
|
456
|
+
u_sectionWidth: gravWaveGridMaterialDefaults.u_sectionWidth,
|
|
457
|
+
u_lineColor: gravWaveGridMaterialDefaults.u_lineColor.clone(),
|
|
458
|
+
u_sectionColor: gravWaveGridMaterialDefaults.u_sectionColor.clone(),
|
|
459
|
+
u_cellColor: gravWaveGridMaterialDefaults.u_cellColor.clone(),
|
|
460
|
+
u_glowColor: gravWaveGridMaterialDefaults.u_glowColor.clone(),
|
|
461
|
+
u_bgColor: gravWaveGridMaterialDefaults.u_bgColor.clone(),
|
|
462
|
+
u_bgOpacity: gravWaveGridMaterialDefaults.u_bgOpacity,
|
|
463
|
+
u_lineMode: gravWaveGridMaterialDefaults.u_lineMode,
|
|
464
|
+
u_cellMode: gravWaveGridMaterialDefaults.u_cellMode,
|
|
465
|
+
u_animSpeed: gravWaveGridMaterialDefaults.u_animSpeed,
|
|
466
|
+
u_animScale: gravWaveGridMaterialDefaults.u_animScale,
|
|
467
|
+
u_animIntensity: gravWaveGridMaterialDefaults.u_animIntensity,
|
|
468
|
+
u_fadeDistance: gravWaveGridMaterialDefaults.u_fadeDistance,
|
|
469
|
+
u_fadeStrength: gravWaveGridMaterialDefaults.u_fadeStrength,
|
|
470
|
+
u_focus: gravWaveGridMaterialDefaults.u_focus.clone(),
|
|
471
|
+
u_mouse: gravWaveGridMaterialDefaults.u_mouse.clone(),
|
|
472
|
+
u_displace: gravWaveGridMaterialDefaults.u_displace,
|
|
473
|
+
u_reveal: gravWaveGridMaterialDefaults.u_reveal,
|
|
474
|
+
u_strain: gravWaveGridMaterialDefaults.u_strain,
|
|
475
|
+
u_chirpTime: gravWaveGridMaterialDefaults.u_chirpTime,
|
|
476
|
+
u_waveSpeed: gravWaveGridMaterialDefaults.u_waveSpeed,
|
|
477
|
+
u_massRatio: gravWaveGridMaterialDefaults.u_massRatio,
|
|
478
|
+
}, vertex, fragment);
|
|
479
|
+
extend({ GravWaveGridMaterial });
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* An Escher-style {p,q} tiling of the Poincare disk. A slow Mobius translation glides the tiling through itself, and the tiles shrink without end toward the rim.
|
|
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 HyperbolicGridMaterialUniforms {
|
|
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
|
+
/** sides of each polygon (p), 3..12 */
|
|
33
|
+
u_sides: number;
|
|
34
|
+
/** polygons around each vertex (q), 3..12; raised in the shader until (p-2)(q-2) > 4 */
|
|
35
|
+
u_valence: number;
|
|
36
|
+
/** 0..1, how far the tiling glides through itself */
|
|
37
|
+
u_drift: number;
|
|
38
|
+
}
|
|
39
|
+
declare module '@react-three/fiber' {
|
|
40
|
+
interface ThreeElements {
|
|
41
|
+
hyperbolicGridMaterial: ThreeElements['shaderMaterial'] & Partial<HyperbolicGridMaterialUniforms>;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export declare const hyperbolicGridMaterialDefaults: HyperbolicGridMaterialUniforms;
|
|
45
|
+
export declare const HyperbolicGridMaterial: import("@react-three/fiber").ConstructorRepresentation<THREE.ShaderMaterial & {
|
|
46
|
+
u_time: number;
|
|
47
|
+
u_cellSize: number;
|
|
48
|
+
u_lineWidth: number;
|
|
49
|
+
u_sectionSize: number;
|
|
50
|
+
u_sectionWidth: number;
|
|
51
|
+
u_lineColor: THREE.Color;
|
|
52
|
+
u_sectionColor: THREE.Color;
|
|
53
|
+
u_cellColor: THREE.Color;
|
|
54
|
+
u_glowColor: THREE.Color;
|
|
55
|
+
u_bgColor: THREE.Color;
|
|
56
|
+
u_bgOpacity: number;
|
|
57
|
+
u_lineMode: number;
|
|
58
|
+
u_cellMode: number;
|
|
59
|
+
u_animSpeed: number;
|
|
60
|
+
u_animScale: number;
|
|
61
|
+
u_animIntensity: number;
|
|
62
|
+
u_fadeDistance: number;
|
|
63
|
+
u_fadeStrength: number;
|
|
64
|
+
u_focus: THREE.Vector2;
|
|
65
|
+
u_mouse: THREE.Vector2;
|
|
66
|
+
u_displace: number;
|
|
67
|
+
u_reveal: number;
|
|
68
|
+
u_sides: number;
|
|
69
|
+
u_valence: number;
|
|
70
|
+
u_drift: number;
|
|
71
|
+
}> & {
|
|
72
|
+
key: string;
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=HyperbolicGridMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HyperbolicGridMaterial.d.ts","sourceRoot":"","sources":["../../src/shaders/HyperbolicGridMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B;;;;;GAKG;AACH,MAAM,WAAW,8BAA8B;IAC3C,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,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,wFAAwF;IACxF,SAAS,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,OAAO,QAAQ,oBAAoB,CAAC;IAChC,UAAU,aAAa;QACnB,sBAAsB,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;KACrG;CACJ;AAED,eAAO,MAAM,8BAA8B,EAAE,8BA0B5C,CAAC;AAoPF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BlC,CAAC"}
|