ugly-game 0.15.64 → 0.15.66

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.
@@ -1,2 +1,15 @@
1
- export declare function encodeGpuGeometry(raw: Uint8Array, precisionBits?: number): Promise<Uint8Array>;
1
+ /**
2
+ * Bits kept per vertex stream when precision is reduced. One number applies to every stream; an
3
+ * object sets them apart, because they need very different precision: a world position spans
4
+ * kilometres, a unit normal or a 0..1 colour does not, and at a shared 18 bits the normals and
5
+ * colours were most of a cooked mesh's bytes. The decoder reverses the same exponential filter
6
+ * whatever the bit count, so files cooked either way read with no format change.
7
+ */
8
+ export type GpuGeometryPrecision = number | {
9
+ position: number;
10
+ normal: number;
11
+ color: number;
12
+ uv: number;
13
+ };
14
+ export declare function encodeGpuGeometry(raw: Uint8Array, precisionBits?: GpuGeometryPrecision): Promise<Uint8Array>;
2
15
  export declare function decodeGpuGeometry(packed: Uint8Array): Promise<Uint8Array>;
@@ -3,10 +3,16 @@
3
3
  * without topology, color, normal or layout rebuilding. */
4
4
  import { MeshoptEncoder, MeshoptDecoder } from 'meshoptimizer';
5
5
  export async function encodeGpuGeometry(raw, precisionBits = 0) {
6
- if (precisionBits &&
7
- (!Number.isInteger(precisionBits) ||
8
- precisionBits < 12 ||
9
- precisionBits > 24))
6
+ const bits = typeof precisionBits === 'number'
7
+ ? [precisionBits, precisionBits, precisionBits, precisionBits]
8
+ : [
9
+ precisionBits.position,
10
+ precisionBits.normal,
11
+ precisionBits.color,
12
+ precisionBits.uv,
13
+ ];
14
+ const reduced = bits.some((b) => b !== 0);
15
+ if (reduced && bits.some((b) => !Number.isInteger(b) || b < 8 || b > 24))
10
16
  throw new Error('Unsupported cook precision');
11
17
  await MeshoptEncoder.ready;
12
18
  const h = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
@@ -22,8 +28,9 @@ export async function encodeGpuGeometry(raw, precisionBits = 0) {
22
28
  ]) {
23
29
  const bytes = raw.subarray(offset, offset + count * stride);
24
30
  const indexStream = streamIndex++ === 4;
25
- const filtered = precisionBits && !indexStream && count
26
- ? MeshoptEncoder.encodeFilterExp(new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), count, stride, precisionBits, 'SharedComponent')
31
+ const streamBits = indexStream ? 0 : bits[streamIndex - 1];
32
+ const filtered = reduced && !indexStream && count
33
+ ? MeshoptEncoder.encodeFilterExp(new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), count, stride, streamBits, 'SharedComponent')
27
34
  : bytes;
28
35
  streams.push(count
29
36
  ? indexStream
@@ -36,7 +43,7 @@ export async function encodeGpuGeometry(raw, precisionBits = 0) {
36
43
  result.set(raw.subarray(0, 32));
37
44
  const header = new DataView(result.buffer);
38
45
  header.setUint32(0, 0x32595047, true);
39
- header.setUint32(20, precisionBits ? 1 : 0, true);
46
+ header.setUint32(20, reduced ? 1 : 0, true);
40
47
  header.setUint32(24, 1, true);
41
48
  offset = 64;
42
49
  streams.forEach((stream, i) => {
@@ -103,6 +103,12 @@ export interface PropMesh {
103
103
  transmission?: number;
104
104
  /** Display-referred albedo render texture, bypassing lighting/tone mapping. */
105
105
  unlit?: boolean;
106
+ /**
107
+ * Self-lit surface (flames, embers, lamps): vertex colour × albedo texture,
108
+ * display-referred, bypassing lighting and tone mapping but still fogged
109
+ * with distance. Unlike `unlit`, vertex colours count.
110
+ */
111
+ glow?: boolean;
106
112
  /** Caller-owned linear occlusion/roughness/metalness map (RGB). */
107
113
  ormMap?: GPUTexture;
108
114
  normalScale?: number;
@@ -438,6 +438,7 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
438
438
  lit = toneMap(radiance);
439
439
  }
440
440
  // A display-referred render texture (rear-view camera) is already lit.
441
+ if (mtl.optics.y > 1.5) { return vec4(mix(tex.rgb * i.c, u.fog.xyz, f), mtl.mat.x); }
441
442
  if (mtl.optics.y > 0.5) { return vec4(tex.rgb, mtl.mat.x); }
442
443
  return vec4(mix(lit, u.fog.xyz, f), opacity);
443
444
  }`;
@@ -1161,7 +1162,7 @@ export class GpuPropsRenderer {
1161
1162
  Math.max(0, Math.min(1, m.pearlStrength ?? 0)),
1162
1163
  0,
1163
1164
  Math.max(0, Math.min(1, m.transmission ?? 0)),
1164
- m.unlit ? 1 : 0,
1165
+ m.unlit ? 1 : m.glow ? 2 : 0,
1165
1166
  0,
1166
1167
  0,
1167
1168
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.64",
3
+ "version": "0.15.66",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {