@3driseai/3drise-core 1.0.1 → 1.0.3
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/services/MaterialRegistry.d.ts +25 -0
- package/dist/services/MaterialRegistry.d.ts.map +1 -1
- package/dist/services/MaterialRegistry.js +102 -1
- package/dist/shaders/CircuitGridMaterial.d.ts +76 -0
- package/dist/shaders/CircuitGridMaterial.d.ts.map +1 -0
- package/dist/shaders/CircuitGridMaterial.js +298 -0
- package/dist/shaders/ContourGridMaterial.d.ts +80 -0
- package/dist/shaders/ContourGridMaterial.d.ts.map +1 -0
- package/dist/shaders/ContourGridMaterial.js +259 -0
- package/dist/shaders/FractalGridMaterial.d.ts +76 -0
- package/dist/shaders/FractalGridMaterial.d.ts.map +1 -0
- package/dist/shaders/FractalGridMaterial.js +247 -0
- package/dist/shaders/HexGridMaterial.d.ts +73 -0
- package/dist/shaders/HexGridMaterial.d.ts.map +1 -0
- package/dist/shaders/HexGridMaterial.js +265 -0
- package/dist/shaders/MoireGridMaterial.d.ts +79 -0
- package/dist/shaders/MoireGridMaterial.d.ts.map +1 -0
- package/dist/shaders/MoireGridMaterial.js +271 -0
- package/dist/shaders/MyGridMaterial.d.ts +7 -0
- package/dist/shaders/MyGridMaterial.d.ts.map +1 -1
- package/dist/shaders/MyGridMaterial.js +19 -0
- package/dist/shaders/QuasiGridMaterial.d.ts +76 -0
- package/dist/shaders/QuasiGridMaterial.d.ts.map +1 -0
- package/dist/shaders/QuasiGridMaterial.js +238 -0
- package/dist/shaders/RadarGridMaterial.d.ts +77 -0
- package/dist/shaders/RadarGridMaterial.d.ts.map +1 -0
- package/dist/shaders/RadarGridMaterial.js +291 -0
- package/dist/shaders/RainMaterial copy.d.ts +34 -0
- package/dist/shaders/RainMaterial copy.d.ts.map +1 -0
- package/dist/shaders/RainMaterial copy.js +56 -0
- package/dist/shaders/ShaderEffectsMaterial copy 2.d.ts +228 -0
- package/dist/shaders/ShaderEffectsMaterial copy 2.d.ts.map +1 -0
- package/dist/shaders/ShaderEffectsMaterial copy 2.js +233 -0
- package/dist/shaders/ShootingStarMaterial copy.d.ts +14 -0
- package/dist/shaders/ShootingStarMaterial copy.d.ts.map +1 -0
- package/dist/shaders/ShootingStarMaterial copy.js +33 -0
- package/dist/shaders/SkyboxMaterial copy.d.ts +38 -0
- package/dist/shaders/SkyboxMaterial copy.d.ts.map +1 -0
- package/dist/shaders/SkyboxMaterial copy.js +57 -0
- package/dist/shaders/VoronoiGridMaterial.d.ts +73 -0
- package/dist/shaders/VoronoiGridMaterial.d.ts.map +1 -0
- package/dist/shaders/VoronoiGridMaterial.js +266 -0
- package/dist/shaders/index.d.ts +11 -0
- package/dist/shaders/index.d.ts.map +1 -1
- package/dist/shaders/index.js +11 -0
- package/dist/types/objectsConfigs.d.ts +12 -0
- package/dist/types/objectsConfigs.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { shaderMaterial } from '@react-three/drei';
|
|
3
|
+
import { extend } from '@react-three/fiber';
|
|
4
|
+
export const hexGridMaterialDefaults = {
|
|
5
|
+
u_time: 0,
|
|
6
|
+
u_cellSize: 1.0,
|
|
7
|
+
u_lineWidth: 1.2,
|
|
8
|
+
u_sectionSize: 4.0,
|
|
9
|
+
u_sectionWidth: 2.0,
|
|
10
|
+
u_lineColor: new THREE.Color(0.16, 0.62, 0.78),
|
|
11
|
+
u_sectionColor: new THREE.Color(0.45, 0.92, 1.0),
|
|
12
|
+
u_cellColor: new THREE.Color(0.06, 0.28, 0.42),
|
|
13
|
+
u_glowColor: new THREE.Color(0.3, 0.95, 1.0),
|
|
14
|
+
u_bgColor: new THREE.Color(0.01, 0.03, 0.05),
|
|
15
|
+
u_bgOpacity: 0.0,
|
|
16
|
+
u_lineMode: 1,
|
|
17
|
+
u_cellMode: 2,
|
|
18
|
+
u_animSpeed: 1.0,
|
|
19
|
+
u_animScale: 0.6,
|
|
20
|
+
u_animIntensity: 1.0,
|
|
21
|
+
u_fadeDistance: 25.0,
|
|
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.0,
|
|
26
|
+
u_reveal: 1.0,
|
|
27
|
+
u_plateau: 1.0,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Shared by both stages.
|
|
31
|
+
*
|
|
32
|
+
* The lattice is the standard pointy-top honeycomb: hex centres sit on a
|
|
33
|
+
* triangular lattice of spacing 1 in normalised coords, so `hexDist` returns
|
|
34
|
+
* 0.5 exactly on an edge and 0 at the centre. Because `hexDist` is 1-Lipschitz
|
|
35
|
+
* in those coords, the *continuous* input's pixel footprint is a valid
|
|
36
|
+
* antialiasing width — which matters, since `fwidth` of the per-hex local
|
|
37
|
+
* coordinate spikes along every hex boundary and would erase the very lines we
|
|
38
|
+
* are trying to draw.
|
|
39
|
+
*/
|
|
40
|
+
const hexCommon = /*glsl*/ `
|
|
41
|
+
const float TAU = 6.28318530718;
|
|
42
|
+
const vec2 HEX_R = vec2(1.0, 1.73205081);
|
|
43
|
+
|
|
44
|
+
float hash21(vec2 p){
|
|
45
|
+
p = fract(p * vec2(123.34, 456.21));
|
|
46
|
+
p += dot(p, p + 45.32);
|
|
47
|
+
return fract(p.x * p.y);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 0.5 exactly on a flat edge, 0 at the centre. The hexes are pointy-top:
|
|
51
|
+
// vertical flats at x = +/-0.5, vertices at (0, +/-0.577).
|
|
52
|
+
float hexDist(vec2 p){
|
|
53
|
+
p = abs(p);
|
|
54
|
+
float c = dot(p, normalize(HEX_R));
|
|
55
|
+
return max(c, p.x);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** xy = position inside the hex, zw = hex centre in the same coords */
|
|
59
|
+
vec4 hexCoords(vec2 p){
|
|
60
|
+
vec2 h = HEX_R * 0.5;
|
|
61
|
+
vec2 a = mod(p, HEX_R) - h;
|
|
62
|
+
vec2 b = mod(p - h, HEX_R) - h;
|
|
63
|
+
vec2 gv = dot(a, a) < dot(b, b) ? a : b;
|
|
64
|
+
return vec4(gv, p - gv);
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
const vertex = /*glsl*/ `
|
|
68
|
+
uniform float u_time;
|
|
69
|
+
uniform float u_cellSize;
|
|
70
|
+
uniform float u_displace;
|
|
71
|
+
uniform float u_animSpeed;
|
|
72
|
+
uniform float u_animScale;
|
|
73
|
+
uniform float u_plateau;
|
|
74
|
+
|
|
75
|
+
varying vec2 vGridPos;
|
|
76
|
+
|
|
77
|
+
${hexCommon}
|
|
78
|
+
|
|
79
|
+
void main(){
|
|
80
|
+
vGridPos = position.xy;
|
|
81
|
+
vec3 pos = position;
|
|
82
|
+
|
|
83
|
+
if (u_displace > 0.0){
|
|
84
|
+
float t = u_time * u_animSpeed;
|
|
85
|
+
vec2 coord = position.xy / max(u_cellSize, 1e-4);
|
|
86
|
+
float smoothLift = 0.5 + 0.5 * sin(length(coord) * u_animScale - t);
|
|
87
|
+
float lift = smoothLift;
|
|
88
|
+
|
|
89
|
+
if (u_plateau > 0.5){
|
|
90
|
+
vec4 hc = hexCoords(coord);
|
|
91
|
+
vec2 id = hc.zw;
|
|
92
|
+
float h = hash21(id);
|
|
93
|
+
// The plate height comes from a smooth field sampled at the hex centre,
|
|
94
|
+
// not from the hash alone: uncorrelated neighbours shred the mesh into
|
|
95
|
+
// spikes. The hash only nudges each plate off the wave.
|
|
96
|
+
float plate = clamp(smoothLift + (h - 0.5) * 0.5, 0.0, 1.0);
|
|
97
|
+
// Flat across the middle of the hex, ramping back to the smooth field
|
|
98
|
+
// at the rim. A hard step would have to be resolved by whatever
|
|
99
|
+
// triangles happen to straddle the boundary, which reads as sawtooth;
|
|
100
|
+
// the ramp turns those walls into clean bevels instead.
|
|
101
|
+
float flatness = smoothstep(0.5, 0.26, hexDist(hc.xy));
|
|
102
|
+
lift = mix(smoothLift, plate, flatness);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
pos.z += lift * u_displace;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
111
|
+
const fragment = /*glsl*/ `
|
|
112
|
+
precision highp float;
|
|
113
|
+
|
|
114
|
+
uniform float u_time;
|
|
115
|
+
uniform float u_cellSize;
|
|
116
|
+
uniform float u_lineWidth;
|
|
117
|
+
uniform float u_sectionSize;
|
|
118
|
+
uniform float u_sectionWidth;
|
|
119
|
+
uniform vec3 u_lineColor;
|
|
120
|
+
uniform vec3 u_sectionColor;
|
|
121
|
+
uniform vec3 u_cellColor;
|
|
122
|
+
uniform vec3 u_glowColor;
|
|
123
|
+
uniform vec3 u_bgColor;
|
|
124
|
+
uniform float u_bgOpacity;
|
|
125
|
+
uniform float u_lineMode;
|
|
126
|
+
uniform float u_cellMode;
|
|
127
|
+
uniform float u_animSpeed;
|
|
128
|
+
uniform float u_animScale;
|
|
129
|
+
uniform float u_animIntensity;
|
|
130
|
+
uniform float u_fadeDistance;
|
|
131
|
+
uniform float u_fadeStrength;
|
|
132
|
+
uniform vec2 u_focus;
|
|
133
|
+
uniform float u_reveal;
|
|
134
|
+
|
|
135
|
+
varying vec2 vGridPos;
|
|
136
|
+
|
|
137
|
+
${hexCommon}
|
|
138
|
+
|
|
139
|
+
/** hexagonal edge mask for a lattice scaled by the scale argument */
|
|
140
|
+
float hexEdge(vec2 coord, float scale, float width, float px){
|
|
141
|
+
vec2 c = coord / scale;
|
|
142
|
+
float d = 0.5 - hexDist(hexCoords(c).xy);
|
|
143
|
+
return 1.0 - smoothstep(0.0, max(px / scale, 1e-6) * max(width, 0.05), d);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
void main(){
|
|
147
|
+
vec2 coord = vGridPos / max(u_cellSize, 1e-4);
|
|
148
|
+
vec2 focus = u_focus / max(u_cellSize, 1e-4);
|
|
149
|
+
float t = u_time * u_animSpeed;
|
|
150
|
+
float px = max(length(fwidth(coord)), 1e-6);
|
|
151
|
+
|
|
152
|
+
vec4 hc = hexCoords(coord);
|
|
153
|
+
vec2 gv = hc.xy;
|
|
154
|
+
vec2 id = hc.zw;
|
|
155
|
+
float hd = hexDist(gv);
|
|
156
|
+
|
|
157
|
+
float minor = hexEdge(coord, 1.0, u_lineWidth, px);
|
|
158
|
+
float major = 0.0;
|
|
159
|
+
if (u_sectionWidth > 0.0 && u_sectionSize > 0.0){
|
|
160
|
+
major = hexEdge(coord, u_sectionSize, u_sectionWidth, px);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ---- edge animation -------------------------------------------------
|
|
164
|
+
float lineAnim = 1.0;
|
|
165
|
+
if (u_lineMode > 0.5 && u_lineMode < 1.5){
|
|
166
|
+
// ripple: hexagonal rings, so the wavefront keeps the lattice's shape
|
|
167
|
+
float ring = hexDist(id - focus);
|
|
168
|
+
lineAnim = 0.5 + 0.5 * sin(ring * u_animScale - t);
|
|
169
|
+
} else if (u_lineMode < 2.5){
|
|
170
|
+
// flow: a wave travelling along one lattice axis
|
|
171
|
+
lineAnim = 0.5 + 0.5 * sin(dot(id, vec2(0.5, 0.866)) * u_animScale - t);
|
|
172
|
+
} else if (u_lineMode < 3.5){
|
|
173
|
+
// scan: a bright band sweeping across
|
|
174
|
+
float s = fract((id.x + id.y * 0.5) * 0.05 * u_animScale - t * 0.15);
|
|
175
|
+
lineAnim = 0.25 + smoothstep(0.0, 0.15, s) * (1.0 - smoothstep(0.15, 0.35, s));
|
|
176
|
+
} else if (u_lineMode < 4.5){
|
|
177
|
+
lineAnim = 0.5 + 0.5 * sin(t);
|
|
178
|
+
}
|
|
179
|
+
lineAnim = mix(1.0, lineAnim, u_animIntensity);
|
|
180
|
+
|
|
181
|
+
// ---- cell fill ------------------------------------------------------
|
|
182
|
+
float cell = 0.0;
|
|
183
|
+
if (u_cellMode > 0.5 && u_cellMode < 1.5){
|
|
184
|
+
cell = 0.5 + 0.5 * sin(dot(id, vec2(0.7, 0.3)) * u_animScale - t);
|
|
185
|
+
} else if (u_cellMode < 2.5){
|
|
186
|
+
float h = hash21(id);
|
|
187
|
+
cell = 0.5 + 0.5 * sin(t * (0.6 + h) + h * TAU);
|
|
188
|
+
} else if (u_cellMode < 3.5){
|
|
189
|
+
float ring = hexDist(id - focus);
|
|
190
|
+
cell = smoothstep(0.6, 1.0, sin(ring * u_animScale - t));
|
|
191
|
+
} else if (u_cellMode < 4.5){
|
|
192
|
+
// the honeycomb's answer to a checkerboard: a proper 3-colouring. Column
|
|
193
|
+
// index alone works here — every neighbour differs by 1 or 2 columns.
|
|
194
|
+
float tri = mod(floor(id.x * 2.0 + 0.5), 3.0);
|
|
195
|
+
cell = step(1.5, tri) * (0.5 + 0.5 * sin(t));
|
|
196
|
+
}
|
|
197
|
+
cell *= u_animIntensity;
|
|
198
|
+
// keep the fill inside the hex, clear of its own edge
|
|
199
|
+
cell *= smoothstep(0.5, 0.34, hd);
|
|
200
|
+
|
|
201
|
+
// charged hexes glow brightest at the rim, which reads as depth
|
|
202
|
+
float rim = smoothstep(0.24, 0.46, hd);
|
|
203
|
+
|
|
204
|
+
float r = length(vGridPos) / max(u_fadeDistance, 1e-4);
|
|
205
|
+
float fade = 1.0 - smoothstep(1.0 - u_fadeStrength, 1.0, r);
|
|
206
|
+
|
|
207
|
+
vec3 col = u_bgColor * u_bgOpacity;
|
|
208
|
+
float a = u_bgOpacity;
|
|
209
|
+
|
|
210
|
+
col += u_cellColor * cell; a = max(a, cell * 0.9);
|
|
211
|
+
float minorI = minor * lineAnim;
|
|
212
|
+
col += u_lineColor * minorI; a = max(a, minorI);
|
|
213
|
+
float majorI = major * lineAnim;
|
|
214
|
+
col += u_sectionColor * majorI; a = max(a, majorI);
|
|
215
|
+
col += u_glowColor * (minorI * 0.2 + cell * rim * 0.6) * u_animIntensity;
|
|
216
|
+
|
|
217
|
+
col *= fade;
|
|
218
|
+
a *= fade;
|
|
219
|
+
|
|
220
|
+
// ---- reveal ----------------------------------------------------------
|
|
221
|
+
// The build boundary sweeps outward from the focus point. Its leading band
|
|
222
|
+
// mostly brightens whatever is already there rather than painting a solid
|
|
223
|
+
// disc, so the grid reads as assembling itself rather than fading in.
|
|
224
|
+
if (u_reveal < 0.999){
|
|
225
|
+
float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
|
|
226
|
+
// 1.1, not 1.25: the boundary has to clear the fade radius by just the
|
|
227
|
+
// width of its own soft edge. Overshooting further finishes the build
|
|
228
|
+
// before reveal reaches 1 and leaves the tail of the range doing nothing.
|
|
229
|
+
float edge = u_reveal * 1.1;
|
|
230
|
+
float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
|
|
231
|
+
float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
|
|
232
|
+
col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
|
|
233
|
+
a = max(a * mask, front * 0.10);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (a < 0.002) discard;
|
|
237
|
+
gl_FragColor = vec4(col, a);
|
|
238
|
+
}
|
|
239
|
+
`;
|
|
240
|
+
export const HexGridMaterial = shaderMaterial({
|
|
241
|
+
u_time: hexGridMaterialDefaults.u_time,
|
|
242
|
+
u_cellSize: hexGridMaterialDefaults.u_cellSize,
|
|
243
|
+
u_lineWidth: hexGridMaterialDefaults.u_lineWidth,
|
|
244
|
+
u_sectionSize: hexGridMaterialDefaults.u_sectionSize,
|
|
245
|
+
u_sectionWidth: hexGridMaterialDefaults.u_sectionWidth,
|
|
246
|
+
u_lineColor: hexGridMaterialDefaults.u_lineColor.clone(),
|
|
247
|
+
u_sectionColor: hexGridMaterialDefaults.u_sectionColor.clone(),
|
|
248
|
+
u_cellColor: hexGridMaterialDefaults.u_cellColor.clone(),
|
|
249
|
+
u_glowColor: hexGridMaterialDefaults.u_glowColor.clone(),
|
|
250
|
+
u_bgColor: hexGridMaterialDefaults.u_bgColor.clone(),
|
|
251
|
+
u_bgOpacity: hexGridMaterialDefaults.u_bgOpacity,
|
|
252
|
+
u_lineMode: hexGridMaterialDefaults.u_lineMode,
|
|
253
|
+
u_cellMode: hexGridMaterialDefaults.u_cellMode,
|
|
254
|
+
u_animSpeed: hexGridMaterialDefaults.u_animSpeed,
|
|
255
|
+
u_animScale: hexGridMaterialDefaults.u_animScale,
|
|
256
|
+
u_animIntensity: hexGridMaterialDefaults.u_animIntensity,
|
|
257
|
+
u_fadeDistance: hexGridMaterialDefaults.u_fadeDistance,
|
|
258
|
+
u_fadeStrength: hexGridMaterialDefaults.u_fadeStrength,
|
|
259
|
+
u_focus: hexGridMaterialDefaults.u_focus.clone(),
|
|
260
|
+
u_mouse: hexGridMaterialDefaults.u_mouse.clone(),
|
|
261
|
+
u_displace: hexGridMaterialDefaults.u_displace,
|
|
262
|
+
u_reveal: hexGridMaterialDefaults.u_reveal,
|
|
263
|
+
u_plateau: hexGridMaterialDefaults.u_plateau,
|
|
264
|
+
}, vertex, fragment);
|
|
265
|
+
extend({ HexGridMaterial });
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
export interface MoireGridMaterialUniforms {
|
|
3
|
+
u_time: number;
|
|
4
|
+
/** base lattice spacing, in world units */
|
|
5
|
+
u_cellSize: number;
|
|
6
|
+
/** line thickness, in pixels */
|
|
7
|
+
u_lineWidth: number;
|
|
8
|
+
/** spacing of the beat lattice drawn over the interference (square shape only) */
|
|
9
|
+
u_sectionSize: number;
|
|
10
|
+
/** beat-lattice thickness, in pixels; 0 hides it */
|
|
11
|
+
u_sectionWidth: number;
|
|
12
|
+
u_lineColor: THREE.Color;
|
|
13
|
+
u_sectionColor: THREE.Color;
|
|
14
|
+
u_cellColor: THREE.Color;
|
|
15
|
+
u_glowColor: THREE.Color;
|
|
16
|
+
u_bgColor: THREE.Color;
|
|
17
|
+
u_bgOpacity: number;
|
|
18
|
+
u_lineMode: number;
|
|
19
|
+
u_cellMode: number;
|
|
20
|
+
u_animSpeed: number;
|
|
21
|
+
u_animScale: number;
|
|
22
|
+
u_animIntensity: number;
|
|
23
|
+
u_fadeDistance: number;
|
|
24
|
+
u_fadeStrength: number;
|
|
25
|
+
u_focus: THREE.Vector2;
|
|
26
|
+
u_mouse: THREE.Vector2;
|
|
27
|
+
u_displace: number;
|
|
28
|
+
/**
|
|
29
|
+
* 0..1 assemble/dissolve. The build boundary sweeps outward from u_focus
|
|
30
|
+
* with a bright leading edge; 1 is fully built, 0 is gone. Animate it
|
|
31
|
+
* downward to dissolve.
|
|
32
|
+
*/
|
|
33
|
+
u_reveal: number;
|
|
34
|
+
/** lattice shape for both layers: 0 square, 1 hex, 2 concentric rings */
|
|
35
|
+
u_shape: number;
|
|
36
|
+
/** fixed angle between the two layers, in radians */
|
|
37
|
+
u_layerAngle: number;
|
|
38
|
+
/** spacing ratio of the second layer; near 1 gives long, slow beats */
|
|
39
|
+
u_layerScale: number;
|
|
40
|
+
/** counter-rotation speed; 0 freezes the pattern at u_layerAngle */
|
|
41
|
+
u_spin: number;
|
|
42
|
+
}
|
|
43
|
+
declare module '@react-three/fiber' {
|
|
44
|
+
interface ThreeElements {
|
|
45
|
+
moireGridMaterial: ThreeElements['shaderMaterial'] & Partial<MoireGridMaterialUniforms>;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export declare const moireGridMaterialDefaults: MoireGridMaterialUniforms;
|
|
49
|
+
export declare const MoireGridMaterial: 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_shape: number;
|
|
73
|
+
u_layerAngle: number;
|
|
74
|
+
u_layerScale: number;
|
|
75
|
+
u_spin: number;
|
|
76
|
+
}> & {
|
|
77
|
+
key: string;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=MoireGridMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoireGridMaterial.d.ts","sourceRoot":"","sources":["../../src/shaders/MoireGridMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,WAAW,yBAAyB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,aAAa,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,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;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,OAAO,QAAQ,oBAAoB,CAAC;IAChC,UAAU,aAAa;QACnB,iBAAiB,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;KAC3F;CACJ;AAED,eAAO,MAAM,yBAAyB,EAAE,yBA2BvC,CAAC;AAwNF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+B7B,CAAC"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { shaderMaterial } from '@react-three/drei';
|
|
3
|
+
import { extend } from '@react-three/fiber';
|
|
4
|
+
export const moireGridMaterialDefaults = {
|
|
5
|
+
u_time: 0,
|
|
6
|
+
u_cellSize: 2.8,
|
|
7
|
+
u_lineWidth: 1.4,
|
|
8
|
+
u_sectionSize: 12.0,
|
|
9
|
+
u_sectionWidth: 0.0,
|
|
10
|
+
u_lineColor: new THREE.Color(0.13, 0.42, 0.85),
|
|
11
|
+
u_sectionColor: new THREE.Color(0.95, 0.35, 0.62),
|
|
12
|
+
u_cellColor: new THREE.Color(0.05, 0.1, 0.25),
|
|
13
|
+
u_glowColor: new THREE.Color(0.6, 0.85, 1.0),
|
|
14
|
+
u_bgColor: new THREE.Color(0.01, 0.02, 0.05),
|
|
15
|
+
u_bgOpacity: 0.0,
|
|
16
|
+
u_lineMode: 0,
|
|
17
|
+
u_cellMode: 2,
|
|
18
|
+
u_animSpeed: 1.0,
|
|
19
|
+
u_animScale: 1.0,
|
|
20
|
+
u_animIntensity: 1.0,
|
|
21
|
+
u_fadeDistance: 25.0,
|
|
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.0,
|
|
26
|
+
u_reveal: 1.0,
|
|
27
|
+
u_shape: 0.0,
|
|
28
|
+
u_layerAngle: 0.05,
|
|
29
|
+
u_layerScale: 1.06,
|
|
30
|
+
u_spin: 1.0,
|
|
31
|
+
};
|
|
32
|
+
const moireCommon = /*glsl*/ `
|
|
33
|
+
const float TAU = 6.28318530718;
|
|
34
|
+
const vec2 HEX_R = vec2(1.0, 1.73205081);
|
|
35
|
+
|
|
36
|
+
float hash21(vec2 p){
|
|
37
|
+
p = fract(p * vec2(123.34, 456.21));
|
|
38
|
+
p += dot(p, p + 45.32);
|
|
39
|
+
return fract(p.x * p.y);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
vec2 rot2(vec2 p, float a){
|
|
43
|
+
float c = cos(a), s = sin(a);
|
|
44
|
+
return vec2(p.x * c - p.y * s, p.x * s + p.y * c);
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
const vertex = /*glsl*/ `
|
|
48
|
+
uniform float u_time;
|
|
49
|
+
uniform float u_cellSize;
|
|
50
|
+
uniform float u_displace;
|
|
51
|
+
uniform float u_animSpeed;
|
|
52
|
+
uniform float u_animScale;
|
|
53
|
+
|
|
54
|
+
varying vec2 vGridPos;
|
|
55
|
+
|
|
56
|
+
${moireCommon}
|
|
57
|
+
|
|
58
|
+
void main(){
|
|
59
|
+
vGridPos = position.xy;
|
|
60
|
+
vec3 pos = position;
|
|
61
|
+
if (u_displace > 0.0){
|
|
62
|
+
float t = u_time * u_animSpeed;
|
|
63
|
+
float d = length(position.xy) / max(u_cellSize, 1e-4);
|
|
64
|
+
pos.z += sin(d * u_animScale - t) * u_displace;
|
|
65
|
+
}
|
|
66
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
const fragment = /*glsl*/ `
|
|
70
|
+
precision highp float;
|
|
71
|
+
|
|
72
|
+
uniform float u_time;
|
|
73
|
+
uniform float u_cellSize;
|
|
74
|
+
uniform float u_lineWidth;
|
|
75
|
+
uniform float u_sectionSize;
|
|
76
|
+
uniform float u_sectionWidth;
|
|
77
|
+
uniform vec3 u_lineColor;
|
|
78
|
+
uniform vec3 u_sectionColor;
|
|
79
|
+
uniform vec3 u_cellColor;
|
|
80
|
+
uniform vec3 u_glowColor;
|
|
81
|
+
uniform vec3 u_bgColor;
|
|
82
|
+
uniform float u_bgOpacity;
|
|
83
|
+
uniform float u_lineMode;
|
|
84
|
+
uniform float u_cellMode;
|
|
85
|
+
uniform float u_animSpeed;
|
|
86
|
+
uniform float u_animScale;
|
|
87
|
+
uniform float u_animIntensity;
|
|
88
|
+
uniform float u_fadeDistance;
|
|
89
|
+
uniform float u_fadeStrength;
|
|
90
|
+
uniform vec2 u_focus;
|
|
91
|
+
uniform float u_reveal;
|
|
92
|
+
uniform float u_shape;
|
|
93
|
+
uniform float u_layerAngle;
|
|
94
|
+
uniform float u_layerScale;
|
|
95
|
+
uniform float u_spin;
|
|
96
|
+
|
|
97
|
+
varying vec2 vGridPos;
|
|
98
|
+
|
|
99
|
+
${moireCommon}
|
|
100
|
+
|
|
101
|
+
float hexDist(vec2 p){
|
|
102
|
+
p = abs(p);
|
|
103
|
+
return max(dot(p, normalize(HEX_R)), p.x);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
vec2 hexLocal(vec2 p){
|
|
107
|
+
vec2 h = HEX_R * 0.5;
|
|
108
|
+
vec2 a = mod(p, HEX_R) - h;
|
|
109
|
+
vec2 b = mod(p - h, HEX_R) - h;
|
|
110
|
+
return dot(a, a) < dot(b, b) ? a : b;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
float squareLattice(vec2 c, float width){
|
|
114
|
+
vec2 d = fwidth(c);
|
|
115
|
+
vec2 g = abs(fract(c - 0.5) - 0.5) / max(d * width, 1e-5);
|
|
116
|
+
return 1.0 - clamp(min(g.x, g.y), 0.0, 1.0);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
float hexLattice(vec2 c, float width){
|
|
120
|
+
float px = max(length(fwidth(c)), 1e-6);
|
|
121
|
+
float d = 0.5 - hexDist(hexLocal(c));
|
|
122
|
+
return 1.0 - smoothstep(0.0, px * max(width, 0.05), d);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
float ringLattice(vec2 c, float width){
|
|
126
|
+
float r = length(c);
|
|
127
|
+
float fp = max(fwidth(r), 1e-6);
|
|
128
|
+
float d = abs(fract(r - 0.5) - 0.5);
|
|
129
|
+
return 1.0 - clamp(d / max(fp * max(width, 0.05), 1e-6), 0.0, 1.0);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** one layer, in whichever shape u_shape selects */
|
|
133
|
+
float layer(vec2 c, float width){
|
|
134
|
+
if (u_shape < 0.5) return squareLattice(c, width);
|
|
135
|
+
if (u_shape < 1.5) return hexLattice(c, width);
|
|
136
|
+
return ringLattice(c, width);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void main(){
|
|
140
|
+
vec2 coord = vGridPos / max(u_cellSize, 1e-4);
|
|
141
|
+
vec2 focus = u_focus / max(u_cellSize, 1e-4);
|
|
142
|
+
float t = u_time * u_animSpeed;
|
|
143
|
+
|
|
144
|
+
// Two lattices, counter-rotated by half the layer angle each. The
|
|
145
|
+
// interference is not drawn — it emerges from where the two line sets
|
|
146
|
+
// nearly coincide, which is what makes the beat pattern read as physical.
|
|
147
|
+
// The angle oscillates rather than accumulating. A steadily growing offset
|
|
148
|
+
// leaves the small-angle regime within seconds and never comes back, and
|
|
149
|
+
// the wide-angle cross-hatch it lands in is the least interesting part of
|
|
150
|
+
// the range; swinging keeps it cycling through the long, slow beats.
|
|
151
|
+
float spin = u_spin * sin(t * 0.04 * u_animScale) * 0.10;
|
|
152
|
+
float a1 = u_layerAngle * 0.5 + spin;
|
|
153
|
+
float a2 = -u_layerAngle * 0.5 - spin;
|
|
154
|
+
|
|
155
|
+
// Rings have no orientation, so for that shape the two layers are offset
|
|
156
|
+
// from each other instead of rotated — otherwise they would sit identical.
|
|
157
|
+
vec2 cA = u_shape < 1.5 ? rot2(coord, a1) : coord - vec2(u_layerAngle, 0.0) * 4.0;
|
|
158
|
+
vec2 cB = (u_shape < 1.5 ? rot2(coord, a2) : coord + vec2(u_layerAngle, 0.0) * 4.0)
|
|
159
|
+
/ max(u_layerScale, 1e-3);
|
|
160
|
+
|
|
161
|
+
float A = layer(cA, u_lineWidth);
|
|
162
|
+
float B = layer(cB, u_lineWidth);
|
|
163
|
+
float nodes = A * B; // both layers lit at once = an interference node
|
|
164
|
+
|
|
165
|
+
// The difference coordinate carries the beat frequency, so drawing a
|
|
166
|
+
// lattice on it draws the moire pattern itself rather than its symptom.
|
|
167
|
+
float beat = 0.0;
|
|
168
|
+
if (u_shape < 0.5 && u_sectionWidth > 0.0 && u_sectionSize > 0.0){
|
|
169
|
+
beat = squareLattice((cA - cB) / u_sectionSize, u_sectionWidth);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ---- line animation --------------------------------------------------
|
|
173
|
+
float lineAnim = 1.0;
|
|
174
|
+
if (u_lineMode > 0.5 && u_lineMode < 1.5){
|
|
175
|
+
lineAnim = 0.5 + 0.5 * sin(length(coord - focus) * u_animScale - t);
|
|
176
|
+
} else if (u_lineMode < 2.5){
|
|
177
|
+
lineAnim = 0.5 + 0.5 * sin(dot(coord, vec2(0.5, 0.5)) * u_animScale - t);
|
|
178
|
+
} else if (u_lineMode < 3.5){
|
|
179
|
+
float s = fract((coord.x + coord.y) * 0.05 * u_animScale - t * 0.15);
|
|
180
|
+
lineAnim = 0.25 + smoothstep(0.0, 0.15, s) * (1.0 - smoothstep(0.15, 0.35, s));
|
|
181
|
+
} else if (u_lineMode < 4.5){
|
|
182
|
+
lineAnim = 0.5 + 0.5 * sin(t);
|
|
183
|
+
}
|
|
184
|
+
lineAnim = mix(1.0, lineAnim, u_animIntensity);
|
|
185
|
+
|
|
186
|
+
// ---- node highlight --------------------------------------------------
|
|
187
|
+
float cell = 0.0;
|
|
188
|
+
if (u_cellMode > 0.5){
|
|
189
|
+
vec2 nid = floor(cA);
|
|
190
|
+
if (u_cellMode < 1.5){
|
|
191
|
+
cell = 0.5 + 0.5 * sin(dot(nid, vec2(0.7, 0.3)) * u_animScale - t);
|
|
192
|
+
} else if (u_cellMode < 2.5){
|
|
193
|
+
cell = 1.0; // steady: let the interference alone carry the motion
|
|
194
|
+
} else if (u_cellMode < 3.5){
|
|
195
|
+
cell = smoothstep(0.6, 1.0, sin(length(coord - focus) * u_animScale - t));
|
|
196
|
+
} else if (u_cellMode < 4.5){
|
|
197
|
+
cell = 0.5 + 0.5 * sin(t);
|
|
198
|
+
}
|
|
199
|
+
cell *= u_animIntensity;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
float r = length(vGridPos) / max(u_fadeDistance, 1e-4);
|
|
203
|
+
float fade = 1.0 - smoothstep(1.0 - u_fadeStrength, 1.0, r);
|
|
204
|
+
|
|
205
|
+
vec3 col = u_bgColor * u_bgOpacity;
|
|
206
|
+
float a = u_bgOpacity;
|
|
207
|
+
|
|
208
|
+
float Ai = A * lineAnim;
|
|
209
|
+
float Bi = B * lineAnim;
|
|
210
|
+
col += u_lineColor * Ai * 0.9; a = max(a, Ai * 0.9);
|
|
211
|
+
col += u_sectionColor * Bi * 0.9; a = max(a, Bi * 0.9);
|
|
212
|
+
|
|
213
|
+
float nodeI = nodes * cell;
|
|
214
|
+
col += u_glowColor * nodeI * 2.0; a = max(a, nodeI);
|
|
215
|
+
col += u_cellColor * nodes * 0.6;
|
|
216
|
+
|
|
217
|
+
float beatI = beat * lineAnim;
|
|
218
|
+
col += u_glowColor * beatI * 0.7; a = max(a, beatI * 0.7);
|
|
219
|
+
|
|
220
|
+
col *= fade;
|
|
221
|
+
a *= fade;
|
|
222
|
+
|
|
223
|
+
// ---- reveal ----------------------------------------------------------
|
|
224
|
+
// The build boundary sweeps outward from the focus point. Its leading band
|
|
225
|
+
// mostly brightens whatever is already there rather than painting a solid
|
|
226
|
+
// disc, so the grid reads as assembling itself rather than fading in.
|
|
227
|
+
if (u_reveal < 0.999){
|
|
228
|
+
float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
|
|
229
|
+
// 1.1, not 1.25: the boundary has to clear the fade radius by just the
|
|
230
|
+
// width of its own soft edge. Overshooting further finishes the build
|
|
231
|
+
// before reveal reaches 1 and leaves the tail of the range doing nothing.
|
|
232
|
+
float edge = u_reveal * 1.1;
|
|
233
|
+
float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
|
|
234
|
+
float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
|
|
235
|
+
col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
|
|
236
|
+
a = max(a * mask, front * 0.10);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (a < 0.002) discard;
|
|
240
|
+
gl_FragColor = vec4(col, a);
|
|
241
|
+
}
|
|
242
|
+
`;
|
|
243
|
+
export const MoireGridMaterial = shaderMaterial({
|
|
244
|
+
u_time: moireGridMaterialDefaults.u_time,
|
|
245
|
+
u_cellSize: moireGridMaterialDefaults.u_cellSize,
|
|
246
|
+
u_lineWidth: moireGridMaterialDefaults.u_lineWidth,
|
|
247
|
+
u_sectionSize: moireGridMaterialDefaults.u_sectionSize,
|
|
248
|
+
u_sectionWidth: moireGridMaterialDefaults.u_sectionWidth,
|
|
249
|
+
u_lineColor: moireGridMaterialDefaults.u_lineColor.clone(),
|
|
250
|
+
u_sectionColor: moireGridMaterialDefaults.u_sectionColor.clone(),
|
|
251
|
+
u_cellColor: moireGridMaterialDefaults.u_cellColor.clone(),
|
|
252
|
+
u_glowColor: moireGridMaterialDefaults.u_glowColor.clone(),
|
|
253
|
+
u_bgColor: moireGridMaterialDefaults.u_bgColor.clone(),
|
|
254
|
+
u_bgOpacity: moireGridMaterialDefaults.u_bgOpacity,
|
|
255
|
+
u_lineMode: moireGridMaterialDefaults.u_lineMode,
|
|
256
|
+
u_cellMode: moireGridMaterialDefaults.u_cellMode,
|
|
257
|
+
u_animSpeed: moireGridMaterialDefaults.u_animSpeed,
|
|
258
|
+
u_animScale: moireGridMaterialDefaults.u_animScale,
|
|
259
|
+
u_animIntensity: moireGridMaterialDefaults.u_animIntensity,
|
|
260
|
+
u_fadeDistance: moireGridMaterialDefaults.u_fadeDistance,
|
|
261
|
+
u_fadeStrength: moireGridMaterialDefaults.u_fadeStrength,
|
|
262
|
+
u_focus: moireGridMaterialDefaults.u_focus.clone(),
|
|
263
|
+
u_mouse: moireGridMaterialDefaults.u_mouse.clone(),
|
|
264
|
+
u_displace: moireGridMaterialDefaults.u_displace,
|
|
265
|
+
u_reveal: moireGridMaterialDefaults.u_reveal,
|
|
266
|
+
u_shape: moireGridMaterialDefaults.u_shape,
|
|
267
|
+
u_layerAngle: moireGridMaterialDefaults.u_layerAngle,
|
|
268
|
+
u_layerScale: moireGridMaterialDefaults.u_layerScale,
|
|
269
|
+
u_spin: moireGridMaterialDefaults.u_spin,
|
|
270
|
+
}, vertex, fragment);
|
|
271
|
+
extend({ MoireGridMaterial });
|
|
@@ -26,6 +26,12 @@ export interface MyGridMaterialUniforms {
|
|
|
26
26
|
u_mouse: THREE.Vector2;
|
|
27
27
|
/** vertex displacement amount along the plane normal (needs a segmented plane) */
|
|
28
28
|
u_displace: number;
|
|
29
|
+
/**
|
|
30
|
+
* 0..1 assemble/dissolve. The build boundary sweeps outward from u_focus
|
|
31
|
+
* with a bright leading edge; 1 is fully built, 0 is gone. Animate it
|
|
32
|
+
* downward to dissolve.
|
|
33
|
+
*/
|
|
34
|
+
u_reveal: number;
|
|
29
35
|
}
|
|
30
36
|
declare module '@react-three/fiber' {
|
|
31
37
|
interface ThreeElements {
|
|
@@ -55,6 +61,7 @@ export declare const MyGridMaterial: import("@react-three/fiber").ConstructorRep
|
|
|
55
61
|
u_focus: THREE.Vector2;
|
|
56
62
|
u_mouse: THREE.Vector2;
|
|
57
63
|
u_displace: number;
|
|
64
|
+
u_reveal: number;
|
|
58
65
|
}> & {
|
|
59
66
|
key: string;
|
|
60
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MyGridMaterial.d.ts","sourceRoot":"","sources":["../../src/shaders/MyGridMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACnC,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,+CAA+C;IAC/C,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;IACvB,+EAA+E;IAC/E,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;IACvB,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"MyGridMaterial.d.ts","sourceRoot":"","sources":["../../src/shaders/MyGridMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACnC,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,+CAA+C;IAC/C,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;IACvB,+EAA+E;IAC/E,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;IACvB,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,OAAO,QAAQ,oBAAoB,CAAC;IAChC,UAAU,aAAa;QACnB,cAAc,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;KACrF;CACJ;AAED,eAAO,MAAM,sBAAsB,EAAE,sBAuBpC,CAAC;AAgJF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;CAuBP,CAAC"}
|
|
@@ -23,6 +23,7 @@ export const myGridMaterialDefaults = {
|
|
|
23
23
|
u_focus: new THREE.Vector2(0, 0),
|
|
24
24
|
u_mouse: new THREE.Vector2(0, 0),
|
|
25
25
|
u_displace: 0.0,
|
|
26
|
+
u_reveal: 1.0,
|
|
26
27
|
};
|
|
27
28
|
const vertex = /*glsl*/ `
|
|
28
29
|
uniform float u_time;
|
|
@@ -70,6 +71,7 @@ const fragment = /*glsl*/ `
|
|
|
70
71
|
uniform float u_fadeDistance;
|
|
71
72
|
uniform float u_fadeStrength;
|
|
72
73
|
uniform vec2 u_focus;
|
|
74
|
+
uniform float u_reveal;
|
|
73
75
|
|
|
74
76
|
varying vec2 vGridPos;
|
|
75
77
|
|
|
@@ -146,6 +148,22 @@ const fragment = /*glsl*/ `
|
|
|
146
148
|
col *= fade;
|
|
147
149
|
a *= fade;
|
|
148
150
|
|
|
151
|
+
// ---- reveal ----------------------------------------------------------
|
|
152
|
+
// The build boundary sweeps outward from the focus point. Its leading band
|
|
153
|
+
// mostly brightens whatever is already there rather than painting a solid
|
|
154
|
+
// disc, so the grid reads as assembling itself rather than fading in.
|
|
155
|
+
if (u_reveal < 0.999){
|
|
156
|
+
float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
|
|
157
|
+
// 1.1, not 1.25: the boundary has to clear the fade radius by just the
|
|
158
|
+
// width of its own soft edge. Overshooting further finishes the build
|
|
159
|
+
// before reveal reaches 1 and leaves the tail of the range doing nothing.
|
|
160
|
+
float edge = u_reveal * 1.1;
|
|
161
|
+
float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
|
|
162
|
+
float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
|
|
163
|
+
col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
|
|
164
|
+
a = max(a * mask, front * 0.10);
|
|
165
|
+
}
|
|
166
|
+
|
|
149
167
|
if (a < 0.002) discard;
|
|
150
168
|
gl_FragColor = vec4(col, a);
|
|
151
169
|
}
|
|
@@ -172,5 +190,6 @@ export const MyGridMaterial = shaderMaterial({
|
|
|
172
190
|
u_focus: myGridMaterialDefaults.u_focus.clone(),
|
|
173
191
|
u_mouse: myGridMaterialDefaults.u_mouse.clone(),
|
|
174
192
|
u_displace: myGridMaterialDefaults.u_displace,
|
|
193
|
+
u_reveal: myGridMaterialDefaults.u_reveal,
|
|
175
194
|
}, vertex, fragment);
|
|
176
195
|
extend({ MyGridMaterial });
|