@3driseai/3drise-core 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/services/MaterialRegistry.d.ts +25 -0
  2. package/dist/services/MaterialRegistry.d.ts.map +1 -1
  3. package/dist/services/MaterialRegistry.js +102 -1
  4. package/dist/shaders/CircuitGridMaterial.d.ts +76 -0
  5. package/dist/shaders/CircuitGridMaterial.d.ts.map +1 -0
  6. package/dist/shaders/CircuitGridMaterial.js +298 -0
  7. package/dist/shaders/ContourGridMaterial.d.ts +80 -0
  8. package/dist/shaders/ContourGridMaterial.d.ts.map +1 -0
  9. package/dist/shaders/ContourGridMaterial.js +259 -0
  10. package/dist/shaders/FractalGridMaterial.d.ts +76 -0
  11. package/dist/shaders/FractalGridMaterial.d.ts.map +1 -0
  12. package/dist/shaders/FractalGridMaterial.js +247 -0
  13. package/dist/shaders/HexGridMaterial.d.ts +73 -0
  14. package/dist/shaders/HexGridMaterial.d.ts.map +1 -0
  15. package/dist/shaders/HexGridMaterial.js +265 -0
  16. package/dist/shaders/MoireGridMaterial.d.ts +79 -0
  17. package/dist/shaders/MoireGridMaterial.d.ts.map +1 -0
  18. package/dist/shaders/MoireGridMaterial.js +271 -0
  19. package/dist/shaders/MyGridMaterial.d.ts +7 -0
  20. package/dist/shaders/MyGridMaterial.d.ts.map +1 -1
  21. package/dist/shaders/MyGridMaterial.js +19 -0
  22. package/dist/shaders/QuasiGridMaterial.d.ts +76 -0
  23. package/dist/shaders/QuasiGridMaterial.d.ts.map +1 -0
  24. package/dist/shaders/QuasiGridMaterial.js +238 -0
  25. package/dist/shaders/RadarGridMaterial.d.ts +77 -0
  26. package/dist/shaders/RadarGridMaterial.d.ts.map +1 -0
  27. package/dist/shaders/RadarGridMaterial.js +291 -0
  28. package/dist/shaders/RainMaterial copy.d.ts +34 -0
  29. package/dist/shaders/RainMaterial copy.d.ts.map +1 -0
  30. package/dist/shaders/RainMaterial copy.js +56 -0
  31. package/dist/shaders/ShaderEffectsMaterial copy 2.d.ts +228 -0
  32. package/dist/shaders/ShaderEffectsMaterial copy 2.d.ts.map +1 -0
  33. package/dist/shaders/ShaderEffectsMaterial copy 2.js +233 -0
  34. package/dist/shaders/ShootingStarMaterial copy.d.ts +14 -0
  35. package/dist/shaders/ShootingStarMaterial copy.d.ts.map +1 -0
  36. package/dist/shaders/ShootingStarMaterial copy.js +33 -0
  37. package/dist/shaders/SkyboxMaterial copy.d.ts +38 -0
  38. package/dist/shaders/SkyboxMaterial copy.d.ts.map +1 -0
  39. package/dist/shaders/SkyboxMaterial copy.js +57 -0
  40. package/dist/shaders/VoronoiGridMaterial.d.ts +73 -0
  41. package/dist/shaders/VoronoiGridMaterial.d.ts.map +1 -0
  42. package/dist/shaders/VoronoiGridMaterial.js +266 -0
  43. package/dist/types/objectsConfigs.d.ts +12 -0
  44. package/dist/types/objectsConfigs.d.ts.map +1 -1
  45. package/package.json +1 -1
