ugly-game 0.7.10 → 0.8.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.
- package/dist/gpuTerrain.d.ts +6 -0
- package/dist/gpuTerrain.js +20 -4
- package/package.json +1 -1
package/dist/gpuTerrain.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export declare class GpuTerrainRenderer {
|
|
|
15
15
|
private idxB;
|
|
16
16
|
private idxCount;
|
|
17
17
|
private waterB;
|
|
18
|
+
/** Deep / shallow water colour, linear RGB. Defaults reproduce the constants this replaced exactly, so a
|
|
19
|
+
* caller that never sets them sees no change. */
|
|
20
|
+
private wDeep;
|
|
21
|
+
private wShallow;
|
|
22
|
+
/** Set the water body colour for the world being rendered. Render-only — it never reaches a sim hash. */
|
|
23
|
+
setWaterColor(deep: [number, number, number], shallow: [number, number, number]): void;
|
|
18
24
|
private texel;
|
|
19
25
|
constructor(device: GPUDevice, format: GPUTextureFormat, shadow: GpuShadowMap);
|
|
20
26
|
/** Replace the terrain mesh (positions/normals/colors are Nx3, indices triangle list). */
|
package/dist/gpuTerrain.js
CHANGED
|
@@ -35,7 +35,9 @@ const OCCLUDER = /* wgsl */ `
|
|
|
35
35
|
// cam.w carries a render clock (seconds) so the surface animates; ripples perturb the up-normal, driving
|
|
36
36
|
// fresnel sky reflection (more reflective at grazing angles) + a sharp sun glint — a real water look.
|
|
37
37
|
const WATER = /* wgsl */ `
|
|
38
|
-
|
|
38
|
+
// The tail fields (lightVP, shadowP) are declared but unused here: WGSL offsets are positional, so the water
|
|
39
|
+
// colours cannot be reached without spelling out everything before them.
|
|
40
|
+
struct U { mvp: mat4x4<f32>, sun: vec4<f32>, sunCol: vec4<f32>, amb: vec4<f32>, cam: vec4<f32>, fog: vec4<f32>, lightVP: mat4x4<f32>, shadowP: vec4<f32>, wDeep: vec4<f32>, wShallow: vec4<f32> };
|
|
39
41
|
@group(0) @binding(0) var<uniform> u: U;
|
|
40
42
|
struct VO { @builtin(position) pos: vec4<f32>, @location(0) world: vec3<f32> };
|
|
41
43
|
@vertex fn vs(@location(0) p: vec3<f32>) -> VO { var o: VO; o.pos = u.mvp * vec4(p, 1.0); o.world = p; return o; }
|
|
@@ -46,8 +48,11 @@ struct VO { @builtin(position) pos: vec4<f32>, @location(0) world: vec3<f32> };
|
|
|
46
48
|
let w2 = sin(i.world.x * 0.12 - t * 0.55) + sin(i.world.z * 0.17 + t * 0.7);
|
|
47
49
|
let n = normalize(vec3(w1 * 0.05, 1.0, w2 * 0.05));
|
|
48
50
|
let fres = pow(clamp(1.0 - max(dot(view, n), 0.0), 0.0, 1.0), 4.0);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
// PER-WORLD, not the two constants that used to live here. An ocean is the colour of what is dissolved in
|
|
52
|
+
// it — iron runs it rust-red (Rio Tinto), sulfur amber, copper jade, carbonate opaque white — and with the
|
|
53
|
+
// colour hardcoded every sea in every world looked identical. See setWaterColor.
|
|
54
|
+
let deep = u.wDeep.xyz;
|
|
55
|
+
let shallow = u.wShallow.xyz;
|
|
51
56
|
var col = mix(shallow, deep, 0.55);
|
|
52
57
|
col = mix(col, u.fog.xyz, fres * 0.6);
|
|
53
58
|
let refl = reflect(normalize(u.sun.xyz), n);
|
|
@@ -58,7 +63,7 @@ struct VO { @builtin(position) pos: vec4<f32>, @location(0) world: vec3<f32> };
|
|
|
58
63
|
col = mix(col, u.fog.xyz, f);
|
|
59
64
|
return vec4(col, 0.80);
|
|
60
65
|
}`;
|
|
61
|
-
const U_FLOATS =
|
|
66
|
+
const U_FLOATS = 64; // mvp(16)+sun+sunCol+amb+cam+fog(20)+lightVP(16)+shadowP(4)+waterDeep+waterShallow(8)
|
|
62
67
|
export class GpuTerrainRenderer {
|
|
63
68
|
device;
|
|
64
69
|
terrainPipe;
|
|
@@ -75,6 +80,15 @@ export class GpuTerrainRenderer {
|
|
|
75
80
|
idxB = null;
|
|
76
81
|
idxCount = 0;
|
|
77
82
|
waterB;
|
|
83
|
+
/** Deep / shallow water colour, linear RGB. Defaults reproduce the constants this replaced exactly, so a
|
|
84
|
+
* caller that never sets them sees no change. */
|
|
85
|
+
wDeep = [0.03, 0.13, 0.24];
|
|
86
|
+
wShallow = [0.08, 0.3, 0.4];
|
|
87
|
+
/** Set the water body colour for the world being rendered. Render-only — it never reaches a sim hash. */
|
|
88
|
+
setWaterColor(deep, shallow) {
|
|
89
|
+
this.wDeep = deep;
|
|
90
|
+
this.wShallow = shallow;
|
|
91
|
+
}
|
|
78
92
|
texel;
|
|
79
93
|
constructor(device, format, shadow) {
|
|
80
94
|
this.device = device;
|
|
@@ -235,6 +249,8 @@ export class GpuTerrainRenderer {
|
|
|
235
249
|
u.set([fog[0], fog[1], fog[2], fogDensity], 32);
|
|
236
250
|
u.set(lightVP, 36);
|
|
237
251
|
u.set([this.texel, 0, 0, 0], 52);
|
|
252
|
+
u.set([this.wDeep[0], this.wDeep[1], this.wDeep[2], 0], 56);
|
|
253
|
+
u.set([this.wShallow[0], this.wShallow[1], this.wShallow[2], 0], 60);
|
|
238
254
|
this.device.queue.writeBuffer(this.uBuf, 0, u);
|
|
239
255
|
const [cx, cz] = center, e = extent;
|
|
240
256
|
this.device.queue.writeBuffer(this.waterB, 0, new Float32Array([
|