@pinkaphant/kolmo 0.1.2 → 0.2.0

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 (130) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -14
  3. package/bin/kolmo.mjs +22 -54
  4. package/dist/body/HeldItem.js +171 -0
  5. package/dist/body/KhrBody.js +171 -0
  6. package/dist/body/bodySi.d.ts +0 -11
  7. package/dist/body/bodySi.js +52 -0
  8. package/dist/body/index.d.ts +1 -1
  9. package/dist/body/index.js +4 -1
  10. package/dist/engine/index.d.ts +4 -4
  11. package/dist/engine/index.js +12 -3
  12. package/dist/engine/kolmoActor.d.ts +11 -4
  13. package/dist/engine/kolmoActor.js +197 -0
  14. package/dist/engine/kolmoInput.d.ts +17 -0
  15. package/dist/engine/kolmoInput.js +78 -0
  16. package/dist/engine/kolmoIsland.d.ts +3 -1
  17. package/dist/engine/kolmoIsland.js +311 -0
  18. package/dist/engine/kolmoLongDrive.js +223 -0
  19. package/dist/engine/kolmoRigs.js +59 -0
  20. package/dist/engine/kolmoStore.d.ts +53 -27
  21. package/dist/engine/kolmoStore.js +211 -0
  22. package/dist/engine/kolmoSurface.d.ts +1 -1
  23. package/dist/engine/kolmoSurface.js +182 -0
  24. package/dist/engine/kolmoVehicle.d.ts +3 -1
  25. package/dist/engine/kolmoVehicle.js +250 -0
  26. package/dist/engine/kolmoVehicleDriver.d.ts +30 -0
  27. package/dist/engine/kolmoVehicleDriver.js +29 -0
  28. package/dist/engine/kolmoWorld.d.ts +7 -15
  29. package/dist/engine/kolmoWorld.js +139 -0
  30. package/dist/engine/longDriveKit.d.ts +4 -2
  31. package/dist/engine/longDriveKit.js +254 -0
  32. package/dist/engine/mainlandMacroCell.d.ts +3 -7
  33. package/dist/engine/mainlandMacroCell.js +247 -0
  34. package/dist/engine/shiftedFixedBody.d.ts +13 -0
  35. package/dist/engine/shiftedFixedBody.js +64 -0
  36. package/dist/importer/ChopShopPanel.js +465 -0
  37. package/dist/importer/DomainWorkshopPanel.d.ts +9 -4
  38. package/dist/importer/DomainWorkshopPanel.js +385 -0
  39. package/dist/importer/GateHudBar.js +312 -0
  40. package/dist/importer/GlbImportGate.js +250 -0
  41. package/dist/importer/ImperativeVehicleRig.js +336 -0
  42. package/dist/importer/ImporterPlinthUikitTags.js +112 -0
  43. package/dist/importer/Step1CalibrationPlinth.js +275 -0
  44. package/dist/importer/Step2UniversalPad.js +244 -0
  45. package/dist/importer/VfxEmitterPool.js +91 -0
  46. package/dist/importer/chopShopActions.d.ts +22 -2
  47. package/dist/importer/chopShopActions.js +232 -0
  48. package/dist/importer/gateStore.d.ts +1 -1
  49. package/dist/importer/gateStore.js +92 -0
  50. package/dist/importer/glbNormalizer.js +133 -0
  51. package/dist/importer/importerWebMcp.d.ts +17 -6
  52. package/dist/importer/importerWebMcp.js +343 -0
  53. package/dist/importer/index.js +22 -3
  54. package/dist/importer/khrCompiler.d.ts +1 -1
  55. package/dist/importer/khrCompiler.js +434 -0
  56. package/dist/importer/launcherBake.js +51 -0
  57. package/dist/importer/meshIslands.d.ts +1 -1
  58. package/dist/importer/meshIslands.js +301 -0
  59. package/dist/importer/surfaceCutter.js +254 -0
  60. package/dist/importer/surfaceTopology.js +183 -0
  61. package/dist/importer/universalGateBake.js +162 -0
  62. package/dist/importer/usdToGlb.js +294 -0
  63. package/dist/importer/useChopShopController.d.ts +11 -2
  64. package/dist/importer/useChopShopController.js +364 -0
  65. package/dist/importer/vehiclePanelAnim.js +214 -0
  66. package/dist/importer/wheelAxlePairing.d.ts +1 -2
  67. package/dist/importer/wheelAxlePairing.js +102 -0
  68. package/dist/index.d.ts +1 -1
  69. package/dist/index.js +69 -13
  70. package/dist/junk/DestructibleTarget.js +154 -0
  71. package/dist/junk/KolmoJunk.js +65 -0
  72. package/dist/junk/ShardPieces.d.ts +6 -4
  73. package/dist/junk/ShardPieces.js +74 -0
  74. package/dist/junk/TargetDecals.js +51 -0
  75. package/dist/junk/bvhShatter.js +55 -0
  76. package/dist/junk/bvhTriCollector.js +78 -0
  77. package/dist/junk/index.js +11 -1
  78. package/dist/junk/junkGeometry.js +69 -0
  79. package/dist/junk/junkImportSanitize.js +54 -0
  80. package/dist/junk/junkImporter.js +95 -0
  81. package/dist/junk/junkLabelCanvas.js +67 -0
  82. package/dist/junk/junkLabels.js +35 -0
  83. package/dist/junk/targetHelpers.js +103 -0
  84. package/dist/junk/targetHitLogic.js +128 -0
  85. package/dist/junk/useTargetAssets.js +102 -0
  86. package/dist/physics/index.d.ts +26 -0
  87. package/dist/physics/index.js +84 -0
  88. package/dist/schema/kolmoSchema.d.ts +2 -1
  89. package/dist/schema/kolmoSchema.js +184 -0
  90. package/dist/shaders/celestialBackdrop.d.ts +1 -1
  91. package/dist/shaders/celestialBackdrop.js +344 -0
  92. package/dist/shaders/index.d.ts +0 -1
  93. package/dist/shaders/index.js +9 -1
  94. package/dist/shaders/plumeAndSparkle.js +271 -0
  95. package/dist/shaders/ps2GlslShared.d.ts +1 -1
  96. package/dist/shaders/ps2GlslShared.js +3 -0
  97. package/dist/shaders/ps2MaterialsTSL.js +65 -0
  98. package/dist/shaders/ps2MaterialsWebGL.js +40 -0
  99. package/dist/shaders/ps2RoadWebGL.js +101 -0
  100. package/dist/shaders/ps2TerrainWebGL.js +54 -0
  101. package/dist/shaders/ps2Textures.js +224 -0
  102. package/dist/shaders/retroPalettes.js +188 -0
  103. package/dist/shaders/retroShader.d.ts +31 -3
  104. package/dist/shaders/retroShader.js +249 -0
  105. package/dist/shaders/tsl.d.ts +1 -0
  106. package/dist/shaders/tsl.js +1 -0
  107. package/dist/vite/index.d.ts +15 -0
  108. package/dist/vite/index.js +90 -0
  109. package/dist/world/frontage.js +32 -0
  110. package/dist/world/index.d.ts +1 -1
  111. package/dist/world/index.js +11 -3
  112. package/dist/world/infiniteWorld2D.js +244 -0
  113. package/dist/world/island.js +201 -0
  114. package/dist/world/macroCellSchema.js +27 -0
  115. package/dist/world/macroKnightAStar.js +171 -0
  116. package/dist/world/random.js +33 -0
  117. package/dist/world/road.js +136 -0
  118. package/dist/world/roadRibbon.d.ts +6 -6
  119. package/dist/world/roadRibbon.js +161 -0
  120. package/dist/world/terrain.js +87 -0
  121. package/dist/world/worldTypes.js +111 -0
  122. package/package.json +32 -18
  123. package/dist/body-B7FTf67o.js +0 -362
  124. package/dist/engine-BeKvBM8d.js +0 -1745
  125. package/dist/importer-B2-S-N_e.js +0 -5113
  126. package/dist/junk-B4bC1zAl.js +0 -1049
  127. package/dist/kolmoSurface-DTnrFXH0.js +0 -558
  128. package/dist/shaders-GS71Ek1A.js +0 -1383
  129. package/dist/world-PRWPYrlx.js +0 -947
  130. package/dist/worldTypes-Z0KfdCd0.js +0 -226
@@ -1,1383 +0,0 @@
1
- import { i as e, n as t } from "./worldTypes-Z0KfdCd0.js";
2
- import { useEffect as n, useMemo as r, useRef as i } from "react";
3
- import * as a from "three";
4
- import { useFrame as o } from "@react-three/fiber";
5
- import { Stars as s } from "@react-three/drei";
6
- import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
7
- import { BallCollider as d, RigidBody as f } from "@react-three/rapier";
8
- import * as p from "three/webgpu";
9
- import { Fn as m, abs as h, clamp as g, cos as _, exp as v, float as y, floor as b, fract as x, fwidth as S, max as C, mix as w, mod as T, output as E, positionWorld as D, pow as O, screenCoordinate as k, sin as ee, smoothstep as A, step as j, texture as M, uniform as N, uv as P, vec4 as F, vertexColor as I } from "three/tsl";
10
- // src/shaders/retroPalettes.ts
11
- var L = [
12
- {
13
- id: "off",
14
- label: "Off (24-bit)",
15
- shortLabel: "Off",
16
- description: "True 24-bit color"
17
- },
18
- {
19
- id: "rgb555",
20
- label: "RGB555 (32K)",
21
- shortLabel: "RGB555",
22
- description: "Dreamcast / PS1 15-bit"
23
- },
24
- {
25
- id: "rgb444",
26
- label: "RGB444 (4K)",
27
- shortLabel: "RGB444",
28
- description: "DSi / 12-bit crisp"
29
- },
30
- {
31
- id: "rgb332",
32
- label: "RGB332 (256)",
33
- shortLabel: "RGB332",
34
- description: "8-bit arcade quant"
35
- },
36
- {
37
- id: "crunchy16",
38
- label: "Crunchy 16",
39
- shortLabel: "16-Col",
40
- description: "16-color indexed LUT"
41
- },
42
- {
43
- id: "crunchy64",
44
- label: "Crunchy 64",
45
- shortLabel: "64-Col",
46
- description: "64-color indexed LUT"
47
- }
48
- ], R = [
49
- "#050811",
50
- "#141c33",
51
- "#27395c",
52
- "#53739e",
53
- "#a6bfd9",
54
- "#f2f7ff",
55
- "#1c4f6e",
56
- "#38e8ff",
57
- "#199474",
58
- "#70e899",
59
- "#5e2b59",
60
- "#d1436e",
61
- "#8c381f",
62
- "#ff6b00",
63
- "#ffb847",
64
- "#fff29c"
65
- ], z = [
66
- ...R,
67
- "#0a1020",
68
- "#10182b",
69
- "#1b2742",
70
- "#354b73",
71
- "#6e8db8",
72
- "#cad9ec",
73
- "#ffffff",
74
- "#000000",
75
- "#0e2b3d",
76
- "#14445c",
77
- "#1f6a8a",
78
- "#2498b5",
79
- "#58c9e8",
80
- "#9eeeff",
81
- "#d6fbff",
82
- "#0b222e",
83
- "#0f3b35",
84
- "#175e4e",
85
- "#238264",
86
- "#39b57d",
87
- "#86e39b",
88
- "#c6f7c2",
89
- "#426130",
90
- "#96b54c",
91
- "#2a1638",
92
- "#422059",
93
- "#672d78",
94
- "#993e8f",
95
- "#d160a6",
96
- "#ff9ec7",
97
- "#4a1b2d",
98
- "#8c2640",
99
- "#b83333",
100
- "#eb564b",
101
- "#ff8559",
102
- "#522214",
103
- "#75341c",
104
- "#ad4e1d",
105
- "#db7b21",
106
- "#ff9f38",
107
- "#ffd466",
108
- "#4a3d31",
109
- "#78624e",
110
- "#a68b72",
111
- "#d4bfa6",
112
- "#2b2d38",
113
- "#505569",
114
- "#8a91a8"
115
- ];
116
- function te(e) {
117
- let t = e.startsWith("#") ? e.slice(1) : e, n = parseInt(t, 16);
118
- return [
119
- n >> 16 & 255,
120
- n >> 8 & 255,
121
- n & 255
122
- ];
123
- }
124
- function ne(e) {
125
- let t = e.map(te), n = /* @__PURE__ */ new Uint8Array(131072);
126
- for (let e = 0; e < 32; e++) {
127
- let r = Math.round(e / 31 * 255);
128
- for (let i = 0; i < 32; i++) {
129
- let a = Math.round(i / 31 * 255);
130
- for (let o = 0; o < 32; o++) {
131
- let s = Math.round(o / 31 * 255), c = Infinity, l = t[0];
132
- for (let e = 0; e < t.length; e++) {
133
- let n = t[e], i = s - n[0], o = r - n[1], u = a - n[2], d = 2 * i * i + 4 * o * o + 3 * u * u;
134
- d < c && (c = d, l = n);
135
- }
136
- let u = (e * 1024 + (i * 32 + o)) * 4;
137
- n[u] = l[0], n[u + 1] = l[1], n[u + 2] = l[2], n[u + 3] = 255;
138
- }
139
- }
140
- }
141
- return n;
142
- }
143
- function re(e, t = 1024, n = 32) {
144
- let r = new a.DataTexture(e, t, n, a.RGBAFormat, a.UnsignedByteType);
145
- return r.magFilter = a.NearestFilter, r.minFilter = a.NearestFilter, r.generateMipmaps = !1, r.colorSpace = a.NoColorSpace, r.unpackAlignment = 1, r.needsUpdate = !0, r;
146
- }
147
- var ie = {};
148
- function ae(e) {
149
- let t = ie[e];
150
- if (t) return t;
151
- let n = e === "crunchy16" ? re(ne(R)) : e === "crunchy64" ? re(ne(z)) : re(new Uint8Array([
152
- 255,
153
- 255,
154
- 255,
155
- 255
156
- ]), 1, 1);
157
- return ie[e] = n, n;
158
- }
159
- function oe(e, t = new a.Vector4()) {
160
- switch (e) {
161
- case "off": return t.set(255, 255, 255, 0);
162
- case "rgb444": return t.set(15, 15, 15, 1);
163
- case "rgb332": return t.set(7, 7, 3, 1);
164
- case "crunchy16": return t.set(16, .26, 0, 2);
165
- case "crunchy64": return t.set(64, .14, 0, 2);
166
- default: return t.set(31, 31, 31, 1);
167
- }
168
- }
169
- var se = [
170
- "map",
171
- "normalMap",
172
- "roughnessMap",
173
- "metalnessMap",
174
- "emissiveMap",
175
- "bumpMap",
176
- "aoMap"
177
- ];
178
- function ce(e, t) {
179
- if (!e) return e;
180
- let n = t?.pixelated !== !1, r = t?.mipmaps !== !1;
181
- return e.magFilter = n ? a.NearestFilter : a.LinearFilter, e.generateMipmaps = r, e.minFilter = r ? a.NearestMipmapLinearFilter : n ? a.NearestFilter : a.LinearFilter, typeof t?.anisotropy == "number" && Number.isFinite(t.anisotropy) && (e.anisotropy = Math.max(1, Math.round(t.anisotropy))), e.needsUpdate = !0, e;
182
- }
183
- function le(e, t) {
184
- if (!e) return;
185
- let n = e;
186
- for (let e of se) {
187
- let r = n[e];
188
- r && typeof r == "object" && r.isTexture && ce(r, t);
189
- }
190
- }
191
- function ue(e, t = !1, n) {
192
- if (t) return .5;
193
- let r = typeof window < "u" && Number.isFinite(window.devicePixelRatio) && window.devicePixelRatio > 0 ? window.devicePixelRatio : 1, i = Math.min(2, Math.max(1, Math.round(typeof n == "number" && Number.isFinite(n) && n > 0 ? n : r))), o = Number.isFinite(e) ? e : .67, s = a.MathUtils.clamp(o, .33, 1);
194
- return s >= .98 ? i : i / Math.max(1, Math.round(i / s));
195
- }
196
- // src/shaders/retroShader.ts
197
- var B = new a.Vector2(320, 180), V = {
198
- uPs1Grid: { value: B },
199
- uDitherMix: { value: .62 },
200
- uSnapStrength: { value: 0 },
201
- uDitherScale: { value: 2 },
202
- uColorQuant: { value: oe("rgb555") },
203
- uPaletteLut: { value: ae("fallback") }
204
- };
205
- function de() {
206
- return {
207
- uPs1Grid: V.uPs1Grid,
208
- uDitherMix: V.uDitherMix,
209
- uSnapStrength: V.uSnapStrength,
210
- uDitherScale: V.uDitherScale,
211
- uColorQuant: V.uColorQuant,
212
- uPaletteLut: V.uPaletteLut
213
- };
214
- }
215
- var H = [
216
- {
217
- id: "dreamcast",
218
- label: "Nu-School Dreamcast",
219
- renderScale: .67,
220
- ditherAmount: .62,
221
- pixelSnapAmount: 0,
222
- colorMode: "rgb555",
223
- ditherScale: 2
224
- },
225
- {
226
- id: "ps2-shinobi",
227
- label: "PS2 Shinobi",
228
- renderScale: .58,
229
- ditherAmount: .8,
230
- pixelSnapAmount: 0,
231
- colorMode: "rgb555",
232
- ditherScale: 2
233
- },
234
- {
235
- id: "dsi-crisp",
236
- label: "DSi Crisp",
237
- renderScale: .5,
238
- ditherAmount: .88,
239
- pixelSnapAmount: .35,
240
- colorMode: "rgb444",
241
- ditherScale: 2
242
- },
243
- {
244
- id: "psx-chonk",
245
- label: "PSX Full Chonk",
246
- renderScale: .33,
247
- ditherAmount: 1,
248
- pixelSnapAmount: 1,
249
- colorMode: "rgb555",
250
- ditherScale: 2.5
251
- },
252
- {
253
- id: "clean-hd",
254
- label: "HD Remaster 1:1",
255
- renderScale: 1,
256
- ditherAmount: 0,
257
- pixelSnapAmount: 0,
258
- colorMode: "off",
259
- ditherScale: 1
260
- }
261
- ];
262
- function fe(e) {
263
- return H.find((t) => t.id === e) ?? H[0];
264
- }
265
- var pe = 1280, U = 720, me = 1, he = .67, ge = 2;
266
- function _e() {
267
- V.uDitherScale.value = Math.max(1, Math.round(ge * me));
268
- let e = a.MathUtils.clamp((he - .33) / .67, 0, 1), t = Math.max(1, Math.round(U / (150 + e * 150))), n = pe / (2 * t), r = U / (2 * t), i = Math.min(n, r), o = i > 0 && i < 45 ? 45 / i : 1;
269
- B.set(Math.max(1, Math.round(n * o)), Math.max(1, Math.round(r * o)));
270
- }
271
- function ve(e, t = 0, n = .67, r, i) {
272
- if (typeof e == "string") {
273
- let t = fe(e);
274
- return ve(t.ditherAmount, t.pixelSnapAmount, t.renderScale, t.colorMode, t.ditherScale), t;
275
- }
276
- Number.isFinite(e) && (V.uDitherMix.value = a.MathUtils.clamp(e, 0, 1)), Number.isFinite(t) && (V.uSnapStrength.value = a.MathUtils.clamp(t, 0, 1)), Number.isFinite(n) && (he = a.MathUtils.clamp(n, .33, 1)), r && (oe(r, V.uColorQuant.value), V.uPaletteLut.value = ae(r === "crunchy16" || r === "crunchy64" ? r : "fallback")), typeof i == "number" && Number.isFinite(i) && (ge = a.MathUtils.clamp(i, .5, 6)), _e();
277
- }
278
- function ye(e, t, n) {
279
- !Number.isFinite(e) || !Number.isFinite(t) || e <= 0 || t <= 0 || (pe = e, U = t, Number.isFinite(n) && n > 0 && (me = n), _e());
280
- }
281
- var W = "\nvec3 ps1SrgbToLinear(vec3 s) { vec3 a = clamp(s, 0.0, 1.0); return a * (a * (a * 0.305306011 + 0.682171111) + 0.012522878); }\nvec3 ps1LinearToSrgb(vec3 l) { return max(1.055 * pow(clamp(l, 0.0, 1.0), vec3(0.416666667)) - 0.055, vec3(0.0)); }\nfloat ps1Bayer2(vec2 c) { return (c.y < 0.5) ? (c.x < 0.5 ? 0.0 : 2.0) : (c.x < 0.5 ? 3.0 : 1.0); }\nfloat ps1Bayer4x4(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) + 0.5) / 16.0; }\nfloat ps1Bayer8x8(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 16.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.25), 2.0)) + 0.5) / 64.0; }\nvec3 ps1QuantizeRGB555Mix(vec3 col, vec2 fragCoord, float mixAmt) {\n if (mixAmt <= 0.001) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord * 0.5);\n vec3 c0 = floor(srgb * 31.0) / 31.0, c1 = min(c0 + 1.0 / 31.0, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, clamp(mixAmt, 0.0, 1.0))), t));\n}\nvec3 ps1QuantizeRGB555(vec3 col, vec2 fragCoord) { return ps1QuantizeRGB555Mix(col, fragCoord, 1.0); }\n", G = `
282
- uniform float uDitherScale; uniform vec4 uColorQuant; uniform sampler2D uPaletteLut;
283
- ${W}
284
- float ps1BayerDither(vec2 fragCoord) { return ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)); }
285
- vec3 ps1SamplePaletteLut(vec3 srgb) {
286
- vec3 c = clamp(srgb, 0.0, 1.0);
287
- return texture2D(uPaletteLut, vec2((floor(c.b * 31.0 + 0.5) * 32.0 + floor(c.r * 31.0 + 0.5) + 0.5) / 1024.0, (floor(c.g * 31.0 + 0.5) + 0.5) / 32.0)).rgb;
288
- }
289
- vec3 ps1QuantizeRetro(vec3 col, vec2 fragCoord, float ditherSpread) {
290
- if (uColorQuant.w < 0.5) return col;
291
- vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer8x8(fragCoord / max(uDitherScale, 0.5)), spread = clamp(ditherSpread, 0.0, 1.0);
292
- if (uColorQuant.w > 1.5) return ps1SamplePaletteLut(ps1LinearToSrgb(clamp(ps1SrgbToLinear(srgb) + (bayer - 0.5) * (uColorQuant.y * spread), 0.0, 1.0)));
293
- vec3 levels = max(uColorQuant.rgb, vec3(1.0)), c0 = floor(srgb * levels) / levels, c1 = min(c0 + 1.0 / levels, vec3(1.0));
294
- vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);
295
- vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);
296
- return mix(c0, c1, step(vec3(mix(0.5, bayer, spread)), t));
297
- }
298
- `, be = /* @__PURE__ */ new WeakSet();
299
- function K(e, t) {
300
- if (!e || be.has(e)) return e;
301
- be.add(e), e.userData.__kolmoRetroApplied = !0, t?.flatShading !== !1 && "flatShading" in e && (e.flatShading = !0);
302
- let n = e.onBeforeCompile, r = Object.prototype.hasOwnProperty.call(e, "customProgramCacheKey") ? e.customProgramCacheKey : null, i = t?.snap === void 0 ? V.uSnapStrength : { value: t.snap }, a = t?.dither === void 0 ? V.uDitherMix : { value: t.dither };
303
- return e.onBeforeCompile = (t, r) => {
304
- n && n.call(e, t, r), t.uniforms.uPs1Grid = V.uPs1Grid, t.uniforms.uSnapStrength = i, t.uniforms.uDitherMix = a, t.uniforms.uDitherScale = V.uDitherScale, t.uniforms.uColorQuant = V.uColorQuant, t.uniforms.uPaletteLut = V.uPaletteLut, t.vertexShader = "uniform vec2 uPs1Grid;\nuniform float uSnapStrength;\n" + t.vertexShader.replace("#include <project_vertex>", "#include <project_vertex>\nif (uSnapStrength > 0.001 && gl_Position.w > 0.001) {\n vec4 snapped = gl_Position; snapped.xyz = gl_Position.xyz / gl_Position.w;\n vec2 ps1SafeGrid = max(uPs1Grid, vec2(1.0));\n snapped.xy = mix(snapped.xy, floor(ps1SafeGrid * snapped.xy + 0.5) / ps1SafeGrid, uSnapStrength);\n snapped.xyz *= gl_Position.w; gl_Position = snapped;\n}"), t.fragmentShader = `uniform float uDitherMix;\n${G}\n` + t.fragmentShader.replace("#include <dithering_fragment>", "gl_FragColor.rgb = ps1QuantizeRetro(gl_FragColor.rgb, gl_FragCoord.xy, uDitherMix);");
305
- }, e.customProgramCacheKey = () => r ? `${r.call(e)}_dream_nuschool_retro_v3` : "dream_nuschool_retro_v3", e.needsUpdate = !0, e;
306
- }
307
- var xe = K;
308
- function Se(e, t) {
309
- e.traverse((e) => {
310
- let n = e;
311
- if (n.isMesh && n.material) for (let e of Array.isArray(n.material) ? n.material : [n.material]) e.isShaderMaterial || K(e, t);
312
- });
313
- }
314
- // src/shaders/plumeAndSparkle.tsx
315
- var q = 48, Ce = [
316
- 0,
317
- 0,
318
- 0
319
- ], we = "\n if (uSnapStrength > 0.001 && clip.w > 0.001) {\n vec4 snapped = clip; snapped.xyz = clip.xyz / clip.w;\n snapped.xy = mix(snapped.xy, floor(uPs1Grid * snapped.xy + 0.5) / uPs1Grid, uSnapStrength);\n snapped.xyz *= clip.w; clip = snapped;\n }\n", Te = `
320
- uniform vec2 uPs1Grid; uniform float uSnapStrength, uTime, uThrottle, uBoost;
321
- varying vec2 vUv;
322
- void main() {
323
- vUv = uv; vec3 p = position; float along = clamp(uv.y, 0.0, 1.0);
324
- float shock = sin(along * 22.0 - uTime * (16.0 + uBoost * 24.0)) * (0.045 + uBoost * 0.085) * along;
325
- p.xz *= 1.0 + shock + along * (uThrottle * 0.25 + uBoost * 0.52);
326
- vec4 clip = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
327
- ${we}
328
- gl_Position = clip;
329
- }
330
- `, Ee = `
331
- uniform float uTime, uThrottle, uBoost, uIntensity, uDitherMix;
332
- uniform vec3 uColorCore, uColorMid, uColorOuter;
333
- varying vec2 vUv;
334
- ${W}
335
- void main() {
336
- float along = clamp(vUv.y, 0.0, 1.0);
337
- float tailFade = pow(1.0 - along, 1.15 - uBoost * 0.28), nozzleFade = smoothstep(0.0, 0.09, along);
338
- float throatHot = exp(-along * 5.2) * (0.65 + uThrottle * 0.55 + uBoost * 0.9);
339
- float machWave = sin(along * 28.0 - uTime * (16.0 + uThrottle * 10.0 + uBoost * 22.0)) * 0.5 + 0.5;
340
- float machCells = mix(machWave, step(0.42, machWave), uDitherMix * 0.85);
341
- float spiral = sin(vUv.x * 37.699 + along * 10.0 - uTime * 14.0) * 0.16 + 0.84;
342
- float density = (tailFade * (0.62 + machCells * 0.38) * spiral + throatHot * 0.45) * nozzleFade * uIntensity;
343
- if (density < mix(0.04, ps1Bayer4x4(gl_FragCoord.xy * 0.5) * 0.56 + 0.05, uDitherMix)) discard;
344
- vec3 cruise = mix(mix(uColorCore, uColorMid, smoothstep(0.05, 0.36, along)), uColorOuter, smoothstep(0.36, 0.88, along));
345
- vec3 boostC = mix(mix(vec3(1.0, 0.97, 0.90), vec3(0.18, 0.88, 1.0), smoothstep(0.04, 0.28, along)), vec3(1.0, 0.46, 0.08), smoothstep(0.28, 0.72, along));
346
- boostC += vec3(0.22, 0.52, 0.65) * machCells * (1.0 - along) * 0.45;
347
- vec3 col = mix(cruise, boostC, uBoost * 0.85) * (0.82 + uThrottle * 0.22 + uBoost * 0.28 + throatHot * 0.22);
348
- gl_FragColor = vec4(ps1QuantizeRGB555Mix(clamp(col, 0.0, 1.0), gl_FragCoord.xy, uDitherMix), clamp(mix(density * 0.88, 0.88, uDitherMix * 0.55), 0.16, 0.92));
349
- }
350
- `, De = `
351
- attribute float aPhase, aAngle, aRadius, aSpeed, aSize;
352
- uniform float uTime, uDrive, uBoost, uScale, uMode, uSnapStrength;
353
- uniform vec2 uPs1Grid;
354
- varying float vLife, vBoost;
355
- void main() {
356
- float life = fract(aPhase + uTime * (0.7 + uDrive * 0.9 + uBoost * 1.4) * aSpeed);
357
- vLife = life; vBoost = uBoost;
358
- float coneLen = (1.35 + uDrive * 2.5 + uBoost * 4.4) * (uMode > 1.5 ? 1.55 : 1.0) * uScale;
359
- float z = -(0.04 * uScale + life * coneLen);
360
- float spread = uMode > 0.5 && uMode < 1.5 ? 1.6 : (uMode > 1.5 ? 0.42 : 0.88);
361
- float flare = aRadius * uScale * spread * (0.22 + life * (0.85 + uBoost * 0.95));
362
- float ang = aAngle + life * (3.2 + uBoost * 4.2) - uTime * 2.9;
363
- float rise = (uMode > 0.5 && uMode < 1.5) ? life * life * 0.52 * uScale : 0.0;
364
- vec4 mvPos = modelViewMatrix * vec4(cos(ang) * flare, sin(ang) * flare + rise, z, 1.0);
365
- vec4 clip = projectionMatrix * mvPos;
366
- ${we}
367
- gl_Position = clip;
368
- float szMul = uMode > 0.5 && uMode < 1.5 ? (0.75 + life * 0.95) : (1.0 - life * 0.65);
369
- gl_PointSize = clamp(aSize * uScale * szMul * (0.65 + uDrive * 0.5 + uBoost * 0.9) * (155.0 / max(1.5, -mvPos.z)), 2.0, 26.0);
370
- }
371
- `, Oe = `
372
- uniform float uDitherMix, uMode;
373
- uniform vec3 uColor;
374
- varying float vLife, vBoost;
375
- ${W}
376
- void main() {
377
- vec2 p = abs(gl_PointCoord - 0.5) * 2.0;
378
- float manhattan = p.x + p.y;
379
- if (manhattan > 1.05) discard;
380
- float fade = (1.0 - vLife) * (1.0 - vLife * 0.35);
381
- if (uMode > 0.5 && uMode < 1.5) {
382
- if (fade < ps1Bayer4x4(gl_FragCoord.xy * 0.5) * 0.75 * uDitherMix) discard;
383
- gl_FragColor = vec4(ps1QuantizeRGB555Mix(mix(uColor * 1.1, uColor * 0.45, vLife), gl_FragCoord.xy, uDitherMix), clamp(fade * 0.68, 0.0, 0.8));
384
- return;
385
- }
386
- float core = 1.0 - smoothstep(0.0, 1.05, manhattan);
387
- vec3 cEnd = uMode > 1.5 ? uColor * 0.55 : mix(uColor * 0.7, vec3(1.0, 0.48, 0.1), 0.55 + vBoost * 0.45);
388
- vec3 col = mix(mix(vec3(0.96, 0.99, 1.0), uColor, smoothstep(0.0, 0.32, vLife)), cEnd, smoothstep(0.32, 0.95, vLife));
389
- col *= 1.05 + vBoost * 0.85 + core * 0.5;
390
- gl_FragColor = vec4(ps1QuantizeRGB555Mix(clamp(col, 0.0, 1.0), gl_FragCoord.xy, uDitherMix), clamp(fade * 0.9, 0.0, 0.95));
391
- }
392
- `, ke = new a.CylinderGeometry(.06, .28, 1, 8, 5, !0).translate(0, .5, 0), Ae = new a.CylinderGeometry(.03, .16, 1, 8, 5, !0).translate(0, .5, 0), je = new a.CircleGeometry(.11, 6), Me = (() => {
393
- let e = new a.BufferGeometry(), t = new Float32Array(q), n = new Float32Array(q), r = new Float32Array(q), i = new Float32Array(q), o = new Float32Array(q);
394
- for (let e = 0; e < q; e++) t[e] = e / q, n[e] = e * 2.39996 % (Math.PI * 2), r[e] = .06 + e * 19 % 100 / 100 * .22, i[e] = .72 + e * 31 % 100 / 100 * .65, o[e] = .55 + e * 13 % 100 / 100 * .72;
395
- return e.setAttribute("position", new a.BufferAttribute(/* @__PURE__ */ new Float32Array(144), 3)), e.setAttribute("aPhase", new a.BufferAttribute(t, 1)), e.setAttribute("aAngle", new a.BufferAttribute(n, 1)), e.setAttribute("aRadius", new a.BufferAttribute(r, 1)), e.setAttribute("aSpeed", new a.BufferAttribute(i, 1)), e.setAttribute("aSize", new a.BufferAttribute(o, 1)), e;
396
- })();
397
- function Ne({ e, signalsRef: t }) {
398
- let s = i(null), d = i(null), f = i(null), p = i(null), m = i(0), h = i(null), g = r(() => {
399
- let t = new a.Color(e.color[0], e.color[1], e.color[2]);
400
- if (e.kind === "plume") {
401
- let e = (e, t, n, r) => new a.ShaderMaterial({
402
- uniforms: {
403
- uPs1Grid: V.uPs1Grid,
404
- uSnapStrength: V.uSnapStrength,
405
- uDitherMix: V.uDitherMix,
406
- uTime: { value: 0 },
407
- uThrottle: { value: 0 },
408
- uBoost: { value: 0 },
409
- uIntensity: { value: r },
410
- uColorCore: { value: e },
411
- uColorMid: { value: t },
412
- uColorOuter: { value: n }
413
- },
414
- vertexShader: Te,
415
- fragmentShader: Ee,
416
- transparent: !0,
417
- depthWrite: !1,
418
- blending: a.AdditiveBlending,
419
- side: a.DoubleSide,
420
- toneMapped: !1
421
- });
422
- return {
423
- outer: e(t.clone().lerp(new a.Color("#ffffff"), .65), t.clone(), t.clone().multiplyScalar(.45), .72),
424
- inner: e(new a.Color("#ffffff"), t.clone().lerp(new a.Color("#ffffff"), .45), t.clone(), .92)
425
- };
426
- }
427
- if (e.kind === "flare") {
428
- let e = {
429
- transparent: !0,
430
- opacity: 0,
431
- depthWrite: !1,
432
- blending: a.AdditiveBlending,
433
- side: a.DoubleSide,
434
- toneMapped: !1
435
- };
436
- return {
437
- halo: new a.MeshBasicMaterial({
438
- color: t,
439
- ...e
440
- }),
441
- core: new a.MeshBasicMaterial({
442
- color: t.clone().lerp(new a.Color("#ffffff"), .7),
443
- ...e
444
- })
445
- };
446
- }
447
- let n = e.kind === "fume" ? 1 : e.kind === "trail" ? 2 : 0;
448
- return { pts: new a.ShaderMaterial({
449
- uniforms: {
450
- uPs1Grid: V.uPs1Grid,
451
- uSnapStrength: V.uSnapStrength,
452
- uDitherMix: V.uDitherMix,
453
- uTime: { value: 0 },
454
- uDrive: { value: 0 },
455
- uBoost: { value: 0 },
456
- uScale: { value: e.size },
457
- uMode: { value: n },
458
- uColor: { value: t }
459
- },
460
- vertexShader: De,
461
- fragmentShader: Oe,
462
- transparent: !0,
463
- depthWrite: !1,
464
- blending: e.kind === "fume" ? a.NormalBlending : a.AdditiveBlending,
465
- toneMapped: !1
466
- }) };
467
- }, [
468
- e.kind,
469
- e.size,
470
- e.color[0],
471
- e.color[1],
472
- e.color[2]
473
- ]);
474
- return n(() => {
475
- let t, n = e.object;
476
- if (e.kind === "flare" && n?.isMesh && n.material && !Array.isArray(n.material) && "emissive" in n.material) {
477
- t = n.material;
478
- let r = t.clone();
479
- r.emissive.setRGB(e.color[0], e.color[1], e.color[2]), n.material = r, h.current = r;
480
- }
481
- return () => {
482
- t && n?.isMesh && (n.material = t), h.current?.dispose(), h.current = null, Object.values(g).forEach((e) => e?.dispose());
483
- };
484
- }, [
485
- e.kind,
486
- e.object,
487
- e.color[0],
488
- e.color[1],
489
- e.color[2],
490
- g
491
- ]), o((n, r) => {
492
- let i = Math.min(r, .05), o = t.current, c = o ? a.MathUtils.clamp(o[e.drive], 0, 1) : 0, l = o ? a.MathUtils.clamp(e.drive === "boost" ? c : o.boost, 0, 1) : 0;
493
- if (g.outer && g.inner && s.current && d.current) {
494
- let t = c > .015;
495
- if (s.current.visible = t, d.current.visible = t, !t) return;
496
- m.current += i * (5 + c * 7 + l * 16);
497
- let n = e.size * (.48 + c * 1.35 + l * 1.95) * (.94 + Math.sin(m.current * 4.7) * .06), r = e.size * (.58 + c * .24 + l * .34);
498
- s.current.scale.set(r, n, r), d.current.scale.set(r * .54, n * .74, r * .54), g.outer.uniforms.uTime.value = m.current, g.outer.uniforms.uThrottle.value = c, g.outer.uniforms.uBoost.value = l, g.inner.uniforms.uTime.value = m.current * 1.25, g.inner.uniforms.uThrottle.value = c, g.inner.uniforms.uBoost.value = l;
499
- } else if (g.pts && f.current) {
500
- if (f.current.visible = c > .015, !f.current.visible) return;
501
- g.pts.uniforms.uTime.value += i, g.pts.uniforms.uDrive.value = c, g.pts.uniforms.uBoost.value = l;
502
- } else if (g.halo && g.core && p.current) {
503
- let t = c * ((e.drive === "turn_l" || e.drive === "turn_r") && c > .5 ? Math.sin(n.clock.elapsedTime * 18) > -.1 ? 1 : .06 : 1);
504
- p.current.visible = t > .02, p.current.scale.setScalar(e.size * (.65 + t * .75)), g.halo.opacity = t * .78, g.core.opacity = Math.min(1, t * .96), h.current && (h.current.emissiveIntensity = .15 + t * 2.4);
505
- }
506
- }), /* @__PURE__ */ u("group", {
507
- position: e.localPosition,
508
- quaternion: e.localQuaternion,
509
- children: [
510
- e.kind === "plume" && g.outer && g.inner && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("mesh", {
511
- ref: d,
512
- geometry: Ae,
513
- material: g.inner,
514
- rotation: [
515
- -Math.PI / 2,
516
- 0,
517
- 0
518
- ],
519
- frustumCulled: !1
520
- }), /* @__PURE__ */ l("mesh", {
521
- ref: s,
522
- geometry: ke,
523
- material: g.outer,
524
- rotation: [
525
- -Math.PI / 2,
526
- 0,
527
- 0
528
- ],
529
- frustumCulled: !1
530
- })] }),
531
- (e.kind === "sparkle" || e.kind === "fume" || e.kind === "trail") && g.pts && /* @__PURE__ */ l("points", {
532
- ref: f,
533
- geometry: Me,
534
- material: g.pts,
535
- frustumCulled: !1
536
- }),
537
- e.kind === "flare" && g.halo && g.core && /* @__PURE__ */ u("group", {
538
- ref: p,
539
- position: [
540
- 0,
541
- 0,
542
- -.015
543
- ],
544
- children: [/* @__PURE__ */ l("mesh", {
545
- geometry: je,
546
- material: g.halo
547
- }), /* @__PURE__ */ l("mesh", {
548
- geometry: je,
549
- material: g.core,
550
- scale: .48,
551
- position: [
552
- 0,
553
- 0,
554
- -.004
555
- ]
556
- })]
557
- })
558
- ]
559
- });
560
- }
561
- function Pe({ emitters: e, signalsRef: t, comOffset: n = Ce }) {
562
- let i = r(() => [
563
- -n[0],
564
- -n[1],
565
- -n[2]
566
- ], [
567
- n[0],
568
- n[1],
569
- n[2]
570
- ]);
571
- return e.length === 0 ? null : /* @__PURE__ */ l("group", {
572
- position: i,
573
- children: e.map((e, n) => /* @__PURE__ */ l(Ne, {
574
- e,
575
- signalsRef: t
576
- }, `${e.nodeName}-${n}`))
577
- });
578
- }
579
- // src/shaders/celestialBackdrop.tsx
580
- var J = new a.Vector3(-.62, .42, -.66).normalize(), Fe = 72, Ie = "varying vec3 vDir; void main() { vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }", Le = `
581
- uniform float uTime, uDitherMix; uniform vec3 uSunDir; varying vec3 vDir;
582
- ${W}
583
- float hash(vec3 p) { p = fract(p * 0.3183099 + 0.1) * 17.0; return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); }
584
- float noise(vec3 x) {
585
- vec3 i = floor(x), f = fract(x);
586
- return mix(
587
- mix(mix(hash(i + vec3(0,0,0)), hash(i + vec3(1,0,0)), f.x), mix(hash(i + vec3(0,1,0)), hash(i + vec3(1,1,0)), f.x), f.y),
588
- mix(mix(hash(i + vec3(0,0,1)), hash(i + vec3(1,0,1)), f.x), mix(hash(i + vec3(0,1,1)), hash(i + vec3(1,1,1)), f.x), f.y), f.z
589
- );
590
- }
591
- float fbm(vec3 p) { float v = 0.0, a = 0.55; for (int i = 0; i < 3; i++) { v += a * noise(p); p = p * 2.05 + vec3(13.1, 7.7, 5.3); a *= 0.48; } return v; }
592
- void main() {
593
- vec3 dir = normalize(vDir);
594
- float horizon = exp(-abs(dir.y + dir.x * 0.18) * 3.0);
595
- vec3 col = mix(mix(vec3(0.015, 0.02, 0.055), vec3(0.02, 0.03, 0.08), dir.y * 0.5 + 0.5), vec3(0.08, 0.16, 0.27), horizon * 0.9);
596
- float n1 = fbm(dir * 2.8 + vec3(0.0, uTime * 0.003, 0.0)), n2 = fbm(dir * 5.0 - vec3(uTime * 0.002, 0.0, 1.4));
597
- float rawMask = clamp((n1 * 0.72 + n2 * 0.34 - 0.44) * 2.4, 0.0, 1.0) * (0.35 + horizon * 0.85);
598
- float cloudMask = mix(rawMask, floor(rawMask * 5.0) / 5.0, uDitherMix);
599
- float sunDot = max(0.0, dot(dir, normalize(uSunDir)));
600
- vec3 tint = mix(vec3(0.06, 0.38, 0.50), vec3(0.28, 0.12, 0.40), mix(n2, step(0.52, n2), uDitherMix));
601
- col += mix(tint, vec3(0.62, 0.26, 0.14), pow(sunDot, 2.0) * 0.9) * cloudMask * 0.85;
602
- float corona = mix(pow(sunDot, 12.0), floor(pow(sunDot, 12.0) * 6.0) / 6.0, uDitherMix);
603
- col += vec3(0.95, 0.55, 0.22) * corona * 0.65 + vec3(1.0, 0.90, 0.68) * step(0.9965, sunDot) * 1.1;
604
- float s = hash(floor(dir * 165.0));
605
- if (s > 0.995) col += mix(vec3(0.74, 0.90, 1.0), vec3(1.0, 0.86, 0.68), step(0.5, fract(s * 91.3))) * 0.95;
606
- gl_FragColor = vec4(ps1QuantizeRGB555Mix(col, gl_FragCoord.xy, uDitherMix), 1.0);
607
- }
608
- `, Re = "\n uniform vec2 uPs1Grid; uniform float uSnapStrength; varying vec3 vNormalWorld, vWorldPos;\n void main() {\n vec4 wp = modelMatrix * vec4(position, 1.0); vWorldPos = wp.xyz; vNormalWorld = normalize(mat3(modelMatrix) * normal);\n vec4 clip = projectionMatrix * viewMatrix * wp;\n if (uSnapStrength > 0.001 && clip.w > 0.001) {\n vec4 snapped = clip; snapped.xyz = clip.xyz / clip.w; vec2 safeGrid = max(uPs1Grid, vec2(1.0));\n snapped.xy = mix(snapped.xy, floor(safeGrid * snapped.xy + 0.5) / safeGrid, uSnapStrength); snapped.xyz *= clip.w; clip = snapped;\n }\n gl_Position = clip;\n }\n", ze = `
609
- uniform vec3 uSunDir, uColor; uniform float uDitherMix; varying vec3 vNormalWorld, vWorldPos;
610
- ${G}
611
- void main() {
612
- vec3 viewDir = normalize(cameraPosition - vWorldPos);
613
- float rim = pow(1.0 - max(0.0, dot(viewDir, vNormalWorld)), 2.6), nl = dot(vNormalWorld, normalize(uSunDir));
614
- float sunLit = mix(smoothstep(-0.3, 0.7, nl), step(-0.25, nl), uDitherMix) * 0.72 + 0.28, alpha = rim * sunLit;
615
- if (alpha < (ps1BayerDither(gl_FragCoord.xy) * 0.65 + 0.14) * uDitherMix) discard;
616
- vec3 col = ps1QuantizeRetro(ps1LinearToSrgb(uColor * (0.8 + sunLit * 0.55)), gl_FragCoord.xy, uDitherMix);
617
- gl_FragColor = vec4(col, mix(alpha * 0.85, 0.75, uDitherMix));
618
- }
619
- `;
620
- function Be({ sunDirection: e }) {
621
- let t = i(null), c = i(null), d = r(() => ({
622
- uTime: { value: 0 },
623
- uSunDir: { value: J.clone() },
624
- uDitherMix: V.uDitherMix
625
- }), []);
626
- return n(() => {
627
- e ? d.uSunDir.value.set(e[0], e[1], e[2]).normalize() : d.uSunDir.value.copy(J);
628
- }, [
629
- e?.[0],
630
- e?.[1],
631
- e?.[2],
632
- d
633
- ]), o((e, n) => {
634
- t.current && (t.current.uniforms.uTime.value += Math.min(n, .05)), c.current && c.current.position.copy(e.camera.position);
635
- }), /* @__PURE__ */ u("group", {
636
- ref: c,
637
- children: [/* @__PURE__ */ u("mesh", {
638
- renderOrder: -10,
639
- frustumCulled: !1,
640
- children: [/* @__PURE__ */ l("icosahedronGeometry", { args: [3800, 2] }), /* @__PURE__ */ l("shaderMaterial", {
641
- ref: t,
642
- uniforms: d,
643
- vertexShader: Ie,
644
- fragmentShader: Le,
645
- side: a.BackSide,
646
- depthWrite: !1
647
- })]
648
- }), /* @__PURE__ */ l(s, {
649
- radius: 190,
650
- depth: 130,
651
- count: 2600,
652
- factor: 4.5,
653
- saturation: .35,
654
- fade: !1,
655
- speed: .18
656
- })]
657
- });
658
- }
659
- var Ve = [
660
- [
661
- 0,
662
- 8,
663
- 2,
664
- 10
665
- ],
666
- [
667
- 12,
668
- 4,
669
- 14,
670
- 6
671
- ],
672
- [
673
- 3,
674
- 11,
675
- 1,
676
- 9
677
- ],
678
- [
679
- 15,
680
- 7,
681
- 13,
682
- 5
683
- ]
684
- ], Y = [
685
- [
686
- 14,
687
- 30,
688
- 56
689
- ],
690
- [
691
- 24,
692
- 58,
693
- 92
694
- ],
695
- [
696
- 42,
697
- 98,
698
- 126
699
- ],
700
- [
701
- 76,
702
- 134,
703
- 152
704
- ],
705
- [
706
- 186,
707
- 128,
708
- 86
709
- ],
710
- [
711
- 232,
712
- 160,
713
- 94
714
- ],
715
- [
716
- 172,
717
- 108,
718
- 74
719
- ],
720
- [
721
- 68,
722
- 108,
723
- 136
724
- ],
725
- [
726
- 34,
727
- 62,
728
- 96
729
- ],
730
- [
731
- 16,
732
- 28,
733
- 50
734
- ]
735
- ], X = (e) => Math.min(255, Math.round(Math.max(0, Math.min(255, e)) / 8.225) * 8);
736
- function He() {
737
- let e = /* @__PURE__ */ new Uint8Array(131072);
738
- for (let t = 0; t < 128; t++) for (let n = 0; n < 256; n++) {
739
- let r = Math.sin(n / 256 * Math.PI * 8 + t * .16) * 2.8 + Math.cos(n / 256 * Math.PI * 16 - t * .24) * 1.4, i = a.MathUtils.clamp((t + r) / 128 * (Y.length - 1), 0, Y.length - 1.001), o = Math.floor(i), [s, c, l] = i - o > Ve[t & 3][n & 3] / 16 ? Y[o + 1] : Y[o], u = (n - 92.16) / 24, d = (t - 71.68) / 11, f = Math.hypot(u, d);
740
- if (f < 1) {
741
- let e = (1 - f) * (.65 + (Math.sin(f * 10 - Math.atan2(d, u) * 2) * .5 + .5) * .35);
742
- s = s * (1 - e) + 244 * e, c = c * (1 - e) + 148 * e, l = l * (1 - e) + 74 * e;
743
- }
744
- let p = ((n * 19 + t * 29 & 15) - 8) * 1.1, m = (t * 256 + n) * 4;
745
- e[m] = X(s + p), e[m + 1] = X(c + p), e[m + 2] = X(l + p), e[m + 3] = 255;
746
- }
747
- let t = new a.DataTexture(e, 256, 128, a.RGBAFormat);
748
- t.colorSpace = a.SRGBColorSpace, t.wrapS = a.RepeatWrapping, t.minFilter = a.NearestFilter, t.magFilter = a.NearestFilter, t.needsUpdate = !0;
749
- let n = /* @__PURE__ */ new Uint8Array(1024);
750
- for (let e = 0; e < 256; e++) {
751
- let t = e / 255, r = Math.abs(t - .44) < .048 || Math.abs(t - .78) < .024 ? 0 : 1, i = (.62 + .38 * Math.sin(t * 78)) * Math.sin(t * Math.PI) * r, a = e * 4;
752
- n[a] = X(168 + 68 * Math.sin(t * 11 + .4)), n[a + 1] = X(186 + 44 * Math.cos(t * 16)), n[a + 2] = X(204 + 42 * Math.sin(t * 13 + 1.8)), n[a + 3] = i > .14 ? Math.round(Math.min(.92, Math.round(i * 8) / 8) * 255) : 0;
753
- }
754
- let r = new a.DataTexture(n, 256, 1, a.RGBAFormat);
755
- return r.colorSpace = a.SRGBColorSpace, r.minFilter = a.NearestFilter, r.magFilter = a.NearestFilter, r.needsUpdate = !0, {
756
- planetMap: t,
757
- ringMap: r
758
- };
759
- }
760
- function Ue() {
761
- let e = new a.DodecahedronGeometry(1, 0), t = e.index ? e.toNonIndexed() : e.clone();
762
- e.dispose();
763
- let n = t.attributes.position, r = new Float32Array(n.count * 3);
764
- for (let e = 0; e < n.count; e++) {
765
- let t = .48 + e * 17 % 10 * .032;
766
- r[e * 3] = t * .92, r[e * 3 + 1] = t * .96, r[e * 3 + 2] = t;
767
- }
768
- return t.setAttribute("color", new a.BufferAttribute(r, 3)), t.computeVertexNormals(), t;
769
- }
770
- function We(e, t, n) {
771
- let r = new a.Object3D();
772
- for (let i = 0; i < 72; i++) {
773
- let o = i / 72 * Math.PI * 2 + i % 5 * .08, s = a.MathUtils.lerp(t + 18, n - 18, i * 37 % 100 / 100), c = (i * 19 % 100 / 100 - .5) * 18, l = 4.5 + i * 13 % 100 / 100 * 14.5;
774
- r.position.set(Math.cos(o) * s, Math.sin(o) * s, c), r.rotation.set(i * .7, i * 1.1, i * .4), r.scale.set(l * 1.2, l * .8, l), r.updateMatrix(), e.setMatrixAt(i, r.matrix);
775
- }
776
- e.instanceMatrix.needsUpdate = !0;
777
- }
778
- function Ge({ position: e = [
779
- -420,
780
- 140,
781
- -980
782
- ], radius: t = 180, ringInner: s, ringOuter: c, color: p = "#47d7ff", collider: m = !1, moonlets: h = !0, gravityWellActive: g = !1 }) {
783
- let _ = s ?? t * 1.45, v = c ?? t * 2.35, y = i(null), b = i(null), x = i(null), S = i(null), C = r(() => {
784
- let { planetMap: e, ringMap: n } = He(), r = new a.SphereGeometry(t, 48, 28), i = r.index ? r.toNonIndexed() : r.clone();
785
- r.dispose(), i.computeVertexNormals();
786
- let o = new a.RingGeometry(_, v, 96, 4), s = o.attributes.position, c = o.attributes.uv, l = new a.Vector3();
787
- for (let e = 0; e < s.count; e++) l.fromBufferAttribute(s, e), c.setXY(e, a.MathUtils.clamp((l.length() - _) / Math.max(.001, v - _), 0, 1), .5);
788
- c.needsUpdate = !0;
789
- let u = o.index ? o.toNonIndexed() : o.clone();
790
- return o.dispose(), u.computeVertexNormals(), {
791
- planetMap: e,
792
- ringMap: n,
793
- planetGeo: i,
794
- ringGeo: u,
795
- moonletGeo: Ue(),
796
- moonletMat: K(new a.MeshStandardMaterial({
797
- vertexColors: !0,
798
- flatShading: !0,
799
- roughness: .82,
800
- metalness: .14
801
- })),
802
- planetMat: K(new a.MeshStandardMaterial({
803
- map: e,
804
- flatShading: !0,
805
- roughness: .9,
806
- metalness: .05
807
- })),
808
- ringMat: K(new a.MeshStandardMaterial({
809
- map: n,
810
- flatShading: !0,
811
- transparent: !0,
812
- alphaTest: .12,
813
- opacity: .94,
814
- roughness: .84,
815
- metalness: .1,
816
- side: a.DoubleSide
817
- })),
818
- gravWellMat: K(new a.MeshBasicMaterial({
819
- color: "#38f2ff",
820
- transparent: !0,
821
- opacity: 0,
822
- side: a.DoubleSide,
823
- depthWrite: !1,
824
- toneMapped: !1
825
- })),
826
- atmoUniforms: {
827
- ...de(),
828
- uSunDir: { value: J.clone() },
829
- uColor: { value: new a.Color(p) }
830
- }
831
- };
832
- }, [
833
- t,
834
- _,
835
- v,
836
- p
837
- ]);
838
- return n(() => {
839
- S.current && We(S.current, _, v);
840
- }, [
841
- _,
842
- v,
843
- h
844
- ]), n(() => () => {
845
- C.planetMap.dispose(), C.ringMap.dispose(), C.planetGeo.dispose(), C.ringGeo.dispose(), C.moonletGeo.dispose(), C.moonletMat.dispose(), C.planetMat.dispose(), C.ringMat.dispose(), C.gravWellMat.dispose();
846
- }, [C]), o((e, t) => {
847
- let n = Math.min(t, .05);
848
- y.current && (y.current.rotation.y += n * .018), b.current && (b.current.rotation.z += n * .008), x.current && (x.current.rotation.z -= n * .1, C.gravWellMat.opacity = a.MathUtils.lerp(C.gravWellMat.opacity, g ? .55 : 0, 1 - Math.exp(-5 * n)), x.current.visible = C.gravWellMat.opacity > .02);
849
- }), /* @__PURE__ */ u("group", {
850
- position: e,
851
- children: [
852
- m && /* @__PURE__ */ l(f, {
853
- type: "fixed",
854
- colliders: !1,
855
- userData: {
856
- kind: "planet",
857
- radius: t
858
- },
859
- children: /* @__PURE__ */ l(d, { args: [t * .97] })
860
- }),
861
- /* @__PURE__ */ l("mesh", {
862
- ref: y,
863
- geometry: C.planetGeo,
864
- material: C.planetMat,
865
- receiveShadow: !1
866
- }),
867
- /* @__PURE__ */ l("mesh", {
868
- geometry: C.planetGeo,
869
- scale: 1.04,
870
- children: /* @__PURE__ */ l("shaderMaterial", {
871
- uniforms: C.atmoUniforms,
872
- vertexShader: Re,
873
- fragmentShader: ze,
874
- transparent: !0,
875
- depthWrite: !1,
876
- blending: a.AdditiveBlending
877
- })
878
- }),
879
- /* @__PURE__ */ u("group", {
880
- ref: b,
881
- rotation: [
882
- Math.PI * .39,
883
- .24,
884
- -.32
885
- ],
886
- children: [
887
- /* @__PURE__ */ l("mesh", {
888
- geometry: C.ringGeo,
889
- material: C.ringMat
890
- }),
891
- h && /* @__PURE__ */ l("instancedMesh", {
892
- ref: S,
893
- args: [
894
- C.moonletGeo,
895
- C.moonletMat,
896
- 72
897
- ],
898
- frustumCulled: !1
899
- }),
900
- /* @__PURE__ */ l("mesh", {
901
- ref: x,
902
- visible: !1,
903
- material: C.gravWellMat,
904
- children: /* @__PURE__ */ l("ringGeometry", { args: [
905
- v + 14,
906
- v + 30,
907
- 64
908
- ] })
909
- })
910
- ]
911
- })
912
- ]
913
- });
914
- }
915
- // src/shaders/ps2Textures.ts
916
- var Z = {
917
- DIRT: 0,
918
- GRASS: 1,
919
- SAND: 2,
920
- ROCK: 3,
921
- GRAVEL: 4,
922
- FOREST: 5,
923
- SNOW: 6,
924
- ASPHALT: 7
925
- };
926
- function Q(e, t, n, r) {
927
- let i = (e % n + n) % n, a = (t % n + n) % n, o = Math.imul(i, 374761393) + Math.imul(a, 668265263) + r | 0;
928
- return o = Math.imul(o ^ o >>> 13, 1274126177), ((o ^ o >>> 16) >>> 0) / 4294967296;
929
- }
930
- function Ke(e, t, n, r) {
931
- let i = e * n, a = t * n, o = Math.floor(i), s = Math.floor(a), c = i - o, l = a - s, u = c * c * (3 - 2 * c), d = l * l * (3 - 2 * l), f = Q(o, s, n, r), p = Q(o + 1, s, n, r), m = Q(o, s + 1, n, r), h = Q(o + 1, s + 1, n, r);
932
- return (f * (1 - u) + p * u) * (1 - d) + (m * (1 - u) + h * u) * d;
933
- }
934
- var qe = (e) => Math.max(0, Math.min(255, Math.round(e))), Je = [
935
- {
936
- base: [
937
- 108,
938
- 82,
939
- 56
940
- ],
941
- dark: [
942
- 72,
943
- 53,
944
- 36
945
- ],
946
- light: [
947
- 138,
948
- 108,
949
- 76
950
- ],
951
- freqA: 16,
952
- freqB: 48,
953
- speckle: .28
954
- },
955
- {
956
- base: [
957
- 86,
958
- 114,
959
- 52
960
- ],
961
- dark: [
962
- 58,
963
- 82,
964
- 34
965
- ],
966
- light: [
967
- 122,
968
- 146,
969
- 68
970
- ],
971
- freqA: 20,
972
- freqB: 64,
973
- speckle: .22
974
- },
975
- {
976
- base: [
977
- 194,
978
- 174,
979
- 128
980
- ],
981
- dark: [
982
- 164,
983
- 142,
984
- 98
985
- ],
986
- light: [
987
- 218,
988
- 202,
989
- 158
990
- ],
991
- freqA: 12,
992
- freqB: 64,
993
- speckle: .14,
994
- striateY: 3
995
- },
996
- {
997
- base: [
998
- 112,
999
- 110,
1000
- 106
1001
- ],
1002
- dark: [
1003
- 68,
1004
- 66,
1005
- 64
1006
- ],
1007
- light: [
1008
- 148,
1009
- 145,
1010
- 138
1011
- ],
1012
- freqA: 14,
1013
- freqB: 36,
1014
- speckle: .2,
1015
- striateY: 4.5
1016
- },
1017
- {
1018
- base: [
1019
- 124,
1020
- 118,
1021
- 108
1022
- ],
1023
- dark: [
1024
- 76,
1025
- 72,
1026
- 66
1027
- ],
1028
- light: [
1029
- 168,
1030
- 162,
1031
- 150
1032
- ],
1033
- freqA: 32,
1034
- freqB: 64,
1035
- speckle: .45
1036
- },
1037
- {
1038
- base: [
1039
- 56,
1040
- 76,
1041
- 42
1042
- ],
1043
- dark: [
1044
- 36,
1045
- 48,
1046
- 28
1047
- ],
1048
- light: [
1049
- 88,
1050
- 98,
1051
- 54
1052
- ],
1053
- freqA: 18,
1054
- freqB: 52,
1055
- speckle: .26
1056
- },
1057
- {
1058
- base: [
1059
- 222,
1060
- 228,
1061
- 236
1062
- ],
1063
- dark: [
1064
- 182,
1065
- 194,
1066
- 212
1067
- ],
1068
- light: [
1069
- 246,
1070
- 248,
1071
- 252
1072
- ],
1073
- freqA: 12,
1074
- freqB: 40,
1075
- speckle: .1
1076
- },
1077
- {
1078
- base: [
1079
- 54,
1080
- 55,
1081
- 58
1082
- ],
1083
- dark: [
1084
- 36,
1085
- 37,
1086
- 40
1087
- ],
1088
- light: [
1089
- 86,
1090
- 88,
1091
- 92
1092
- ],
1093
- freqA: 32,
1094
- freqB: 64,
1095
- speckle: .42
1096
- }
1097
- ];
1098
- function Ye(e, n = 128) {
1099
- let r = new t(e), i = [];
1100
- for (let e = 0; e < 8; e++) {
1101
- let t = new Uint8Array(n * n * 4), a = Je[e], o = r.next() * 2147483647 | 0, s = r.next() * 2147483647 | 0, c = r.next() * 2147483647 | 0;
1102
- for (let e = 0; e < n; e++) for (let r = 0; r < n; r++) {
1103
- let i = r / n, l = Ke(i, e / n * (a.striateY ?? 1) % 1, a.freqA, o), u = Ke(i, e / n, a.freqB, s), d = Q(r, e, n, c), f = l * .55 + u * .45;
1104
- d > 1 - a.speckle * .35 ? f = Math.min(1, f + .32) : d < a.speckle * .35 && (f = Math.max(0, f - .3)), f = Math.round(f * 12) / 12;
1105
- let p = f < .5 ? f * 2 : (f - .5) * 2, m = f < .5 ? a.dark : a.base, h = f < .5 ? a.base : a.light, g = (e * n + r) * 4;
1106
- t[g] = qe(m[0] * (1 - p) + h[0] * p), t[g + 1] = qe(m[1] * (1 - p) + h[1] * p), t[g + 2] = qe(m[2] * (1 - p) + h[2] * p), t[g + 3] = 255;
1107
- }
1108
- i.push(t);
1109
- }
1110
- return i;
1111
- }
1112
- function Xe(t) {
1113
- let n = t.config.gridCells, r = (e) => {
1114
- let t = new a.DataTexture(e, n, n, a.RGBAFormat, a.UnsignedByteType);
1115
- return t.colorSpace = a.NoColorSpace, t.wrapS = a.ClampToEdgeWrapping, t.wrapT = a.ClampToEdgeWrapping, t.magFilter = a.LinearFilter, t.minFilter = a.LinearFilter, t.generateMipmaps = !1, t.flipY = !1, t.needsUpdate = !0, t;
1116
- }, i = r(t.splat0), o = r(t.splat1), s = new a.DataTexture(t.alphaMap, n, n, a.RedFormat, a.UnsignedByteType);
1117
- s.colorSpace = a.NoColorSpace, s.wrapS = a.ClampToEdgeWrapping, s.wrapT = a.ClampToEdgeWrapping, s.magFilter = a.NearestFilter, s.minFilter = a.NearestFilter, s.generateMipmaps = !1, s.flipY = !1, s.needsUpdate = !0;
1118
- let c = Ye(e(t.config.seed) ^ 2654435769, 128), l = /* @__PURE__ */ new Uint8Array(524288), u = [];
1119
- for (let e = 0; e < 8; e++) {
1120
- l.set(c[e], e * 128 * 128 * 4);
1121
- let t = new a.DataTexture(c[e], 128, 128, a.RGBAFormat, a.UnsignedByteType);
1122
- t.colorSpace = a.SRGBColorSpace, t.wrapS = a.RepeatWrapping, t.wrapT = a.RepeatWrapping, t.magFilter = a.NearestFilter, t.minFilter = a.LinearMipmapNearestFilter, t.generateMipmaps = !0, t.needsUpdate = !0, u.push(t);
1123
- }
1124
- let d = new a.DataArrayTexture(l, 128, 128, 8);
1125
- return d.format = a.RGBAFormat, d.type = a.UnsignedByteType, d.colorSpace = a.SRGBColorSpace, d.wrapS = a.RepeatWrapping, d.wrapT = a.RepeatWrapping, d.magFilter = a.NearestFilter, d.minFilter = a.LinearMipmapNearestFilter, d.generateMipmaps = !0, d.needsUpdate = !0, {
1126
- splat0Tex: i,
1127
- splat1Tex: o,
1128
- alphaTex: s,
1129
- detailArrayTex: d,
1130
- detailSliceTexs: u,
1131
- dispose: () => {
1132
- i.dispose(), o.dispose(), s.dispose(), d.dispose(), u.forEach((e) => e.dispose());
1133
- }
1134
- };
1135
- }
1136
- // src/shaders/ps2GlslShared.ts
1137
- var Ze = "\n // Branchless 4x4 Bayer matrix mapped to [0.5/16 .. 15.5/16] so w=0 and w=1 never speckle.\n float ps2Bayer4x4(vec2 cellCoord) {\n vec2 cell = floor(cellCoord);\n vec2 p0 = mod(cell, 2.0);\n vec2 p1 = mod(floor(cell * 0.5), 2.0);\n float b0 = 2.0 * abs(p0.x - p0.y) + p0.y;\n float b1 = 2.0 * abs(p1.x - p1.y) + p1.y;\n return (4.0 * b0 + b1 + 0.5) * 0.0625;\n }\n\n float ps2MacroVariation(vec2 worldXZ) {\n vec2 p = worldXZ * 0.037;\n float n = sin(p.x * 1.7 + cos(p.y * 1.3)) * 0.5 + 0.5;\n return mix(0.88, 1.10, n);\n }\n\n // PS2 Graphics Synthesizer 16-bit (RGB555) DIMX screen-space framebuffer dither\n vec3 ps2QuantizeRGB555(vec3 srgbColor, vec2 fragCoord, float pixelScale, float strength) {\n if (strength <= 0.001) return srgbColor;\n float bayer = ps2Bayer4x4(fragCoord / max(1.0, pixelScale)) - 0.5;\n vec3 quantized = clamp(floor(srgbColor * 31.0 + bayer + 0.5) / 31.0, 0.0, 1.0);\n return mix(srgbColor, quantized, strength);\n }\n";
1138
- // src/shaders/ps2RoadWebGL.ts
1139
- function $(e, t) {
1140
- let n = t.preset === "DIRT", r = {
1141
- uDetailArray: { value: e.detailArrayTex },
1142
- uTileScale: { value: t.tileScale ?? 1 / 3 },
1143
- uDitherTexelsPerMeter: { value: t.ditherTexelsPerMeter ?? 16 },
1144
- uCavityStrength: { value: t.cavityStrength ?? 1 },
1145
- uIsDirtRoad: { value: +!!n },
1146
- uCenterLineColor: { value: new a.Color(t.centerLineColor ?? 14393896) },
1147
- uEdgeLineColor: { value: new a.Color(t.edgeLineColor ?? 13815748) },
1148
- uPs2ColorQuantize: { value: t.ps2ColorQuantize ?? .85 },
1149
- uScreenPixelScale: { value: t.screenPixelScale ?? 1 }
1150
- }, i = new a.MeshLambertMaterial({
1151
- vertexColors: !0,
1152
- fog: !0,
1153
- polygonOffset: !0,
1154
- polygonOffsetFactor: -1,
1155
- polygonOffsetUnits: -1
1156
- });
1157
- return i.userData.__kolmoRetroApplied = !0, i.customProgramCacheKey = () => `ps2-road7v-${t.preset}-lambert-v1`, i.onBeforeCompile = (e) => {
1158
- Object.assign(e.uniforms, r), e.vertexShader = e.vertexShader.replace("#include <common>", "\n #include <common>\n varying vec2 vPs2Uv;\n varying vec3 vPs2WorldPos;\n ").replace("#include <project_vertex>", "\n vPs2Uv = uv;\n vec4 ps2Wp = vec4(transformed, 1.0);\n #ifdef USE_INSTANCING\n ps2Wp = instanceMatrix * ps2Wp;\n #endif\n ps2Wp = modelMatrix * ps2Wp;\n vPs2WorldPos = ps2Wp.xyz;\n #include <project_vertex>\n "), e.fragmentShader = e.fragmentShader.replace("#include <common>", `
1159
- #include <common>
1160
- precision mediump sampler2DArray;
1161
-
1162
- uniform sampler2DArray uDetailArray;
1163
- uniform float uTileScale;
1164
- uniform float uDitherTexelsPerMeter;
1165
- uniform float uCavityStrength;
1166
- uniform int uIsDirtRoad;
1167
- uniform vec3 uCenterLineColor;
1168
- uniform vec3 uEdgeLineColor;
1169
- uniform float uPs2ColorQuantize;
1170
- uniform float uScreenPixelScale;
1171
-
1172
- varying vec2 vPs2Uv;
1173
- varying vec3 vPs2WorldPos;
1174
-
1175
- ${Ze}
1176
- `).replace("#include <color_fragment>", `
1177
- float uSym = abs(vPs2Uv.x - 0.5);
1178
- float bayerWorld = ps2Bayer4x4(vPs2WorldPos.xz * uDitherTexelsPerMeter);
1179
- vec2 tileUv = vPs2WorldPos.xz * uTileScale;
1180
- vec2 dTileDx = dFdx(tileUv);
1181
- vec2 dTileDy = dFdy(tileUv);
1182
- vec3 roadAlbedo;
1183
-
1184
- if (uIsDirtRoad == 0) {
1185
- float gravelMix = smoothstep(0.285, 0.355, uSym);
1186
- float dirtSkirtMix = smoothstep(0.385, 0.465, uSym);
1187
- int surfLayer = ${Z.ASPHALT};
1188
- if (bayerWorld < dirtSkirtMix) {
1189
- surfLayer = ${Z.DIRT};
1190
- } else if (bayerWorld < gravelMix) {
1191
- surfLayer = ${Z.GRAVEL};
1192
- }
1193
- roadAlbedo = textureGrad(uDetailArray, vec3(tileUv, float(surfLayer)), dTileDx, dTileDy).rgb;
1194
-
1195
- float laneTrack = exp(-pow((uSym - 0.155) / 0.055, 2.0));
1196
- roadAlbedo *= (1.0 - 0.16 * laneTrack * (1.0 - gravelMix));
1197
-
1198
- float wearSignal = sin(vPs2WorldPos.x * 3.1 + cos(vPs2WorldPos.z * 2.7)) * 0.5 + 0.5;
1199
- float paintIntact = step(bayerWorld * 0.38, wearSignal * 0.85 + 0.18);
1200
-
1201
- float uAa = max(fwidth(uSym), 0.002);
1202
- float centerWidthMask = 1.0 - smoothstep(0.009 - uAa, 0.009 + uAa, uSym);
1203
- float vFract = fract(vPs2Uv.y);
1204
- float vAa = max(fwidth(vPs2Uv.y), 0.004);
1205
- float dashLongMask = 1.0 - smoothstep(0.19 - vAa, 0.19 + vAa, abs(vFract - 0.5));
1206
- float junctionClearMask = smoothstep(0.56, 0.66, vPs2Uv.y);
1207
- float yellowMask = centerWidthMask * dashLongMask * junctionClearMask * paintIntact;
1208
-
1209
- float edgeDist = abs(uSym - 0.285);
1210
- float whiteMask = (1.0 - smoothstep(0.008 - uAa, 0.008 + uAa, edgeDist)) * paintIntact;
1211
-
1212
- roadAlbedo = mix(roadAlbedo, uCenterLineColor, yellowMask * 0.90);
1213
- roadAlbedo = mix(roadAlbedo, uEdgeLineColor, whiteMask * 0.82);
1214
- } else {
1215
- float outerGrassMix = smoothstep(0.27, 0.42, uSym);
1216
- float centerHumpGrass = (1.0 - smoothstep(0.0, 0.065, uSym)) * 0.45;
1217
- float rutGravel = exp(-pow((uSym - 0.165) / 0.05, 2.0));
1218
- int surfLayer = ${Z.DIRT};
1219
- if (bayerWorld < max(outerGrassMix, centerHumpGrass)) {
1220
- surfLayer = ${Z.GRASS};
1221
- } else if (bayerWorld < rutGravel * 0.45) {
1222
- surfLayer = ${Z.GRAVEL};
1223
- }
1224
- roadAlbedo = textureGrad(uDetailArray, vec3(tileUv, float(surfLayer)), dTileDx, dTileDy).rgb;
1225
- roadAlbedo *= (1.0 - 0.18 * rutGravel);
1226
- }
1227
-
1228
- diffuseColor.rgb *= roadAlbedo;
1229
- `).replace("#include <aomap_fragment>", "\n #include <aomap_fragment>\n #if defined(USE_COLOR) || defined(USE_COLOR_ALPHA)\n float roadAo = clamp(vColor.r, 0.0, 1.0);\n reflectedLight.indirectDiffuse *= mix(1.0, pow(roadAo, 1.35), uCavityStrength);\n reflectedLight.directDiffuse *= mix(1.0, mix(0.65, 1.0, roadAo), uCavityStrength);\n #endif\n ").replace("#include <dithering_fragment>", "\n #include <dithering_fragment>\n gl_FragColor.rgb = ps2QuantizeRGB555(\n gl_FragColor.rgb,\n gl_FragCoord.xy,\n uScreenPixelScale,\n uPs2ColorQuantize\n );\n ");
1230
- }, {
1231
- material: i,
1232
- uniforms: r
1233
- };
1234
- }
1235
- // src/shaders/ps2TerrainWebGL.ts
1236
- function Qe(e, t = {}) {
1237
- let n = {
1238
- uSplat0: { value: e.splat0Tex },
1239
- uSplat1: { value: e.splat1Tex },
1240
- uAlphaTex: { value: e.alphaTex },
1241
- uDetailArray: { value: e.detailArrayTex },
1242
- uTileScale: { value: t.tileScale ?? 1 / 3 },
1243
- uDitherTexelsPerMeter: { value: t.ditherTexelsPerMeter ?? 16 },
1244
- uSplatContrast: { value: t.splatContrast ?? 1.65 },
1245
- uCavityStrength: { value: t.cavityStrength ?? 1 },
1246
- uCavityShadowTint: { value: new a.Color(7239820) },
1247
- uPs2ColorQuantize: { value: t.ps2ColorQuantize ?? .85 },
1248
- uScreenPixelScale: { value: t.screenPixelScale ?? 1 }
1249
- }, r = new a.MeshLambertMaterial({
1250
- vertexColors: !0,
1251
- fog: !0
1252
- });
1253
- r.userData.__kolmoRetroApplied = !0, r.customProgramCacheKey = () => "ps2-terrain-splat8-lambert-v1", r.onBeforeCompile = (e) => {
1254
- Object.assign(e.uniforms, n), e.vertexShader = e.vertexShader.replace("#include <common>", "\n #include <common>\n varying vec2 vPs2Uv;\n varying vec3 vPs2WorldPos;\n ").replace("#include <project_vertex>", "\n vPs2Uv = uv;\n vec4 ps2Wp = vec4(transformed, 1.0);\n #ifdef USE_INSTANCING\n ps2Wp = instanceMatrix * ps2Wp;\n #endif\n ps2Wp = modelMatrix * ps2Wp;\n vPs2WorldPos = ps2Wp.xyz;\n #include <project_vertex>\n "), e.fragmentShader = e.fragmentShader.replace("#include <common>", `
1255
- #include <common>
1256
- precision mediump sampler2DArray;
1257
-
1258
- uniform sampler2D uSplat0;
1259
- uniform sampler2D uSplat1;
1260
- uniform sampler2D uAlphaTex;
1261
- uniform sampler2DArray uDetailArray;
1262
-
1263
- uniform float uTileScale;
1264
- uniform float uDitherTexelsPerMeter;
1265
- uniform float uSplatContrast;
1266
- uniform float uCavityStrength;
1267
- uniform vec3 uCavityShadowTint;
1268
- uniform float uPs2ColorQuantize;
1269
- uniform float uScreenPixelScale;
1270
-
1271
- varying vec2 vPs2Uv;
1272
- varying vec3 vPs2WorldPos;
1273
-
1274
- ${Ze}
1275
- `).replace("#include <color_fragment>", "\n if (texture(uAlphaTex, vPs2Uv).r < 0.5) discard;\n\n vec4 s0 = pow(max(texture(uSplat0, vPs2Uv), vec4(0.0)), vec4(uSplatContrast));\n vec4 s1 = pow(max(texture(uSplat1, vPs2Uv), vec4(0.0)), vec4(uSplatContrast));\n float totalW = s0.r + s0.g + s0.b + s0.a + s1.r + s1.g + s1.b + s1.a;\n float invW = totalW > 1e-5 ? (1.0 / totalW) : 0.0;\n s0 *= invW;\n s1 *= invW;\n\n float bayerWorld = ps2Bayer4x4(vPs2WorldPos.xz * uDitherTexelsPerMeter);\n int winLayer = 7;\n float cdf = s0.r;\n if (bayerWorld < cdf) { winLayer = 0; }\n else if (bayerWorld < (cdf += s0.g)) { winLayer = 1; }\n else if (bayerWorld < (cdf += s0.b)) { winLayer = 2; }\n else if (bayerWorld < (cdf += s0.a)) { winLayer = 3; }\n else if (bayerWorld < (cdf += s1.r)) { winLayer = 4; }\n else if (bayerWorld < (cdf += s1.g)) { winLayer = 5; }\n else if (bayerWorld < (cdf += s1.b)) { winLayer = 6; }\n\n vec2 tileUv = vPs2WorldPos.xz * uTileScale;\n vec2 dTileDx = dFdx(tileUv);\n vec2 dTileDy = dFdy(tileUv);\n vec3 splatAlbedo = textureGrad(uDetailArray, vec3(tileUv, float(winLayer)), dTileDx, dTileDy).rgb;\n splatAlbedo *= ps2MacroVariation(vPs2WorldPos.xz);\n\n float rawCavity = 1.0;\n #if defined(USE_COLOR) || defined(USE_COLOR_ALPHA)\n rawCavity = vColor.r;\n #endif\n float cavityClamped = clamp(rawCavity, 0.0, 1.0);\n float ridgeLift = max(0.0, rawCavity - 1.0) * 0.85 * uCavityStrength;\n vec3 cavityTint = mix(uCavityShadowTint, vec3(1.0), cavityClamped);\n\n diffuseColor.rgb *= splatAlbedo * mix(vec3(1.0), cavityTint, uCavityStrength * 0.45) * (1.0 + ridgeLift);\n ").replace("#include <aomap_fragment>", "\n #include <aomap_fragment>\n #if defined(USE_COLOR) || defined(USE_COLOR_ALPHA)\n float ps2Ao = clamp(vColor.r, 0.0, 1.0);\n float indirectAo = mix(1.0, pow(ps2Ao, 1.45), uCavityStrength);\n float directAo = mix(1.0, mix(0.55, 1.0, ps2Ao), uCavityStrength);\n reflectedLight.indirectDiffuse *= indirectAo;\n reflectedLight.directDiffuse *= directAo;\n #endif\n ").replace("#include <dithering_fragment>", "\n #include <dithering_fragment>\n gl_FragColor.rgb = ps2QuantizeRGB555(\n gl_FragColor.rgb,\n gl_FragCoord.xy,\n uScreenPixelScale,\n uPs2ColorQuantize\n );\n ");
1276
- };
1277
- let i = new a.MeshDepthMaterial({ depthPacking: a.RGBADepthPacking });
1278
- return i.customProgramCacheKey = () => "ps2-terrain-depth-cutout-v1", i.onBeforeCompile = (e) => {
1279
- e.uniforms.uAlphaTex = n.uAlphaTex, e.vertexShader = e.vertexShader.replace("#include <common>", "#include <common>\nvarying vec2 vPs2DepthUv;").replace("#include <project_vertex>", "vPs2DepthUv = uv;\n#include <project_vertex>"), e.fragmentShader = e.fragmentShader.replace("#include <common>", "#include <common>\nuniform sampler2D uAlphaTex;\nvarying vec2 vPs2DepthUv;").replace("void main() {", "void main() {\n if (texture(uAlphaTex, vPs2DepthUv).r < 0.5) discard;");
1280
- }, {
1281
- material: r,
1282
- depthMaterial: i,
1283
- uniforms: n
1284
- };
1285
- }
1286
- // src/shaders/ps2MaterialsWebGL.ts
1287
- function $e(e, t, n, r, i) {
1288
- let o = 10335428;
1289
- e.background = new a.Color(o), e.fog = new a.FogExp2(o, .00145);
1290
- let s = new a.HemisphereLight(11059416, 5392440, .75);
1291
- e.add(s);
1292
- let c = new a.DirectionalLight(16773332, 1.35);
1293
- c.position.set(420, 680, 310), c.castShadow = !0, e.add(c);
1294
- let l = Xe(t), { material: u, depthMaterial: d } = Qe(l, {
1295
- ditherTexelsPerMeter: 16,
1296
- ps2ColorQuantize: .85
1297
- }), f = new a.Group();
1298
- for (let e of n) {
1299
- let t = new a.Mesh(e, u);
1300
- t.customDepthMaterial = d, t.castShadow = !0, t.receiveShadow = !0, t.matrixAutoUpdate = !1, t.updateMatrix(), f.add(t);
1301
- }
1302
- e.add(f);
1303
- let { material: p } = $(l, {
1304
- preset: "ASPHALT",
1305
- ditherTexelsPerMeter: 16,
1306
- ps2ColorQuantize: .85
1307
- }), m = new a.Mesh(r, p);
1308
- m.receiveShadow = !0, e.add(m);
1309
- let { material: h } = $(l, {
1310
- preset: "DIRT",
1311
- ditherTexelsPerMeter: 16,
1312
- ps2ColorQuantize: .85
1313
- }), g = new a.Mesh(i, h);
1314
- return g.receiveShadow = !0, e.add(g), {
1315
- texBundle: l,
1316
- terrainGroup: f,
1317
- asphaltMesh: m,
1318
- dirtMesh: g
1319
- };
1320
- }
1321
- // src/shaders/ps2MaterialsTSL.ts
1322
- function et(e) {
1323
- let t = b(e), n = T(t, 2), r = T(b(t.mul(.5)), 2), i = h(n.x.sub(n.y)).mul(2).add(n.y), a = h(r.x.sub(r.y)).mul(2).add(r.y);
1324
- return i.mul(4).add(a).add(.5).mul(.0625);
1325
- }
1326
- function tt(e, t, n) {
1327
- let r = et(k.xy.div(C(1, t))).sub(.5), i = g(b(e.mul(31).add(r).add(.5)).div(31), 0, 1);
1328
- return w(e, i, n);
1329
- }
1330
- function nt(e) {
1331
- let t = N(1 / 3), n = N(16), r = N(1.65), i = N(1), a = N(.85), o = N(1), s = new p.MeshLambertNodeMaterial({ fog: !0 }), c = P();
1332
- s.opacityNode = M(e.alphaTex, c).r, s.alphaTest = .5;
1333
- let l = I().r;
1334
- return s.aoNode = w(y(1), O(g(l, 0, 1), 1.45), i), s.colorNode = m(() => {
1335
- let a = C(M(e.splat0Tex, c), F(0)).pow(F(r)), o = C(M(e.splat1Tex, c), F(0)).pow(F(r)), s = a.r.add(a.g).add(a.b).add(a.a).add(o.r).add(o.g).add(o.b).add(o.a), u = y(1).div(C(s, 1e-5)), d = a.mul(u), f = o.mul(u), p = et(D.xz.mul(n)), m = D.xz.mul(t), h = M(e.detailSliceTexs[0], m).rgb, g = M(e.detailSliceTexs[1], m).rgb, v = M(e.detailSliceTexs[2], m).rgb, b = M(e.detailSliceTexs[3], m).rgb, x = M(e.detailSliceTexs[4], m).rgb, S = M(e.detailSliceTexs[5], m).rgb, T = M(e.detailSliceTexs[6], m).rgb, E = M(e.detailSliceTexs[7], m).rgb, O = d.r, k = O.add(d.g), A = k.add(d.b), N = A.add(d.a), P = N.add(f.r), I = P.add(f.g), L = I.add(f.b), R = E;
1336
- R = w(R, T, j(p, L)), R = w(R, S, j(p, I)), R = w(R, x, j(p, P)), R = w(R, b, j(p, N)), R = w(R, v, j(p, A)), R = w(R, g, j(p, k)), R = w(R, h, j(p, O));
1337
- let z = w(y(.88), y(1.1), ee(D.x.mul(.062).add(_(D.z.mul(.048)))).mul(.5).add(.5)), te = C(0, l.sub(1)).mul(.85).mul(i);
1338
- return R.mul(z).mul(y(1).add(te));
1339
- })(), s.outputNode = m(() => F(tt(E.rgb, o, a), E.a))(), {
1340
- material: s,
1341
- uniforms: {
1342
- uTileScale: t,
1343
- uDitherTexels: n,
1344
- uSplatContrast: r,
1345
- uCavityStrength: i,
1346
- uPs2Quantize: a,
1347
- uPixelScale: o
1348
- }
1349
- };
1350
- }
1351
- function rt(e, t = "ASPHALT") {
1352
- let n = N(1 / 3), r = N(16), i = N(1), a = N(.85), o = N(1), s = N(new p.Color(14393896)), c = N(new p.Color(13815748)), l = new p.MeshLambertNodeMaterial({
1353
- fog: !0,
1354
- polygonOffset: !0,
1355
- polygonOffsetFactor: -1,
1356
- polygonOffsetUnits: -1
1357
- }), u = g(I().r, 0, 1);
1358
- l.aoNode = w(y(1), O(u, 1.35), i);
1359
- let d = P();
1360
- return l.colorNode = m(() => {
1361
- let i = h(d.x.sub(.5)), a = et(D.xz.mul(r)), o = D.xz.mul(n), l = M(e.detailSliceTexs[0], o).rgb, u = M(e.detailSliceTexs[1], o).rgb, f = M(e.detailSliceTexs[4], o).rgb, p = M(e.detailSliceTexs[7], o).rgb;
1362
- if (t === "DIRT") {
1363
- let e = A(.27, .42, i), t = y(1).sub(A(0, .065, i)).mul(.45), n = v(O(i.sub(.165).div(.05), 2).negate()), r = w(l, f, j(a, n.mul(.45)));
1364
- return r = w(r, u, j(a, C(e, t))), r.mul(y(1).sub(n.mul(.18)));
1365
- }
1366
- let m = A(.285, .355, i), g = A(.385, .465, i), b = w(p, f, j(a, m));
1367
- b = w(b, l, j(a, g));
1368
- let T = v(O(i.sub(.155).div(.055), 2).negate());
1369
- b = b.mul(y(1).sub(T.mul(.16).mul(y(1).sub(m))));
1370
- let E = ee(D.x.mul(3.1).add(_(D.z.mul(2.7)))).mul(.5).add(.5), k = j(a.mul(.38), E.mul(.85).add(.18)), N = C(S(i), .002), P = C(S(d.y), .004), F = y(1).sub(A(y(.009).sub(N), y(.009).add(N), i)), I = y(1).sub(A(y(.19).sub(P), y(.19).add(P), h(x(d.y).sub(.5)))), L = A(.56, .66, d.y), R = F.mul(I).mul(L).mul(k), z = y(1).sub(A(y(.008).sub(N), y(.008).add(N), h(i.sub(.285)))).mul(k);
1371
- return b = w(b, s, R.mul(.9)), w(b, c, z.mul(.82));
1372
- })(), l.outputNode = m(() => F(tt(E.rgb, o, a), E.a))(), {
1373
- material: l,
1374
- uniforms: {
1375
- uTileScale: n,
1376
- uDitherTexels: r,
1377
- uCavityStrength: i,
1378
- uPs2Quantize: a,
1379
- uPixelScale: o
1380
- }
1381
- };
1382
- }
1383
- export { de as A, oe as B, B as C, K as D, xe as E, L as F, le as I, ce as L, ye as M, R as N, Se as O, z as P, ne as R, G as S, V as T, ae as V, Oe as _, $ as a, Te as b, Ye as c, J as d, Ge as f, Pe as g, We as h, Qe as i, ve as j, fe as k, ze as l, Fe as m, nt as n, Z as o, Be as p, $e as r, Xe as s, rt as t, Re as u, De as v, H as w, W as x, Ee as y, ue as z };