@@ -0,0 +1,76 @@
1
+ import * as THREE from 'three';
2
+ export interface QuasiGridMaterialUniforms {
3
+ u_time: number;
4
+ /** spacing between the lines of each family, in world units */
5
+ u_cellSize: number;
6
+ /** line thickness, in pixels */
7
+ u_lineWidth: number;
8
+ /** every Nth line of each family is an accent line */
9
+ u_sectionSize: number;
10
+ /** accent thickness, in pixels; 0 disables the layer */
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
+ /**
35
+ * How many line families, 3..9. 5 is Penrose. 4 and 6 divide the half-turn
36
+ * evenly and so come out periodic; everything else is quasiperiodic.
37
+ */
38
+ u_symmetry: number;
39
+ /** shifts every family's offset together, sliding the pattern through itself */
40
+ u_phase: number;
41
+ }
42
+ declare module '@react-three/fiber' {
43
+ interface ThreeElements {
44
+ quasiGridMaterial: ThreeElements['shaderMaterial'] & Partial<QuasiGridMaterialUniforms>;
45
+ }
46
+ }
47
+ export declare const quasiGridMaterialDefaults: QuasiGridMaterialUniforms;
48
+ export declare const QuasiGridMaterial: import("@react-three/fiber").ConstructorRepresentation<THREE.ShaderMaterial & {
49
+ u_time: number;
50
+ u_cellSize: number;
51
+ u_lineWidth: number;
52
+ u_sectionSize: number;
53
+ u_sectionWidth: number;
54
+ u_lineColor: THREE.Color;
55
+ u_sectionColor: THREE.Color;
56
+ u_cellColor: THREE.Color;
57
+ u_glowColor: THREE.Color;
58
+ u_bgColor: THREE.Color;
59
+ u_bgOpacity: number;
60
+ u_lineMode: number;
61
+ u_cellMode: number;
62
+ u_animSpeed: number;
63
+ u_animScale: number;
64
+ u_animIntensity: number;
65
+ u_fadeDistance: number;
66
+ u_fadeStrength: number;
67
+ u_focus: THREE.Vector2;
68
+ u_mouse: THREE.Vector2;
69
+ u_displace: number;
70
+ u_reveal: number;
71
+ u_symmetry: number;
72
+ u_phase: number;
73
+ }> & {
74
+ key: string;
75
+ };
76
+ //# sourceMappingURL=QuasiGridMaterial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuasiGridMaterial.d.ts","sourceRoot":"","sources":["../../src/shaders/QuasiGridMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,WAAW,yBAAyB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,aAAa,EAAE,MAAM,CAAC;IACtB,wDAAwD;IACxD,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;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;CACnB;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,yBAyBvC,CAAC;AA2LF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B7B,CAAC"}
@@ -0,0 +1,238 @@
1
+ import * as THREE from 'three';
2
+ import { shaderMaterial } from '@react-three/drei';
3
+ import { extend } from '@react-three/fiber';
4
+ export const quasiGridMaterialDefaults = {
5
+ u_time: 0,
6
+ u_cellSize: 3.0,
7
+ u_lineWidth: 1.2,
8
+ u_sectionSize: 5.0,
9
+ u_sectionWidth: 2.0,
10
+ u_lineColor: new THREE.Color(0.55, 0.3, 0.12),
11
+ u_sectionColor: new THREE.Color(1.0, 0.78, 0.35),
12
+ u_cellColor: new THREE.Color(0.22, 0.1, 0.03),
13
+ u_glowColor: new THREE.Color(1.0, 0.65, 0.25),
14
+ u_bgColor: new THREE.Color(0.05, 0.02, 0.01),
15
+ u_bgOpacity: 0.0,
16
+ u_lineMode: 1,
17
+ u_cellMode: 2,
18
+ u_animSpeed: 1.0,
19
+ u_animScale: 0.5,
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_symmetry: 5.0,
28
+ u_phase: 0.2,
29
+ };
30
+ const quasiCommon = /*glsl*/ `
31
+ const float PI = 3.14159265359;
32
+ const float TAU = 6.28318530718;
33
+
34
+ float hash21(vec2 p){
35
+ p = fract(p * vec2(123.34, 456.21));
36
+ p += dot(p, p + 45.32);
37
+ return fract(p.x * p.y);
38
+ }
39
+ `;
40
+ const vertex = /*glsl*/ `
41
+ uniform float u_time;
42
+ uniform float u_cellSize;
43
+ uniform float u_displace;
44
+ uniform float u_animSpeed;
45
+ uniform float u_animScale;
46
+
47
+ varying vec2 vGridPos;
48
+
49
+ ${quasiCommon}
50
+
51
+ void main(){
52
+ vGridPos = position.xy;
53
+ vec3 pos = position;
54
+ if (u_displace > 0.0){
55
+ float t = u_time * u_animSpeed;
56
+ float d = length(position.xy) / max(u_cellSize, 1e-4);
57
+ pos.z += sin(d * u_animScale - t) * u_displace;
58
+ }
59
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
60
+ }
61
+ `;
62
+ const fragment = /*glsl*/ `
63
+ precision highp float;
64
+
65
+ uniform float u_time;
66
+ uniform float u_cellSize;
67
+ uniform float u_lineWidth;
68
+ uniform float u_sectionSize;
69
+ uniform float u_sectionWidth;
70
+ uniform vec3 u_lineColor;
71
+ uniform vec3 u_sectionColor;
72
+ uniform vec3 u_cellColor;
73
+ uniform vec3 u_glowColor;
74
+ uniform vec3 u_bgColor;
75
+ uniform float u_bgOpacity;
76
+ uniform float u_lineMode;
77
+ uniform float u_cellMode;
78
+ uniform float u_animSpeed;
79
+ uniform float u_animScale;
80
+ uniform float u_animIntensity;
81
+ uniform float u_fadeDistance;
82
+ uniform float u_fadeStrength;
83
+ uniform vec2 u_focus;
84
+ uniform float u_reveal;
85
+ uniform float u_symmetry;
86
+ uniform float u_phase;
87
+
88
+ varying vec2 vGridPos;
89
+
90
+ ${quasiCommon}
91
+
92
+ float lineAt(float c, float width, float fp){
93
+ float d = abs(fract(c - 0.5) - 0.5);
94
+ return 1.0 - clamp(d / max(fp * max(width, 0.05), 1e-6), 0.0, 1.0);
95
+ }
96
+
97
+ void main(){
98
+ vec2 coord = vGridPos / max(u_cellSize, 1e-4);
99
+ vec2 focus = u_focus / max(u_cellSize, 1e-4);
100
+ float t = u_time * u_animSpeed;
101
+
102
+ // de Bruijn's multigrid: N families of evenly spaced parallel lines, spread
103
+ // over a half turn. Where the angles do not divide the half turn evenly the
104
+ // intersections never repeat, so the tiling is genuinely aperiodic — pan as
105
+ // far as you like and the pattern never comes back around.
106
+ float n = clamp(u_symmetry, 3.0, 9.0);
107
+
108
+ float lines = 0.0;
109
+ float accent = 0.0;
110
+ float dmin = 1e9; // distance to the nearest line, in line-spacing units
111
+ float idAcc = 0.0; // the cell's integer coordinates, folded into one number
112
+ vec2 cpos = vec2(0.0);
113
+
114
+ for (int j = 0; j < 9; j++){
115
+ float fj = float(j);
116
+ float on = step(fj, n - 0.5);
117
+
118
+ float ang = PI * fj / n;
119
+ vec2 e = vec2(cos(ang), sin(ang));
120
+ float d = dot(coord, e) + u_phase + fj * 0.2;
121
+ float fp = max(fwidth(d), 1e-6);
122
+
123
+ lines = max(lines, lineAt(d, u_lineWidth, fp) * on);
124
+
125
+ if (u_sectionWidth > 0.0 && u_sectionSize > 0.0){
126
+ float md = d / u_sectionSize;
127
+ accent = max(accent, lineAt(md, u_sectionWidth, max(fwidth(md), 1e-6)) * on);
128
+ }
129
+
130
+ float k = floor(d);
131
+ idAcc += on * k * (1.0 + fj * 7.13);
132
+ cpos += on * (k + 0.5) * e;
133
+
134
+ float fr = fract(d);
135
+ dmin = min(dmin, mix(1e9, min(fr, 1.0 - fr), on));
136
+ }
137
+
138
+ // Summing dot(p, e_j) * e_j over evenly spread directions returns n/2 times
139
+ // the original point, so scaling by 2/n puts the cell centre back into the
140
+ // same units as coord and the ripple distances stay meaningful.
141
+ vec2 cellPos = cpos * (2.0 / n);
142
+ float cellH = hash21(vec2(idAcc * 0.137, idAcc * 0.041 + 7.7));
143
+
144
+ // ---- line animation --------------------------------------------------
145
+ float lineAnim = 1.0;
146
+ if (u_lineMode > 0.5 && u_lineMode < 1.5){
147
+ lineAnim = 0.5 + 0.5 * sin(length(cellPos - focus) * u_animScale - t);
148
+ } else if (u_lineMode < 2.5){
149
+ lineAnim = 0.5 + 0.5 * sin(dot(cellPos, vec2(0.5, 0.5)) * u_animScale - t);
150
+ } else if (u_lineMode < 3.5){
151
+ float s = fract((coord.x + coord.y) * 0.05 * u_animScale - t * 0.15);
152
+ lineAnim = 0.25 + smoothstep(0.0, 0.15, s) * (1.0 - smoothstep(0.15, 0.35, s));
153
+ } else if (u_lineMode < 4.5){
154
+ lineAnim = 0.5 + 0.5 * sin(t);
155
+ }
156
+ lineAnim = mix(1.0, lineAnim, u_animIntensity);
157
+
158
+ // ---- rhomb fill ------------------------------------------------------
159
+ float cell = 0.0;
160
+ if (u_cellMode > 0.5 && u_cellMode < 1.5){
161
+ cell = 0.5 + 0.5 * sin(idAcc * 0.05 * u_animScale - t);
162
+ } else if (u_cellMode < 2.5){
163
+ cell = 0.5 + 0.5 * sin(t * (0.6 + cellH) + cellH * TAU);
164
+ } else if (u_cellMode < 3.5){
165
+ cell = smoothstep(0.6, 1.0, sin(length(cellPos - focus) * u_animScale - t));
166
+ } else if (u_cellMode < 4.5){
167
+ cell = step(0.5, cellH) * (0.5 + 0.5 * sin(t));
168
+ }
169
+ cell *= u_animIntensity;
170
+ cell *= smoothstep(0.0, 0.16, dmin); // keep the fill off its own edges
171
+
172
+ // two rhomb tones, the fat/thin split a Penrose tiling reads by
173
+ float tone = step(0.55, cellH);
174
+
175
+ float r = length(vGridPos) / max(u_fadeDistance, 1e-4);
176
+ float fade = 1.0 - smoothstep(1.0 - u_fadeStrength, 1.0, r);
177
+
178
+ vec3 col = u_bgColor * u_bgOpacity;
179
+ float a = u_bgOpacity;
180
+
181
+ col += mix(u_cellColor, u_cellColor * 2.2, tone) * cell;
182
+ a = max(a, cell * 0.9);
183
+ float linesI = lines * lineAnim;
184
+ col += u_lineColor * linesI; a = max(a, linesI);
185
+ float accentI = accent * lineAnim;
186
+ col += u_sectionColor * accentI; a = max(a, accentI);
187
+ col += u_glowColor * (linesI * 0.2 + cell * 0.35) * u_animIntensity;
188
+
189
+ col *= fade;
190
+ a *= fade;
191
+
192
+ // ---- reveal ----------------------------------------------------------
193
+ // The build boundary sweeps outward from the focus point. Its leading band
194
+ // mostly brightens whatever is already there rather than painting a solid
195
+ // disc, so the grid reads as assembling itself rather than fading in.
196
+ if (u_reveal < 0.999){
197
+ float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
198
+ // 1.1, not 1.25: the boundary has to clear the fade radius by just the
199
+ // width of its own soft edge. Overshooting further finishes the build
200
+ // before reveal reaches 1 and leaves the tail of the range doing nothing.
201
+ float edge = u_reveal * 1.1;
202
+ float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
203
+ float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
204
+ col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
205
+ a = max(a * mask, front * 0.10);
206
+ }
207
+
208
+ if (a < 0.002) discard;
209
+ gl_FragColor = vec4(col, a);
210
+ }
211
+ `;
212
+ export const QuasiGridMaterial = shaderMaterial({
213
+ u_time: quasiGridMaterialDefaults.u_time,
214
+ u_cellSize: quasiGridMaterialDefaults.u_cellSize,
215
+ u_lineWidth: quasiGridMaterialDefaults.u_lineWidth,
216
+ u_sectionSize: quasiGridMaterialDefaults.u_sectionSize,
217
+ u_sectionWidth: quasiGridMaterialDefaults.u_sectionWidth,
218
+ u_lineColor: quasiGridMaterialDefaults.u_lineColor.clone(),
219
+ u_sectionColor: quasiGridMaterialDefaults.u_sectionColor.clone(),
220
+ u_cellColor: quasiGridMaterialDefaults.u_cellColor.clone(),
221
+ u_glowColor: quasiGridMaterialDefaults.u_glowColor.clone(),
222
+ u_bgColor: quasiGridMaterialDefaults.u_bgColor.clone(),
223
+ u_bgOpacity: quasiGridMaterialDefaults.u_bgOpacity,
224
+ u_lineMode: quasiGridMaterialDefaults.u_lineMode,
225
+ u_cellMode: quasiGridMaterialDefaults.u_cellMode,
226
+ u_animSpeed: quasiGridMaterialDefaults.u_animSpeed,
227
+ u_animScale: quasiGridMaterialDefaults.u_animScale,
228
+ u_animIntensity: quasiGridMaterialDefaults.u_animIntensity,
229
+ u_fadeDistance: quasiGridMaterialDefaults.u_fadeDistance,
230
+ u_fadeStrength: quasiGridMaterialDefaults.u_fadeStrength,
231
+ u_focus: quasiGridMaterialDefaults.u_focus.clone(),
232
+ u_mouse: quasiGridMaterialDefaults.u_mouse.clone(),
233
+ u_displace: quasiGridMaterialDefaults.u_displace,
234
+ u_reveal: quasiGridMaterialDefaults.u_reveal,
235
+ u_symmetry: quasiGridMaterialDefaults.u_symmetry,
236
+ u_phase: quasiGridMaterialDefaults.u_phase,
237
+ }, vertex, fragment);
238
+ extend({ QuasiGridMaterial });
@@ -0,0 +1,77 @@
1
+ import * as THREE from 'three';
2
+ export interface RadarGridMaterialUniforms {
3
+ u_time: number;
4
+ /** spacing between rings, in world units */
5
+ u_cellSize: number;
6
+ /** ring/spoke thickness, in pixels */
7
+ u_lineWidth: number;
8
+ /** every Nth ring is drawn as a major ring */
9
+ u_sectionSize: number;
10
+ /** major-ring, bezel and crosshair thickness, in pixels; 0 hides them */
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
+ /** doubles as the disc radius — the surface is masked to it */
24
+ u_fadeDistance: number;
25
+ u_fadeStrength: number;
26
+ u_focus: THREE.Vector2;
27
+ u_mouse: THREE.Vector2;
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;
35
+ /** number of radial spokes; 0 disables them */
36
+ u_spokes: number;
37
+ /** angular length of the sweep trail, as a fraction of a turn; 0 disables the sweep */
38
+ u_sweepWidth: number;
39
+ /** 0..1 — chance that a ring/spoke sector holds a blip */
40
+ u_blipDensity: number;
41
+ }
42
+ declare module '@react-three/fiber' {
43
+ interface ThreeElements {
44
+ radarGridMaterial: ThreeElements['shaderMaterial'] & Partial<RadarGridMaterialUniforms>;
45
+ }
46
+ }
47
+ export declare const radarGridMaterialDefaults: RadarGridMaterialUniforms;
48
+ export declare const RadarGridMaterial: import("@react-three/fiber").ConstructorRepresentation<THREE.ShaderMaterial & {
49
+ u_time: number;
50
+ u_cellSize: number;
51
+ u_lineWidth: number;
52
+ u_sectionSize: number;
53
+ u_sectionWidth: number;
54
+ u_lineColor: THREE.Color;
55
+ u_sectionColor: THREE.Color;
56
+ u_cellColor: THREE.Color;
57
+ u_glowColor: THREE.Color;
58
+ u_bgColor: THREE.Color;
59
+ u_bgOpacity: number;
60
+ u_lineMode: number;
61
+ u_cellMode: number;
62
+ u_animSpeed: number;
63
+ u_animScale: number;
64
+ u_animIntensity: number;
65
+ u_fadeDistance: number;
66
+ u_fadeStrength: number;
67
+ u_focus: THREE.Vector2;
68
+ u_mouse: THREE.Vector2;
69
+ u_displace: number;
70
+ u_reveal: number;
71
+ u_spokes: number;
72
+ u_sweepWidth: number;
73
+ u_blipDensity: number;
74
+ }> & {
75
+ key: string;
76
+ };
77
+ //# sourceMappingURL=RadarGridMaterial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RadarGridMaterial.d.ts","sourceRoot":"","sources":["../../src/shaders/RadarGridMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,WAAW,yBAAyB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,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,+DAA+D;IAC/D,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,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,YAAY,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,aAAa,EAAE,MAAM,CAAC;CACzB;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,yBA0BvC,CAAC;AA8OF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8B7B,CAAC"}
@@ -0,0 +1,291 @@
1
+ import * as THREE from 'three';
2
+ import { shaderMaterial } from '@react-three/drei';
3
+ import { extend } from '@react-three/fiber';
4
+ export const radarGridMaterialDefaults = {
5
+ u_time: 0,
6
+ u_cellSize: 2.5,
7
+ u_lineWidth: 1.0,
8
+ u_sectionSize: 4.0,
9
+ u_sectionWidth: 1.8,
10
+ u_lineColor: new THREE.Color(0.1, 0.5, 0.34),
11
+ u_sectionColor: new THREE.Color(0.5, 1.0, 0.72),
12
+ u_cellColor: new THREE.Color(0.05, 0.2, 0.14),
13
+ u_glowColor: new THREE.Color(0.35, 1.0, 0.6),
14
+ u_bgColor: new THREE.Color(0.01, 0.05, 0.03),
15
+ u_bgOpacity: 0.25,
16
+ u_lineMode: 1,
17
+ u_cellMode: 0,
18
+ u_animSpeed: 1.0,
19
+ u_animScale: 0.5,
20
+ u_animIntensity: 1.0,
21
+ u_fadeDistance: 25.0,
22
+ u_fadeStrength: 0.25,
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_spokes: 24.0,
28
+ u_sweepWidth: 0.13,
29
+ u_blipDensity: 0.08,
30
+ };
31
+ const radarCommon = /*glsl*/ `
32
+ const float TAU = 6.28318530718;
33
+
34
+ vec2 hash22(vec2 p){
35
+ p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));
36
+ return fract(sin(p) * 43758.5453123);
37
+ }
38
+ `;
39
+ const vertex = /*glsl*/ `
40
+ uniform float u_time;
41
+ uniform float u_cellSize;
42
+ uniform float u_displace;
43
+ uniform float u_animSpeed;
44
+ uniform float u_animScale;
45
+
46
+ varying vec2 vGridPos;
47
+
48
+ ${radarCommon}
49
+
50
+ void main(){
51
+ vGridPos = position.xy;
52
+ vec3 pos = position;
53
+ if (u_displace > 0.0){
54
+ float t = u_time * u_animSpeed;
55
+ float d = length(position.xy) / max(u_cellSize, 1e-4);
56
+ pos.z += sin(d * u_animScale - t) * u_displace;
57
+ }
58
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
59
+ }
60
+ `;
61
+ const fragment = /*glsl*/ `
62
+ precision highp float;
63
+
64
+ uniform float u_time;
65
+ uniform float u_cellSize;
66
+ uniform float u_lineWidth;
67
+ uniform float u_sectionSize;
68
+ uniform float u_sectionWidth;
69
+ uniform vec3 u_lineColor;
70
+ uniform vec3 u_sectionColor;
71
+ uniform vec3 u_cellColor;
72
+ uniform vec3 u_glowColor;
73
+ uniform vec3 u_bgColor;
74
+ uniform float u_bgOpacity;
75
+ uniform float u_lineMode;
76
+ uniform float u_cellMode;
77
+ uniform float u_animSpeed;
78
+ uniform float u_animScale;
79
+ uniform float u_animIntensity;
80
+ uniform float u_fadeDistance;
81
+ uniform float u_fadeStrength;
82
+ uniform vec2 u_focus;
83
+ uniform float u_reveal;
84
+ uniform float u_spokes;
85
+ uniform float u_sweepWidth;
86
+ uniform float u_blipDensity;
87
+
88
+ varying vec2 vGridPos;
89
+
90
+ ${radarCommon}
91
+
92
+ /** antialiased line wherever c crosses an integer; fp = footprint of c */
93
+ float lineAt(float c, float width, float fp){
94
+ float d = abs(fract(c - 0.5) - 0.5);
95
+ return 1.0 - clamp(d / max(fp * max(width, 0.05), 1e-6), 0.0, 1.0);
96
+ }
97
+
98
+ void main(){
99
+ vec2 p = vGridPos;
100
+ float r = length(p);
101
+ float ang = atan(p.y, p.x);
102
+ float radius = max(u_fadeDistance, 1e-4);
103
+ float rn = r / radius;
104
+ float t = u_time * u_animSpeed;
105
+ float px = max(length(fwidth(p)), 1e-6);
106
+
107
+ // ---- rings -----------------------------------------------------------
108
+ float rc = r / max(u_cellSize, 1e-4);
109
+ float rings = lineAt(rc, u_lineWidth, max(fwidth(rc), 1e-6));
110
+
111
+ float major = 0.0;
112
+ if (u_sectionWidth > 0.0 && u_sectionSize > 0.0){
113
+ float mc = rc / u_sectionSize;
114
+ major = lineAt(mc, u_sectionWidth, max(fwidth(mc), 1e-6));
115
+ }
116
+
117
+ // ---- spokes ----------------------------------------------------------
118
+ // fwidth of an angle blows up at the atan seam and at the origin, so it is
119
+ // clamped and the spokes are faded out of the hub.
120
+ float sc = 0.0;
121
+ float spokes = 0.0;
122
+ if (u_spokes >= 1.0){
123
+ sc = (ang / TAU + 0.5) * u_spokes;
124
+ float spx = clamp(fwidth(sc), 1e-6, 0.3);
125
+ spokes = lineAt(sc, u_lineWidth, spx) * smoothstep(0.0, u_cellSize * 0.7, r);
126
+ }
127
+
128
+ // ---- sweep arm -------------------------------------------------------
129
+ float sweepA = t * 0.5;
130
+ float sweep = 0.0;
131
+ float sweepEdge = 0.0;
132
+ if (u_sweepWidth > 0.0){
133
+ float age = fract((sweepA - ang) / TAU); // 0 right at the arm, 1 just before it
134
+ sweep = exp(-age / max(u_sweepWidth, 1e-3));
135
+ sweepEdge = 1.0 - smoothstep(0.0, 0.006, age);
136
+ }
137
+
138
+ // ---- contact blips ---------------------------------------------------
139
+ float blip = 0.0;
140
+ if (u_blipDensity > 0.0 && u_spokes >= 1.0){
141
+ vec2 pid = floor(vec2(rc, sc));
142
+ vec2 hh = hash22(pid);
143
+ float br = (pid.x + 0.25 + 0.5 * hh.y) * u_cellSize;
144
+ if (hh.x < u_blipDensity && br > u_cellSize * 1.5 && br < radius * 0.97){
145
+ float bs = pid.y + 0.25 + 0.5 * fract(hh.y * 13.71);
146
+ float ba = (bs / u_spokes - 0.5) * TAU;
147
+ vec2 bp = vec2(cos(ba), sin(ba)) * br;
148
+ float bRad = u_cellSize * 0.07;
149
+ float dot0 = 1.0 - smoothstep(bRad, bRad + px * 2.0, length(p - bp));
150
+ // a contact glows when the arm crosses it, then decays until it returns
151
+ float age = fract((sweepA - ba) / TAU);
152
+ blip = dot0 * (u_sweepWidth > 0.0 ? exp(-age * 5.0) : 1.0);
153
+ }
154
+ }
155
+
156
+ // ---- ring / spoke animation -----------------------------------------
157
+ float lineAnim = 1.0;
158
+ float ping = 0.0;
159
+ if (u_lineMode > 0.5 && u_lineMode < 1.5){
160
+ // ping rings expanding from the focus point
161
+ float pd = length(p - u_focus);
162
+ for (int i = 0; i < 2; i++){
163
+ float phase = fract(t * 0.25 + float(i) * 0.5);
164
+ float pr = phase * radius;
165
+ ping += (1.0 - smoothstep(0.0, px * 2.0 + radius * 0.003, abs(pd - pr))) * (1.0 - phase);
166
+ }
167
+ } else if (u_lineMode < 2.5){
168
+ lineAnim = 0.4 + 0.6 * (0.5 + 0.5 * sin(rc * u_animScale - t));
169
+ } else if (u_lineMode < 3.5){
170
+ // spokes lighting in sequence, like a sector scan
171
+ float s = fract(sc / max(u_spokes, 1.0) - t * 0.12);
172
+ lineAnim = 0.3 + smoothstep(0.0, 0.1, s) * (1.0 - smoothstep(0.1, 0.3, s));
173
+ } else if (u_lineMode < 4.5){
174
+ lineAnim = 0.5 + 0.5 * sin(t);
175
+ }
176
+ lineAnim = mix(1.0, lineAnim, u_animIntensity);
177
+ ping *= u_animIntensity;
178
+
179
+ // ---- sector fill -----------------------------------------------------
180
+ float cell = 0.0;
181
+ if (u_cellMode > 0.5 && u_spokes >= 1.0){
182
+ vec2 pid = floor(vec2(rc, sc));
183
+ vec2 hh = hash22(pid);
184
+ if (u_cellMode < 1.5){
185
+ cell = 0.5 + 0.5 * sin(dot(pid, vec2(0.7, 0.3)) * u_animScale - t);
186
+ } else if (u_cellMode < 2.5){
187
+ cell = 0.5 + 0.5 * sin(t * (0.6 + hh.x) + hh.y * TAU);
188
+ } else if (u_cellMode < 3.5){
189
+ float d = length(p - u_focus) / max(u_cellSize, 1e-4);
190
+ cell = smoothstep(0.6, 1.0, sin(d * u_animScale - t));
191
+ } else if (u_cellMode < 4.5){
192
+ cell = mod(pid.x + pid.y, 2.0) * (0.5 + 0.5 * sin(t));
193
+ }
194
+ cell *= u_animIntensity;
195
+ float fr = abs(fract(rc) - 0.5);
196
+ float fs = abs(fract(sc) - 0.5);
197
+ cell *= smoothstep(0.5, 0.35, max(fr, fs));
198
+ }
199
+
200
+ // ---- bezel, crosshair, ticks ----------------------------------------
201
+ float bezel = 0.0, crosshair = 0.0, ticks = 0.0;
202
+ if (u_sectionWidth > 0.0){
203
+ float bw = max(px * u_sectionWidth * 1.5, 1e-6);
204
+ bezel = 1.0 - clamp(abs(r - radius * 0.99) / bw, 0.0, 1.0);
205
+
206
+ vec2 cd = abs(p) / max(px * u_sectionWidth, 1e-6);
207
+ crosshair = (1.0 - clamp(min(cd.x, cd.y), 0.0, 1.0)) * step(r, radius * 0.99);
208
+
209
+ float tc = (ang / TAU + 0.5) * 72.0;
210
+ ticks = lineAt(tc, 1.0, clamp(fwidth(tc), 1e-6, 0.3))
211
+ * smoothstep(radius * 0.93, radius * 0.955, r)
212
+ * (1.0 - smoothstep(radius * 0.975, radius * 0.99, r));
213
+ }
214
+
215
+ float fade = 1.0 - smoothstep(1.0 - u_fadeStrength, 1.0, rn);
216
+ float disc = 1.0 - smoothstep(0.995, 1.005, rn);
217
+
218
+ // ---- compose ---------------------------------------------------------
219
+ vec3 col = u_bgColor * u_bgOpacity;
220
+ float a = u_bgOpacity;
221
+
222
+ float ringI = rings * lineAnim;
223
+ float majorI = major * lineAnim;
224
+ float spokeI = spokes * lineAnim;
225
+
226
+ col += u_cellColor * cell; a = max(a, cell * 0.9);
227
+ col += u_lineColor * (ringI + spokeI); a = max(a, max(ringI, spokeI));
228
+ col += u_sectionColor * majorI; a = max(a, majorI);
229
+ col += u_glowColor * sweep * 0.55; a = max(a, sweep * 0.55);
230
+ col += u_sectionColor * sweepEdge * 1.2; a = max(a, sweepEdge);
231
+ col += u_glowColor * blip * 2.0; a = max(a, blip);
232
+ col += u_glowColor * ping * 1.4; a = max(a, ping);
233
+
234
+ col *= fade;
235
+ a *= fade;
236
+
237
+ // the instrument frame does not fade out with the field it contains
238
+ col += u_sectionColor * (bezel + ticks + crosshair * 0.55);
239
+ a = max(a, max(bezel, max(ticks, crosshair * 0.55)));
240
+
241
+ col *= disc;
242
+ a *= disc;
243
+
244
+ // ---- reveal ----------------------------------------------------------
245
+ // The build boundary sweeps outward from the focus point. Its leading band
246
+ // mostly brightens whatever is already there rather than painting a solid
247
+ // disc, so the grid reads as assembling itself rather than fading in.
248
+ if (u_reveal < 0.999){
249
+ float rd = length(vGridPos - u_focus) / max(u_fadeDistance, 1e-4);
250
+ // 1.1, not 1.25: the boundary has to clear the fade radius by just the
251
+ // width of its own soft edge. Overshooting further finishes the build
252
+ // before reveal reaches 1 and leaves the tail of the range doing nothing.
253
+ float edge = u_reveal * 1.1;
254
+ float mask = 1.0 - smoothstep(edge - 0.05, edge, rd);
255
+ float front = mask * smoothstep(edge - 0.22, edge - 0.05, rd);
256
+ col = col * mask + u_glowColor * front * (a * 1.8 + 0.08);
257
+ a = max(a * mask, front * 0.10);
258
+ }
259
+
260
+ if (a < 0.002) discard;
261
+ gl_FragColor = vec4(col, a);
262
+ }
263
+ `;
264
+ export const RadarGridMaterial = shaderMaterial({
265
+ u_time: radarGridMaterialDefaults.u_time,
266
+ u_cellSize: radarGridMaterialDefaults.u_cellSize,
267
+ u_lineWidth: radarGridMaterialDefaults.u_lineWidth,
268
+ u_sectionSize: radarGridMaterialDefaults.u_sectionSize,
269
+ u_sectionWidth: radarGridMaterialDefaults.u_sectionWidth,
270
+ u_lineColor: radarGridMaterialDefaults.u_lineColor.clone(),
271
+ u_sectionColor: radarGridMaterialDefaults.u_sectionColor.clone(),
272
+ u_cellColor: radarGridMaterialDefaults.u_cellColor.clone(),
273
+ u_glowColor: radarGridMaterialDefaults.u_glowColor.clone(),
274
+ u_bgColor: radarGridMaterialDefaults.u_bgColor.clone(),
275
+ u_bgOpacity: radarGridMaterialDefaults.u_bgOpacity,
276
+ u_lineMode: radarGridMaterialDefaults.u_lineMode,
277
+ u_cellMode: radarGridMaterialDefaults.u_cellMode,
278
+ u_animSpeed: radarGridMaterialDefaults.u_animSpeed,
279
+ u_animScale: radarGridMaterialDefaults.u_animScale,
280
+ u_animIntensity: radarGridMaterialDefaults.u_animIntensity,
281
+ u_fadeDistance: radarGridMaterialDefaults.u_fadeDistance,
282
+ u_fadeStrength: radarGridMaterialDefaults.u_fadeStrength,
283
+ u_focus: radarGridMaterialDefaults.u_focus.clone(),
284
+ u_mouse: radarGridMaterialDefaults.u_mouse.clone(),
285
+ u_displace: radarGridMaterialDefaults.u_displace,
286
+ u_reveal: radarGridMaterialDefaults.u_reveal,
287
+ u_spokes: radarGridMaterialDefaults.u_spokes,
288
+ u_sweepWidth: radarGridMaterialDefaults.u_sweepWidth,
289
+ u_blipDensity: radarGridMaterialDefaults.u_blipDensity,
290
+ }, vertex, fragment);
291
+ extend({ RadarGridMaterial });