@pinkaphant/kolmo 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +16 -14
- package/bin/kolmo.mjs +19 -54
- package/dist/body/HeldItem.d.ts +22 -0
- package/dist/body/HeldItem.js +171 -0
- package/dist/body/KhrBody.d.ts +26 -0
- package/dist/body/KhrBody.js +179 -0
- package/dist/body/bodySi.d.ts +59 -0
- package/dist/body/bodySi.js +61 -0
- package/dist/body/index.d.ts +3 -0
- package/dist/body/index.js +4 -0
- package/dist/engine/index.d.ts +4 -4
- package/dist/engine/index.js +12 -3
- package/dist/engine/kolmoActor.d.ts +11 -4
- package/dist/engine/kolmoActor.js +197 -0
- package/dist/engine/kolmoInput.d.ts +12 -0
- package/dist/engine/kolmoInput.js +80 -0
- package/dist/engine/kolmoIsland.d.ts +3 -1
- package/dist/engine/kolmoIsland.js +311 -0
- package/dist/engine/kolmoLongDrive.js +223 -0
- package/dist/engine/kolmoRigs.js +59 -0
- package/dist/engine/kolmoStore.d.ts +53 -27
- package/dist/engine/kolmoStore.js +211 -0
- package/dist/engine/kolmoSurface.d.ts +1 -1
- package/dist/engine/kolmoSurface.js +182 -0
- package/dist/engine/kolmoVehicle.d.ts +2 -1
- package/dist/engine/kolmoVehicle.js +244 -0
- package/dist/engine/kolmoVehicleDriver.d.ts +30 -0
- package/dist/engine/kolmoVehicleDriver.js +38 -0
- package/dist/engine/kolmoWorld.d.ts +7 -15
- package/dist/engine/kolmoWorld.js +136 -0
- package/dist/engine/longDriveKit.d.ts +4 -2
- package/dist/engine/longDriveKit.js +254 -0
- package/dist/engine/mainlandMacroCell.d.ts +3 -7
- package/dist/engine/mainlandMacroCell.js +247 -0
- package/dist/engine/shiftedFixedBody.d.ts +13 -0
- package/dist/engine/shiftedFixedBody.js +64 -0
- package/dist/importer/ChopShopPanel.js +465 -0
- package/dist/importer/DomainWorkshopPanel.d.ts +9 -4
- package/dist/importer/DomainWorkshopPanel.js +385 -0
- package/dist/importer/GateHudBar.js +312 -0
- package/dist/importer/GlbImportGate.js +250 -0
- package/dist/importer/ImperativeVehicleRig.js +336 -0
- package/dist/importer/ImporterPlinthUikitTags.js +112 -0
- package/dist/importer/Step1CalibrationPlinth.js +275 -0
- package/dist/importer/Step2UniversalPad.js +244 -0
- package/dist/importer/VfxEmitterPool.js +91 -0
- package/dist/importer/chopShopActions.d.ts +22 -2
- package/dist/importer/chopShopActions.js +232 -0
- package/dist/importer/gateStore.d.ts +1 -1
- package/dist/importer/gateStore.js +92 -0
- package/dist/importer/glbNormalizer.js +133 -0
- package/dist/importer/importerWebMcp.d.ts +17 -6
- package/dist/importer/importerWebMcp.js +343 -0
- package/dist/importer/index.js +22 -3
- package/dist/importer/khrCompiler.d.ts +1 -1
- package/dist/importer/khrCompiler.js +434 -0
- package/dist/importer/launcherBake.js +51 -0
- package/dist/importer/meshIslands.d.ts +1 -1
- package/dist/importer/meshIslands.js +301 -0
- package/dist/importer/surfaceCutter.js +254 -0
- package/dist/importer/surfaceTopology.js +183 -0
- package/dist/importer/universalGateBake.js +162 -0
- package/dist/importer/usdToGlb.js +294 -0
- package/dist/importer/useChopShopController.d.ts +11 -2
- package/dist/importer/useChopShopController.js +364 -0
- package/dist/importer/vehiclePanelAnim.js +214 -0
- package/dist/importer/wheelAxlePairing.d.ts +1 -2
- package/dist/importer/wheelAxlePairing.js +102 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +69 -14
- package/dist/junk/DestructibleTarget.js +154 -0
- package/dist/junk/KolmoJunk.js +65 -0
- package/dist/junk/ShardPieces.d.ts +6 -4
- package/dist/junk/ShardPieces.js +74 -0
- package/dist/junk/TargetDecals.js +51 -0
- package/dist/junk/bvhShatter.js +55 -0
- package/dist/junk/bvhTriCollector.js +78 -0
- package/dist/junk/index.js +11 -1
- package/dist/junk/junkGeometry.js +69 -0
- package/dist/junk/junkImportSanitize.js +54 -0
- package/dist/junk/junkImporter.js +95 -0
- package/dist/junk/junkLabelCanvas.js +67 -0
- package/dist/junk/junkLabels.js +35 -0
- package/dist/junk/targetHelpers.js +103 -0
- package/dist/junk/targetHitLogic.js +128 -0
- package/dist/junk/useTargetAssets.js +102 -0
- package/dist/physics/index.d.ts +26 -0
- package/dist/physics/index.js +84 -0
- package/dist/schema/kolmoSchema.d.ts +2 -1
- package/dist/schema/kolmoSchema.js +184 -0
- package/dist/shaders/celestialBackdrop.d.ts +1 -1
- package/dist/shaders/celestialBackdrop.js +344 -0
- package/dist/shaders/index.d.ts +0 -1
- package/dist/shaders/index.js +9 -1
- package/dist/shaders/plumeAndSparkle.js +271 -0
- package/dist/shaders/ps2GlslShared.d.ts +1 -1
- package/dist/shaders/ps2GlslShared.js +3 -0
- package/dist/shaders/ps2MaterialsTSL.js +65 -0
- package/dist/shaders/ps2MaterialsWebGL.js +40 -0
- package/dist/shaders/ps2RoadWebGL.js +101 -0
- package/dist/shaders/ps2TerrainWebGL.js +54 -0
- package/dist/shaders/ps2Textures.js +224 -0
- package/dist/shaders/retroPalettes.js +188 -0
- package/dist/shaders/retroShader.d.ts +31 -3
- package/dist/shaders/retroShader.js +249 -0
- package/dist/shaders/tsl.d.ts +1 -0
- package/dist/shaders/tsl.js +1 -0
- package/dist/vite/index.d.ts +15 -0
- package/dist/vite/index.js +90 -0
- package/dist/world/frontage.js +32 -0
- package/dist/world/index.d.ts +1 -1
- package/dist/world/index.js +11 -3
- package/dist/world/infiniteWorld2D.js +244 -0
- package/dist/world/island.js +201 -0
- package/dist/world/macroCellSchema.js +27 -0
- package/dist/world/macroKnightAStar.js +171 -0
- package/dist/world/random.js +33 -0
- package/dist/world/road.js +136 -0
- package/dist/world/roadRibbon.d.ts +6 -6
- package/dist/world/roadRibbon.js +161 -0
- package/dist/world/terrain.js +87 -0
- package/dist/world/worldTypes.js +111 -0
- package/package.json +36 -19
- package/dist/engine-BeKvBM8d.js +0 -1745
- package/dist/importer-D9bdcGTh.js +0 -5113
- package/dist/junk-B4bC1zAl.js +0 -1049
- package/dist/kolmoSurface-DTnrFXH0.js +0 -558
- package/dist/shaders-GS71Ek1A.js +0 -1383
- package/dist/world-PRWPYrlx.js +0 -947
- package/dist/worldTypes-Z0KfdCd0.js +0 -226
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { GLSL_BAYER_RGB555 as e, RETRO_UNIFORMS as t } from "./retroShader.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 { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
6
|
+
// src/shaders/plumeAndSparkle.tsx
|
|
7
|
+
var u = 48, d = [
|
|
8
|
+
0,
|
|
9
|
+
0,
|
|
10
|
+
0
|
|
11
|
+
], f = "\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", p = `
|
|
12
|
+
uniform vec2 uPs1Grid; uniform float uSnapStrength, uTime, uThrottle, uBoost;
|
|
13
|
+
varying vec2 vUv;
|
|
14
|
+
void main() {
|
|
15
|
+
vUv = uv; vec3 p = position; float along = clamp(uv.y, 0.0, 1.0);
|
|
16
|
+
float shock = sin(along * 22.0 - uTime * (16.0 + uBoost * 24.0)) * (0.045 + uBoost * 0.085) * along;
|
|
17
|
+
p.xz *= 1.0 + shock + along * (uThrottle * 0.25 + uBoost * 0.52);
|
|
18
|
+
vec4 clip = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
|
|
19
|
+
${f}
|
|
20
|
+
gl_Position = clip;
|
|
21
|
+
}
|
|
22
|
+
`, m = `
|
|
23
|
+
uniform float uTime, uThrottle, uBoost, uIntensity, uDitherMix;
|
|
24
|
+
uniform vec3 uColorCore, uColorMid, uColorOuter;
|
|
25
|
+
varying vec2 vUv;
|
|
26
|
+
${e}
|
|
27
|
+
void main() {
|
|
28
|
+
float along = clamp(vUv.y, 0.0, 1.0);
|
|
29
|
+
float tailFade = pow(1.0 - along, 1.15 - uBoost * 0.28), nozzleFade = smoothstep(0.0, 0.09, along);
|
|
30
|
+
float throatHot = exp(-along * 5.2) * (0.65 + uThrottle * 0.55 + uBoost * 0.9);
|
|
31
|
+
float machWave = sin(along * 28.0 - uTime * (16.0 + uThrottle * 10.0 + uBoost * 22.0)) * 0.5 + 0.5;
|
|
32
|
+
float machCells = mix(machWave, step(0.42, machWave), uDitherMix * 0.85);
|
|
33
|
+
float spiral = sin(vUv.x * 37.699 + along * 10.0 - uTime * 14.0) * 0.16 + 0.84;
|
|
34
|
+
float density = (tailFade * (0.62 + machCells * 0.38) * spiral + throatHot * 0.45) * nozzleFade * uIntensity;
|
|
35
|
+
if (density < mix(0.04, ps1Bayer4x4(gl_FragCoord.xy * 0.5) * 0.56 + 0.05, uDitherMix)) discard;
|
|
36
|
+
vec3 cruise = mix(mix(uColorCore, uColorMid, smoothstep(0.05, 0.36, along)), uColorOuter, smoothstep(0.36, 0.88, along));
|
|
37
|
+
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));
|
|
38
|
+
boostC += vec3(0.22, 0.52, 0.65) * machCells * (1.0 - along) * 0.45;
|
|
39
|
+
vec3 col = mix(cruise, boostC, uBoost * 0.85) * (0.82 + uThrottle * 0.22 + uBoost * 0.28 + throatHot * 0.22);
|
|
40
|
+
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));
|
|
41
|
+
}
|
|
42
|
+
`, h = `
|
|
43
|
+
attribute float aPhase, aAngle, aRadius, aSpeed, aSize;
|
|
44
|
+
uniform float uTime, uDrive, uBoost, uScale, uMode, uSnapStrength;
|
|
45
|
+
uniform vec2 uPs1Grid;
|
|
46
|
+
varying float vLife, vBoost;
|
|
47
|
+
void main() {
|
|
48
|
+
float life = fract(aPhase + uTime * (0.7 + uDrive * 0.9 + uBoost * 1.4) * aSpeed);
|
|
49
|
+
vLife = life; vBoost = uBoost;
|
|
50
|
+
float coneLen = (1.35 + uDrive * 2.5 + uBoost * 4.4) * (uMode > 1.5 ? 1.55 : 1.0) * uScale;
|
|
51
|
+
float z = -(0.04 * uScale + life * coneLen);
|
|
52
|
+
float spread = uMode > 0.5 && uMode < 1.5 ? 1.6 : (uMode > 1.5 ? 0.42 : 0.88);
|
|
53
|
+
float flare = aRadius * uScale * spread * (0.22 + life * (0.85 + uBoost * 0.95));
|
|
54
|
+
float ang = aAngle + life * (3.2 + uBoost * 4.2) - uTime * 2.9;
|
|
55
|
+
float rise = (uMode > 0.5 && uMode < 1.5) ? life * life * 0.52 * uScale : 0.0;
|
|
56
|
+
vec4 mvPos = modelViewMatrix * vec4(cos(ang) * flare, sin(ang) * flare + rise, z, 1.0);
|
|
57
|
+
vec4 clip = projectionMatrix * mvPos;
|
|
58
|
+
${f}
|
|
59
|
+
gl_Position = clip;
|
|
60
|
+
float szMul = uMode > 0.5 && uMode < 1.5 ? (0.75 + life * 0.95) : (1.0 - life * 0.65);
|
|
61
|
+
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);
|
|
62
|
+
}
|
|
63
|
+
`, g = `
|
|
64
|
+
uniform float uDitherMix, uMode;
|
|
65
|
+
uniform vec3 uColor;
|
|
66
|
+
varying float vLife, vBoost;
|
|
67
|
+
${e}
|
|
68
|
+
void main() {
|
|
69
|
+
vec2 p = abs(gl_PointCoord - 0.5) * 2.0;
|
|
70
|
+
float manhattan = p.x + p.y;
|
|
71
|
+
if (manhattan > 1.05) discard;
|
|
72
|
+
float fade = (1.0 - vLife) * (1.0 - vLife * 0.35);
|
|
73
|
+
if (uMode > 0.5 && uMode < 1.5) {
|
|
74
|
+
if (fade < ps1Bayer4x4(gl_FragCoord.xy * 0.5) * 0.75 * uDitherMix) discard;
|
|
75
|
+
gl_FragColor = vec4(ps1QuantizeRGB555Mix(mix(uColor * 1.1, uColor * 0.45, vLife), gl_FragCoord.xy, uDitherMix), clamp(fade * 0.68, 0.0, 0.8));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
float core = 1.0 - smoothstep(0.0, 1.05, manhattan);
|
|
79
|
+
vec3 cEnd = uMode > 1.5 ? uColor * 0.55 : mix(uColor * 0.7, vec3(1.0, 0.48, 0.1), 0.55 + vBoost * 0.45);
|
|
80
|
+
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));
|
|
81
|
+
col *= 1.05 + vBoost * 0.85 + core * 0.5;
|
|
82
|
+
gl_FragColor = vec4(ps1QuantizeRGB555Mix(clamp(col, 0.0, 1.0), gl_FragCoord.xy, uDitherMix), clamp(fade * 0.9, 0.0, 0.95));
|
|
83
|
+
}
|
|
84
|
+
`, _ = new a.CylinderGeometry(.06, .28, 1, 8, 5, !0).translate(0, .5, 0), v = new a.CylinderGeometry(.03, .16, 1, 8, 5, !0).translate(0, .5, 0), y = new a.CircleGeometry(.11, 6), b = (() => {
|
|
85
|
+
let e = new a.BufferGeometry(), t = new Float32Array(u), n = new Float32Array(u), r = new Float32Array(u), i = new Float32Array(u), o = new Float32Array(u);
|
|
86
|
+
for (let e = 0; e < u; e++) t[e] = e / u, 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;
|
|
87
|
+
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;
|
|
88
|
+
})();
|
|
89
|
+
function x({ e, signalsRef: u }) {
|
|
90
|
+
let d = i(null), f = i(null), x = i(null), S = i(null), C = i(0), w = i(null), T = r(() => {
|
|
91
|
+
let n = new a.Color(e.color[0], e.color[1], e.color[2]);
|
|
92
|
+
if (e.kind === "plume") {
|
|
93
|
+
let e = (e, n, r, i) => new a.ShaderMaterial({
|
|
94
|
+
uniforms: {
|
|
95
|
+
uPs1Grid: t.uPs1Grid,
|
|
96
|
+
uSnapStrength: t.uSnapStrength,
|
|
97
|
+
uDitherMix: t.uDitherMix,
|
|
98
|
+
uTime: { value: 0 },
|
|
99
|
+
uThrottle: { value: 0 },
|
|
100
|
+
uBoost: { value: 0 },
|
|
101
|
+
uIntensity: { value: i },
|
|
102
|
+
uColorCore: { value: e },
|
|
103
|
+
uColorMid: { value: n },
|
|
104
|
+
uColorOuter: { value: r }
|
|
105
|
+
},
|
|
106
|
+
vertexShader: p,
|
|
107
|
+
fragmentShader: m,
|
|
108
|
+
transparent: !0,
|
|
109
|
+
depthWrite: !1,
|
|
110
|
+
blending: a.AdditiveBlending,
|
|
111
|
+
side: a.DoubleSide,
|
|
112
|
+
toneMapped: !1
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
outer: e(n.clone().lerp(new a.Color("#ffffff"), .65), n.clone(), n.clone().multiplyScalar(.45), .72),
|
|
116
|
+
inner: e(new a.Color("#ffffff"), n.clone().lerp(new a.Color("#ffffff"), .45), n.clone(), .92)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (e.kind === "flare") {
|
|
120
|
+
let e = {
|
|
121
|
+
transparent: !0,
|
|
122
|
+
opacity: 0,
|
|
123
|
+
depthWrite: !1,
|
|
124
|
+
blending: a.AdditiveBlending,
|
|
125
|
+
side: a.DoubleSide,
|
|
126
|
+
toneMapped: !1
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
halo: new a.MeshBasicMaterial({
|
|
130
|
+
color: n,
|
|
131
|
+
...e
|
|
132
|
+
}),
|
|
133
|
+
core: new a.MeshBasicMaterial({
|
|
134
|
+
color: n.clone().lerp(new a.Color("#ffffff"), .7),
|
|
135
|
+
...e
|
|
136
|
+
})
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
let r = e.kind === "fume" ? 1 : e.kind === "trail" ? 2 : 0;
|
|
140
|
+
return { pts: new a.ShaderMaterial({
|
|
141
|
+
uniforms: {
|
|
142
|
+
uPs1Grid: t.uPs1Grid,
|
|
143
|
+
uSnapStrength: t.uSnapStrength,
|
|
144
|
+
uDitherMix: t.uDitherMix,
|
|
145
|
+
uTime: { value: 0 },
|
|
146
|
+
uDrive: { value: 0 },
|
|
147
|
+
uBoost: { value: 0 },
|
|
148
|
+
uScale: { value: e.size },
|
|
149
|
+
uMode: { value: r },
|
|
150
|
+
uColor: { value: n }
|
|
151
|
+
},
|
|
152
|
+
vertexShader: h,
|
|
153
|
+
fragmentShader: g,
|
|
154
|
+
transparent: !0,
|
|
155
|
+
depthWrite: !1,
|
|
156
|
+
blending: e.kind === "fume" ? a.NormalBlending : a.AdditiveBlending,
|
|
157
|
+
toneMapped: !1
|
|
158
|
+
}) };
|
|
159
|
+
}, [
|
|
160
|
+
e.kind,
|
|
161
|
+
e.size,
|
|
162
|
+
e.color[0],
|
|
163
|
+
e.color[1],
|
|
164
|
+
e.color[2]
|
|
165
|
+
]);
|
|
166
|
+
return n(() => {
|
|
167
|
+
let t, n = e.object;
|
|
168
|
+
if (e.kind === "flare" && n?.isMesh && n.material && !Array.isArray(n.material) && "emissive" in n.material) {
|
|
169
|
+
t = n.material;
|
|
170
|
+
let r = t.clone();
|
|
171
|
+
r.emissive.setRGB(e.color[0], e.color[1], e.color[2]), n.material = r, w.current = r;
|
|
172
|
+
}
|
|
173
|
+
return () => {
|
|
174
|
+
t && n?.isMesh && (n.material = t), w.current?.dispose(), w.current = null, Object.values(T).forEach((e) => e?.dispose());
|
|
175
|
+
};
|
|
176
|
+
}, [
|
|
177
|
+
e.kind,
|
|
178
|
+
e.object,
|
|
179
|
+
e.color[0],
|
|
180
|
+
e.color[1],
|
|
181
|
+
e.color[2],
|
|
182
|
+
T
|
|
183
|
+
]), o((t, n) => {
|
|
184
|
+
let r = Math.min(n, .05), i = u.current, o = i ? a.MathUtils.clamp(i[e.drive], 0, 1) : 0, s = i ? a.MathUtils.clamp(e.drive === "boost" ? o : i.boost, 0, 1) : 0;
|
|
185
|
+
if (T.outer && T.inner && d.current && f.current) {
|
|
186
|
+
let t = o > .015;
|
|
187
|
+
if (d.current.visible = t, f.current.visible = t, !t) return;
|
|
188
|
+
C.current += r * (5 + o * 7 + s * 16);
|
|
189
|
+
let n = e.size * (.48 + o * 1.35 + s * 1.95) * (.94 + Math.sin(C.current * 4.7) * .06), i = e.size * (.58 + o * .24 + s * .34);
|
|
190
|
+
d.current.scale.set(i, n, i), f.current.scale.set(i * .54, n * .74, i * .54), T.outer.uniforms.uTime.value = C.current, T.outer.uniforms.uThrottle.value = o, T.outer.uniforms.uBoost.value = s, T.inner.uniforms.uTime.value = C.current * 1.25, T.inner.uniforms.uThrottle.value = o, T.inner.uniforms.uBoost.value = s;
|
|
191
|
+
} else if (T.pts && x.current) {
|
|
192
|
+
if (x.current.visible = o > .015, !x.current.visible) return;
|
|
193
|
+
T.pts.uniforms.uTime.value += r, T.pts.uniforms.uDrive.value = o, T.pts.uniforms.uBoost.value = s;
|
|
194
|
+
} else if (T.halo && T.core && S.current) {
|
|
195
|
+
let n = o * ((e.drive === "turn_l" || e.drive === "turn_r") && o > .5 ? Math.sin(t.clock.elapsedTime * 18) > -.1 ? 1 : .06 : 1);
|
|
196
|
+
S.current.visible = n > .02, S.current.scale.setScalar(e.size * (.65 + n * .75)), T.halo.opacity = n * .78, T.core.opacity = Math.min(1, n * .96), w.current && (w.current.emissiveIntensity = .15 + n * 2.4);
|
|
197
|
+
}
|
|
198
|
+
}), /* @__PURE__ */ l("group", {
|
|
199
|
+
position: e.localPosition,
|
|
200
|
+
quaternion: e.localQuaternion,
|
|
201
|
+
children: [
|
|
202
|
+
e.kind === "plume" && T.outer && T.inner && /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("mesh", {
|
|
203
|
+
ref: f,
|
|
204
|
+
geometry: v,
|
|
205
|
+
material: T.inner,
|
|
206
|
+
rotation: [
|
|
207
|
+
-Math.PI / 2,
|
|
208
|
+
0,
|
|
209
|
+
0
|
|
210
|
+
],
|
|
211
|
+
frustumCulled: !1
|
|
212
|
+
}), /* @__PURE__ */ c("mesh", {
|
|
213
|
+
ref: d,
|
|
214
|
+
geometry: _,
|
|
215
|
+
material: T.outer,
|
|
216
|
+
rotation: [
|
|
217
|
+
-Math.PI / 2,
|
|
218
|
+
0,
|
|
219
|
+
0
|
|
220
|
+
],
|
|
221
|
+
frustumCulled: !1
|
|
222
|
+
})] }),
|
|
223
|
+
(e.kind === "sparkle" || e.kind === "fume" || e.kind === "trail") && T.pts && /* @__PURE__ */ c("points", {
|
|
224
|
+
ref: x,
|
|
225
|
+
geometry: b,
|
|
226
|
+
material: T.pts,
|
|
227
|
+
frustumCulled: !1
|
|
228
|
+
}),
|
|
229
|
+
e.kind === "flare" && T.halo && T.core && /* @__PURE__ */ l("group", {
|
|
230
|
+
ref: S,
|
|
231
|
+
position: [
|
|
232
|
+
0,
|
|
233
|
+
0,
|
|
234
|
+
-.015
|
|
235
|
+
],
|
|
236
|
+
children: [/* @__PURE__ */ c("mesh", {
|
|
237
|
+
geometry: y,
|
|
238
|
+
material: T.halo
|
|
239
|
+
}), /* @__PURE__ */ c("mesh", {
|
|
240
|
+
geometry: y,
|
|
241
|
+
material: T.core,
|
|
242
|
+
scale: .48,
|
|
243
|
+
position: [
|
|
244
|
+
0,
|
|
245
|
+
0,
|
|
246
|
+
-.004
|
|
247
|
+
]
|
|
248
|
+
})]
|
|
249
|
+
})
|
|
250
|
+
]
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function S({ emitters: e, signalsRef: t, comOffset: n = d }) {
|
|
254
|
+
let i = r(() => [
|
|
255
|
+
-n[0],
|
|
256
|
+
-n[1],
|
|
257
|
+
-n[2]
|
|
258
|
+
], [
|
|
259
|
+
n[0],
|
|
260
|
+
n[1],
|
|
261
|
+
n[2]
|
|
262
|
+
]);
|
|
263
|
+
return e.length === 0 ? null : /* @__PURE__ */ c("group", {
|
|
264
|
+
position: i,
|
|
265
|
+
children: e.map((e, n) => /* @__PURE__ */ c(x, {
|
|
266
|
+
e,
|
|
267
|
+
signalsRef: t
|
|
268
|
+
}, `${e.nodeName}-${n}`))
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
export { S as KolmoEmitterRig, g as PARTICLE_FRAG, h as PARTICLE_VERT, m as PLUME_FRAG, p as PLUME_VERT };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as THREE from "three";
|
|
2
|
-
export declare const SHARED_PS2_GLSL_HELPERS = "\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
|
|
2
|
+
export declare const SHARED_PS2_GLSL_HELPERS = "\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 const float PS2_OMEGA_192 = 6.283185307179586 / 192.0;\n\n float ps2MacroVariation(vec2 worldXZ) {\n float n = sin(worldXZ.x * (2.0 * PS2_OMEGA_192) + cos(worldXZ.y * PS2_OMEGA_192)) * 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";
|
|
3
3
|
export interface PS2TerrainMaterialOptions {
|
|
4
4
|
readonly tileScale?: number;
|
|
5
5
|
readonly ditherTexelsPerMeter?: number;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// src/shaders/ps2GlslShared.ts
|
|
2
|
+
var e = "\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 const float PS2_OMEGA_192 = 6.283185307179586 / 192.0;\n\n float ps2MacroVariation(vec2 worldXZ) {\n float n = sin(worldXZ.x * (2.0 * PS2_OMEGA_192) + cos(worldXZ.y * PS2_OMEGA_192)) * 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";
|
|
3
|
+
export { e as SHARED_PS2_GLSL_HELPERS };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as e from "three/webgpu";
|
|
2
|
+
import { Fn as t, abs as n, clamp as r, cos as i, exp as a, float as o, floor as s, fract as c, fwidth as l, max as u, mix as d, mod as f, output as p, positionWorld as m, pow as h, screenCoordinate as g, sin as _, smoothstep as v, step as y, texture as b, uniform as x, uv as S, vec4 as C, vertexColor as w } from "three/tsl";
|
|
3
|
+
// src/shaders/ps2MaterialsTSL.ts
|
|
4
|
+
function T(e) {
|
|
5
|
+
let t = s(e), r = f(t, 2), i = f(s(t.mul(.5)), 2), a = n(r.x.sub(r.y)).mul(2).add(r.y), o = n(i.x.sub(i.y)).mul(2).add(i.y);
|
|
6
|
+
return a.mul(4).add(o).add(.5).mul(.0625);
|
|
7
|
+
}
|
|
8
|
+
function E(e, t, n) {
|
|
9
|
+
let i = T(g.xy.div(u(1, t))).sub(.5), a = r(s(e.mul(31).add(i).add(.5)).div(31), 0, 1);
|
|
10
|
+
return d(e, a, n);
|
|
11
|
+
}
|
|
12
|
+
function D(n) {
|
|
13
|
+
let a = x(1 / 3), s = x(16), c = x(1.65), l = x(1), f = x(.85), g = x(1), v = new e.MeshLambertNodeMaterial({ fog: !0 }), D = S();
|
|
14
|
+
v.opacityNode = b(n.alphaTex, D).r, v.alphaTest = .5;
|
|
15
|
+
let O = w().r;
|
|
16
|
+
return v.aoNode = d(o(1), h(r(O, 0, 1), 1.45), l), v.colorNode = t(() => {
|
|
17
|
+
let e = u(b(n.splat0Tex, D), C(0)).pow(C(c)), t = u(b(n.splat1Tex, D), C(0)).pow(C(c)), r = e.r.add(e.g).add(e.b).add(e.a).add(t.r).add(t.g).add(t.b).add(t.a), f = o(1).div(u(r, 1e-5)), p = e.mul(f), h = t.mul(f), g = T(m.xz.mul(s)), v = m.xz.mul(a), x = b(n.detailSliceTexs[0], v).rgb, S = b(n.detailSliceTexs[1], v).rgb, w = b(n.detailSliceTexs[2], v).rgb, E = b(n.detailSliceTexs[3], v).rgb, k = b(n.detailSliceTexs[4], v).rgb, A = b(n.detailSliceTexs[5], v).rgb, j = b(n.detailSliceTexs[6], v).rgb, M = b(n.detailSliceTexs[7], v).rgb, N = p.r, P = N.add(p.g), F = P.add(p.b), I = F.add(p.a), L = I.add(h.r), R = L.add(h.g), z = R.add(h.b), B = M;
|
|
18
|
+
B = d(B, j, y(g, z)), B = d(B, A, y(g, R)), B = d(B, k, y(g, L)), B = d(B, E, y(g, I)), B = d(B, w, y(g, F)), B = d(B, S, y(g, P)), B = d(B, x, y(g, N));
|
|
19
|
+
let V = 6.283185307179586 / 192, H = d(o(.88), o(1.1), _(m.x.mul(2 * V).add(i(m.z.mul(V)))).mul(.5).add(.5)), U = u(0, O.sub(1)).mul(.85).mul(l);
|
|
20
|
+
return B.mul(H).mul(o(1).add(U));
|
|
21
|
+
})(), v.outputNode = t(() => C(E(p.rgb, g, f), p.a))(), {
|
|
22
|
+
material: v,
|
|
23
|
+
uniforms: {
|
|
24
|
+
uTileScale: a,
|
|
25
|
+
uDitherTexels: s,
|
|
26
|
+
uSplatContrast: c,
|
|
27
|
+
uCavityStrength: l,
|
|
28
|
+
uPs2Quantize: f,
|
|
29
|
+
uPixelScale: g
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function O(s, f = "ASPHALT") {
|
|
34
|
+
let g = x(1 / 3), D = x(16), O = x(1), k = x(.85), A = x(1), j = x(new e.Color(14393896)), M = x(new e.Color(13815748)), N = new e.MeshLambertNodeMaterial({
|
|
35
|
+
fog: !0,
|
|
36
|
+
polygonOffset: !0,
|
|
37
|
+
polygonOffsetFactor: -1,
|
|
38
|
+
polygonOffsetUnits: -1
|
|
39
|
+
}), P = r(w().r, 0, 1);
|
|
40
|
+
N.aoNode = d(o(1), h(P, 1.35), O);
|
|
41
|
+
let F = S();
|
|
42
|
+
return N.colorNode = t(() => {
|
|
43
|
+
let e = n(F.x.sub(.5)), t = T(m.xz.mul(D)), r = m.xz.mul(g), p = b(s.detailSliceTexs[0], r).rgb, x = b(s.detailSliceTexs[1], r).rgb, S = b(s.detailSliceTexs[4], r).rgb, C = b(s.detailSliceTexs[7], r).rgb;
|
|
44
|
+
if (f === "DIRT") {
|
|
45
|
+
let n = v(.27, .42, e), r = o(1).sub(v(0, .065, e)).mul(.45), i = a(h(e.sub(.165).div(.05), 2).negate()), s = d(p, S, y(t, i.mul(.45)));
|
|
46
|
+
return s = d(s, x, y(t, u(n, r))), s.mul(o(1).sub(i.mul(.18)));
|
|
47
|
+
}
|
|
48
|
+
let w = v(.285, .355, e), E = v(.385, .465, e), O = d(C, S, y(t, w));
|
|
49
|
+
O = d(O, p, y(t, E));
|
|
50
|
+
let k = a(h(e.sub(.155).div(.055), 2).negate());
|
|
51
|
+
O = O.mul(o(1).sub(k.mul(.16).mul(o(1).sub(w))));
|
|
52
|
+
let A = 6.283185307179586 / 192, N = _(m.x.mul(95 * A).add(i(m.z.mul(83 * A)))).mul(.5).add(.5), P = y(t.mul(.38), N.mul(.85).add(.18)), I = u(l(e), .002), L = u(l(F.y), .004), R = o(1).sub(v(o(.009).sub(I), o(.009).add(I), e)), z = o(1).sub(v(o(.19).sub(L), o(.19).add(L), n(c(F.y).sub(.5)))), B = v(.56, .66, F.y), V = R.mul(z).mul(B).mul(P), H = o(1).sub(v(o(.008).sub(I), o(.008).add(I), n(e.sub(.285)))).mul(P);
|
|
53
|
+
return O = d(O, j, V.mul(.9)), d(O, M, H.mul(.82));
|
|
54
|
+
})(), N.outputNode = t(() => C(E(p.rgb, A, k), p.a))(), {
|
|
55
|
+
material: N,
|
|
56
|
+
uniforms: {
|
|
57
|
+
uTileScale: g,
|
|
58
|
+
uDitherTexels: D,
|
|
59
|
+
uCavityStrength: O,
|
|
60
|
+
uPs2Quantize: k,
|
|
61
|
+
uPixelScale: A
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export { O as createPS2RoadMaterialTSL, D as createPS2TerrainMaterialTSL };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createPS2RoadMaterialWebGL as e } from "./ps2RoadWebGL.js";
|
|
2
|
+
import { createPS2TerrainMaterialWebGL as t } from "./ps2TerrainWebGL.js";
|
|
3
|
+
import { createPS2WorldTextures as n } from "./ps2Textures.js";
|
|
4
|
+
import * as r from "three";
|
|
5
|
+
// src/shaders/ps2MaterialsWebGL.ts
|
|
6
|
+
function i(i, a, o, s, c) {
|
|
7
|
+
let l = 10335428;
|
|
8
|
+
i.background = new r.Color(l), i.fog = new r.FogExp2(l, .00145);
|
|
9
|
+
let u = new r.HemisphereLight(11059416, 5392440, .75);
|
|
10
|
+
i.add(u);
|
|
11
|
+
let d = new r.DirectionalLight(16773332, 1.35);
|
|
12
|
+
d.position.set(420, 680, 310), d.castShadow = !0, i.add(d);
|
|
13
|
+
let f = n(a), { material: p, depthMaterial: m } = t(f, {
|
|
14
|
+
ditherTexelsPerMeter: 16,
|
|
15
|
+
ps2ColorQuantize: .85
|
|
16
|
+
}), h = new r.Group();
|
|
17
|
+
for (let e of o) {
|
|
18
|
+
let t = new r.Mesh(e, p);
|
|
19
|
+
t.customDepthMaterial = m, t.castShadow = !0, t.receiveShadow = !0, t.matrixAutoUpdate = !1, t.updateMatrix(), h.add(t);
|
|
20
|
+
}
|
|
21
|
+
i.add(h);
|
|
22
|
+
let { material: g } = e(f, {
|
|
23
|
+
preset: "ASPHALT",
|
|
24
|
+
ditherTexelsPerMeter: 16,
|
|
25
|
+
ps2ColorQuantize: .85
|
|
26
|
+
}), _ = new r.Mesh(s, g);
|
|
27
|
+
_.receiveShadow = !0, i.add(_);
|
|
28
|
+
let { material: v } = e(f, {
|
|
29
|
+
preset: "DIRT",
|
|
30
|
+
ditherTexelsPerMeter: 16,
|
|
31
|
+
ps2ColorQuantize: .85
|
|
32
|
+
}), y = new r.Mesh(c, v);
|
|
33
|
+
return y.receiveShadow = !0, i.add(y), {
|
|
34
|
+
texBundle: f,
|
|
35
|
+
terrainGroup: h,
|
|
36
|
+
asphaltMesh: _,
|
|
37
|
+
dirtMesh: y
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export { e as createPS2RoadMaterialWebGL, t as createPS2TerrainMaterialWebGL, i as mountPS2WorldMeshes };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { SHARED_PS2_GLSL_HELPERS as e } from "./ps2GlslShared.js";
|
|
2
|
+
import { SPLAT_LAYER as t } from "./ps2Textures.js";
|
|
3
|
+
import * as n from "three";
|
|
4
|
+
// src/shaders/ps2RoadWebGL.ts
|
|
5
|
+
function r(r, i) {
|
|
6
|
+
let a = i.preset === "DIRT", o = {
|
|
7
|
+
uDetailArray: { value: r.detailArrayTex },
|
|
8
|
+
uTileScale: { value: i.tileScale ?? 1 / 3 },
|
|
9
|
+
uDitherTexelsPerMeter: { value: i.ditherTexelsPerMeter ?? 16 },
|
|
10
|
+
uCavityStrength: { value: i.cavityStrength ?? 1 },
|
|
11
|
+
uIsDirtRoad: { value: +!!a },
|
|
12
|
+
uCenterLineColor: { value: new n.Color(i.centerLineColor ?? 14393896) },
|
|
13
|
+
uEdgeLineColor: { value: new n.Color(i.edgeLineColor ?? 13815748) },
|
|
14
|
+
uPs2ColorQuantize: { value: i.ps2ColorQuantize ?? .85 },
|
|
15
|
+
uScreenPixelScale: { value: i.screenPixelScale ?? 1 }
|
|
16
|
+
}, s = new n.MeshLambertMaterial({
|
|
17
|
+
vertexColors: !0,
|
|
18
|
+
fog: !0,
|
|
19
|
+
polygonOffset: !0,
|
|
20
|
+
polygonOffsetFactor: -1,
|
|
21
|
+
polygonOffsetUnits: -1
|
|
22
|
+
});
|
|
23
|
+
return s.userData.__kolmoRetroApplied = !0, s.customProgramCacheKey = () => `ps2-road7v-${i.preset}-lambert-v1`, s.onBeforeCompile = (n) => {
|
|
24
|
+
Object.assign(n.uniforms, o), n.vertexShader = n.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 "), n.fragmentShader = n.fragmentShader.replace("#include <common>", `
|
|
25
|
+
#include <common>
|
|
26
|
+
precision mediump sampler2DArray;
|
|
27
|
+
|
|
28
|
+
uniform sampler2DArray uDetailArray;
|
|
29
|
+
uniform float uTileScale;
|
|
30
|
+
uniform float uDitherTexelsPerMeter;
|
|
31
|
+
uniform float uCavityStrength;
|
|
32
|
+
uniform int uIsDirtRoad;
|
|
33
|
+
uniform vec3 uCenterLineColor;
|
|
34
|
+
uniform vec3 uEdgeLineColor;
|
|
35
|
+
uniform float uPs2ColorQuantize;
|
|
36
|
+
uniform float uScreenPixelScale;
|
|
37
|
+
|
|
38
|
+
varying vec2 vPs2Uv;
|
|
39
|
+
varying vec3 vPs2WorldPos;
|
|
40
|
+
|
|
41
|
+
${e}
|
|
42
|
+
`).replace("#include <color_fragment>", `
|
|
43
|
+
float uSym = abs(vPs2Uv.x - 0.5);
|
|
44
|
+
float bayerWorld = ps2Bayer4x4(vPs2WorldPos.xz * uDitherTexelsPerMeter);
|
|
45
|
+
vec2 tileUv = vPs2WorldPos.xz * uTileScale;
|
|
46
|
+
vec2 dTileDx = dFdx(tileUv);
|
|
47
|
+
vec2 dTileDy = dFdy(tileUv);
|
|
48
|
+
vec3 roadAlbedo;
|
|
49
|
+
|
|
50
|
+
if (uIsDirtRoad == 0) {
|
|
51
|
+
float gravelMix = smoothstep(0.285, 0.355, uSym);
|
|
52
|
+
float dirtSkirtMix = smoothstep(0.385, 0.465, uSym);
|
|
53
|
+
int surfLayer = ${t.ASPHALT};
|
|
54
|
+
if (bayerWorld < dirtSkirtMix) {
|
|
55
|
+
surfLayer = ${t.DIRT};
|
|
56
|
+
} else if (bayerWorld < gravelMix) {
|
|
57
|
+
surfLayer = ${t.GRAVEL};
|
|
58
|
+
}
|
|
59
|
+
roadAlbedo = textureGrad(uDetailArray, vec3(tileUv, float(surfLayer)), dTileDx, dTileDy).rgb;
|
|
60
|
+
|
|
61
|
+
float laneTrack = exp(-pow((uSym - 0.155) / 0.055, 2.0));
|
|
62
|
+
roadAlbedo *= (1.0 - 0.16 * laneTrack * (1.0 - gravelMix));
|
|
63
|
+
|
|
64
|
+
float wearSignal = sin(vPs2WorldPos.x * (95.0 * PS2_OMEGA_192) + cos(vPs2WorldPos.z * (83.0 * PS2_OMEGA_192))) * 0.5 + 0.5;
|
|
65
|
+
float paintIntact = step(bayerWorld * 0.38, wearSignal * 0.85 + 0.18);
|
|
66
|
+
|
|
67
|
+
float uAa = max(fwidth(uSym), 0.002);
|
|
68
|
+
float centerWidthMask = 1.0 - smoothstep(0.009 - uAa, 0.009 + uAa, uSym);
|
|
69
|
+
float vFract = fract(vPs2Uv.y);
|
|
70
|
+
float vAa = max(fwidth(vPs2Uv.y), 0.004);
|
|
71
|
+
float dashLongMask = 1.0 - smoothstep(0.19 - vAa, 0.19 + vAa, abs(vFract - 0.5));
|
|
72
|
+
float junctionClearMask = smoothstep(0.56, 0.66, vPs2Uv.y);
|
|
73
|
+
float yellowMask = centerWidthMask * dashLongMask * junctionClearMask * paintIntact;
|
|
74
|
+
|
|
75
|
+
float edgeDist = abs(uSym - 0.285);
|
|
76
|
+
float whiteMask = (1.0 - smoothstep(0.008 - uAa, 0.008 + uAa, edgeDist)) * paintIntact;
|
|
77
|
+
|
|
78
|
+
roadAlbedo = mix(roadAlbedo, uCenterLineColor, yellowMask * 0.90);
|
|
79
|
+
roadAlbedo = mix(roadAlbedo, uEdgeLineColor, whiteMask * 0.82);
|
|
80
|
+
} else {
|
|
81
|
+
float outerGrassMix = smoothstep(0.27, 0.42, uSym);
|
|
82
|
+
float centerHumpGrass = (1.0 - smoothstep(0.0, 0.065, uSym)) * 0.45;
|
|
83
|
+
float rutGravel = exp(-pow((uSym - 0.165) / 0.05, 2.0));
|
|
84
|
+
int surfLayer = ${t.DIRT};
|
|
85
|
+
if (bayerWorld < max(outerGrassMix, centerHumpGrass)) {
|
|
86
|
+
surfLayer = ${t.GRASS};
|
|
87
|
+
} else if (bayerWorld < rutGravel * 0.45) {
|
|
88
|
+
surfLayer = ${t.GRAVEL};
|
|
89
|
+
}
|
|
90
|
+
roadAlbedo = textureGrad(uDetailArray, vec3(tileUv, float(surfLayer)), dTileDx, dTileDy).rgb;
|
|
91
|
+
roadAlbedo *= (1.0 - 0.18 * rutGravel);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
diffuseColor.rgb *= roadAlbedo;
|
|
95
|
+
`).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 ");
|
|
96
|
+
}, {
|
|
97
|
+
material: s,
|
|
98
|
+
uniforms: o
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export { r as createPS2RoadMaterialWebGL };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SHARED_PS2_GLSL_HELPERS as e } from "./ps2GlslShared.js";
|
|
2
|
+
import * as t from "three";
|
|
3
|
+
// src/shaders/ps2TerrainWebGL.ts
|
|
4
|
+
function n(n, r = {}) {
|
|
5
|
+
let i = {
|
|
6
|
+
uSplat0: { value: n.splat0Tex },
|
|
7
|
+
uSplat1: { value: n.splat1Tex },
|
|
8
|
+
uAlphaTex: { value: n.alphaTex },
|
|
9
|
+
uDetailArray: { value: n.detailArrayTex },
|
|
10
|
+
uTileScale: { value: r.tileScale ?? 1 / 3 },
|
|
11
|
+
uDitherTexelsPerMeter: { value: r.ditherTexelsPerMeter ?? 16 },
|
|
12
|
+
uSplatContrast: { value: r.splatContrast ?? 1.65 },
|
|
13
|
+
uCavityStrength: { value: r.cavityStrength ?? 1 },
|
|
14
|
+
uCavityShadowTint: { value: new t.Color(7239820) },
|
|
15
|
+
uPs2ColorQuantize: { value: r.ps2ColorQuantize ?? .85 },
|
|
16
|
+
uScreenPixelScale: { value: r.screenPixelScale ?? 1 }
|
|
17
|
+
}, a = new t.MeshLambertMaterial({
|
|
18
|
+
vertexColors: !0,
|
|
19
|
+
fog: !0
|
|
20
|
+
});
|
|
21
|
+
a.userData.__kolmoRetroApplied = !0, a.customProgramCacheKey = () => "ps2-terrain-splat8-lambert-v1", a.onBeforeCompile = (t) => {
|
|
22
|
+
Object.assign(t.uniforms, i), t.vertexShader = t.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 "), t.fragmentShader = t.fragmentShader.replace("#include <common>", `
|
|
23
|
+
#include <common>
|
|
24
|
+
precision mediump sampler2DArray;
|
|
25
|
+
|
|
26
|
+
uniform sampler2D uSplat0;
|
|
27
|
+
uniform sampler2D uSplat1;
|
|
28
|
+
uniform sampler2D uAlphaTex;
|
|
29
|
+
uniform sampler2DArray uDetailArray;
|
|
30
|
+
|
|
31
|
+
uniform float uTileScale;
|
|
32
|
+
uniform float uDitherTexelsPerMeter;
|
|
33
|
+
uniform float uSplatContrast;
|
|
34
|
+
uniform float uCavityStrength;
|
|
35
|
+
uniform vec3 uCavityShadowTint;
|
|
36
|
+
uniform float uPs2ColorQuantize;
|
|
37
|
+
uniform float uScreenPixelScale;
|
|
38
|
+
|
|
39
|
+
varying vec2 vPs2Uv;
|
|
40
|
+
varying vec3 vPs2WorldPos;
|
|
41
|
+
|
|
42
|
+
${e}
|
|
43
|
+
`).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 ");
|
|
44
|
+
};
|
|
45
|
+
let o = new t.MeshDepthMaterial({ depthPacking: t.RGBADepthPacking });
|
|
46
|
+
return o.customProgramCacheKey = () => "ps2-terrain-depth-cutout-v1", o.onBeforeCompile = (e) => {
|
|
47
|
+
e.uniforms.uAlphaTex = i.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;");
|
|
48
|
+
}, {
|
|
49
|
+
material: a,
|
|
50
|
+
depthMaterial: o,
|
|
51
|
+
uniforms: i
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export { n as createPS2TerrainMaterialWebGL };
|