@pinkaphant/create-kolmo 0.3.0 → 0.3.1
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/bin/create-kolmo.mjs
CHANGED
|
@@ -90,25 +90,28 @@ const pkgJson = {
|
|
|
90
90
|
},
|
|
91
91
|
dependencies: {
|
|
92
92
|
"@dimforge/rapier3d-compat": "0.19.2",
|
|
93
|
-
"@khr3/c12": "^0.
|
|
94
|
-
"@khr3/core": "^0.2.
|
|
93
|
+
"@khr3/c12": "^0.3.12",
|
|
94
|
+
"@khr3/core": "^0.2.15",
|
|
95
95
|
"@khr3/roads": "^0.1.1",
|
|
96
96
|
"@pinkaphant/ecctrl": "2.0.4-beta.6",
|
|
97
|
-
"@pinkaphant/kolmo": "^0.
|
|
97
|
+
"@pinkaphant/kolmo": "^0.5.6",
|
|
98
|
+
"@react-three/drei": "^10.7.7",
|
|
98
99
|
"@react-three/fiber": "^9.6.1",
|
|
99
100
|
"@react-three/rapier": "^2.2.0",
|
|
100
101
|
koota: "^0.6.6",
|
|
102
|
+
maath: "^0.10.8",
|
|
101
103
|
react: "^19.2.7",
|
|
102
104
|
"react-dom": "^19.2.7",
|
|
103
105
|
three: "^0.184.0",
|
|
106
|
+
zustand: "^5.1.0",
|
|
104
107
|
},
|
|
105
108
|
devDependencies: {
|
|
106
109
|
"@types/react": "^19.2.16",
|
|
107
110
|
"@types/react-dom": "^19.2.3",
|
|
108
111
|
"@types/three": "^0.184.0",
|
|
109
|
-
"@vitejs/plugin-react": "^
|
|
112
|
+
"@vitejs/plugin-react": "^4.5.2",
|
|
110
113
|
typescript: "^5.8.3",
|
|
111
|
-
vite: "^
|
|
114
|
+
vite: "^6.3.5",
|
|
112
115
|
},
|
|
113
116
|
};
|
|
114
117
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import type { WaveField } from "@pinkaphant/kolmo/water";
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/** Clear, saturated scene colours. The horizon stays crisp instead of dissolving into fog. */
|
|
5
5
|
export const PALETTE = {
|
|
6
|
-
deep: "#
|
|
7
|
-
shallow: "#
|
|
6
|
+
deep: "#062f4d",
|
|
7
|
+
shallow: "#1597a6",
|
|
8
8
|
horizon: "#b9dbea",
|
|
9
9
|
zenith: "#4f93c9",
|
|
10
10
|
foam: "#f2f8fb",
|
|
@@ -13,8 +13,8 @@ export const PALETTE = {
|
|
|
13
13
|
/** Where the sun is: a unit vector toward it. */
|
|
14
14
|
export const SUN = new THREE.Vector3(-0.45, 0.62, -0.64).normalize();
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
export const OCEAN = { size: 220, segments:
|
|
16
|
+
/** Broad, readable triangles: the rendering grid, not the physics grid. */
|
|
17
|
+
export const OCEAN = { size: 220, segments: 110 } as const;
|
|
18
18
|
|
|
19
19
|
const vertex = /* glsl */ `
|
|
20
20
|
uniform float uTime;
|
|
@@ -23,37 +23,19 @@ uniform float uLevel;
|
|
|
23
23
|
uniform vec4 uDirKW[WAVE_COUNT];
|
|
24
24
|
uniform vec4 uAmp[WAVE_COUNT];
|
|
25
25
|
varying vec3 vWorld;
|
|
26
|
-
varying vec3 vNormal;
|
|
27
26
|
|
|
28
|
-
// The same Gerstner
|
|
29
|
-
// uDirKW is (Dx, Dz, k, omega) per wave and uAmp is (A, s, phase, q) per wave. The normal is the field's exact one.
|
|
27
|
+
// The exact same Gerstner displacement as WaveField.displace. Only the shading is faceted.
|
|
30
28
|
void main() {
|
|
31
29
|
vec2 rest = position.xz + uOrigin;
|
|
32
30
|
vec3 p = vec3(rest.x, uLevel, rest.y);
|
|
33
|
-
float a = 1.0;
|
|
34
|
-
float b = 1.0;
|
|
35
|
-
float c = 0.0;
|
|
36
|
-
float gp = 0.0;
|
|
37
|
-
float gq = 0.0;
|
|
38
31
|
for (int i = 0; i < WAVE_COUNT; i++) {
|
|
39
32
|
vec4 d = uDirKW[i];
|
|
40
33
|
vec4 w = uAmp[i];
|
|
41
34
|
float theta = d.z * (d.x * rest.x + d.y * rest.y) - d.w * uTime + w.z;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
p.
|
|
45
|
-
p.z += w.w * d.y * co;
|
|
46
|
-
p.y += w.x * s;
|
|
47
|
-
float ss = w.y * s;
|
|
48
|
-
a -= ss * d.x * d.x;
|
|
49
|
-
b -= ss * d.y * d.y;
|
|
50
|
-
c -= ss * d.x * d.y;
|
|
51
|
-
float ak = w.x * d.z * co;
|
|
52
|
-
gp += ak * d.x;
|
|
53
|
-
gq += ak * d.y;
|
|
35
|
+
p.x += w.w * d.x * cos(theta);
|
|
36
|
+
p.z += w.w * d.y * cos(theta);
|
|
37
|
+
p.y += w.x * sin(theta);
|
|
54
38
|
}
|
|
55
|
-
float det = a * b - c * c;
|
|
56
|
-
vNormal = normalize(vec3(gq * c - b * gp, det, c * gp - gq * a));
|
|
57
39
|
vWorld = p;
|
|
58
40
|
gl_Position = projectionMatrix * viewMatrix * vec4(p, 1.0);
|
|
59
41
|
}
|
|
@@ -62,29 +44,24 @@ void main() {
|
|
|
62
44
|
const fragment = /* glsl */ `
|
|
63
45
|
uniform vec3 uDeep;
|
|
64
46
|
uniform vec3 uShallow;
|
|
65
|
-
uniform vec3 uHorizon;
|
|
66
47
|
uniform vec3 uFoam;
|
|
67
48
|
uniform vec3 uSun;
|
|
68
49
|
uniform float uLevel;
|
|
69
50
|
uniform float uCrest;
|
|
70
51
|
uniform float uFoamAmount;
|
|
71
|
-
uniform float uFogNear;
|
|
72
|
-
uniform float uFogFar;
|
|
73
52
|
varying vec3 vWorld;
|
|
74
|
-
varying vec3 vNormal;
|
|
75
53
|
|
|
76
54
|
void main() {
|
|
77
|
-
|
|
78
|
-
vec3
|
|
79
|
-
|
|
55
|
+
// One face normal per triangle. No interpolated normals, Fresnel, specular, or atmospheric smoothing.
|
|
56
|
+
vec3 n = normalize(cross(dFdx(vWorld), dFdy(vWorld)));
|
|
57
|
+
if (n.y < 0.0) n = -n;
|
|
80
58
|
float lift = clamp((vWorld.y - uLevel) / max(uCrest, 0.05) * 0.5 + 0.5, 0.0, 1.0);
|
|
81
59
|
float diffuse = max(dot(n, uSun), 0.0);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
vec3
|
|
85
|
-
|
|
86
|
-
col = mix(col, uFoam,
|
|
87
|
-
col = mix(col, uHorizon, smoothstep(uFogNear, uFogFar, distance(cameraPosition, vWorld)));
|
|
60
|
+
float heightBand = floor(lift * 4.0) / 3.0;
|
|
61
|
+
float lightBand = floor(diffuse * 3.0) / 2.0;
|
|
62
|
+
vec3 col = mix(uDeep, uShallow, clamp(heightBand * 0.65 + lightBand * 0.25, 0.0, 1.0));
|
|
63
|
+
float foam = step(0.88, lift) * step(0.35, diffuse) * uFoamAmount;
|
|
64
|
+
col = mix(col, uFoam, foam);
|
|
88
65
|
gl_FragColor = vec4(col, 1.0);
|
|
89
66
|
#include <colorspace_fragment>
|
|
90
67
|
}
|
|
@@ -109,11 +86,8 @@ export function createOceanMaterial(field: WaveField, foam: number): THREE.Shade
|
|
|
109
86
|
uFoamAmount: { value: foam },
|
|
110
87
|
uDeep: { value: new THREE.Color(PALETTE.deep) },
|
|
111
88
|
uShallow: { value: new THREE.Color(PALETTE.shallow) },
|
|
112
|
-
uHorizon: { value: new THREE.Color(PALETTE.horizon) },
|
|
113
89
|
uFoam: { value: new THREE.Color(PALETTE.foam) },
|
|
114
90
|
uSun: { value: SUN },
|
|
115
|
-
uFogNear: { value: OCEAN.fogNear },
|
|
116
|
-
uFogFar: { value: OCEAN.fogFar },
|
|
117
91
|
};
|
|
118
92
|
return new THREE.ShaderMaterial({
|
|
119
93
|
vertexShader: vertex,
|