ugly-game 0.15.57 → 0.15.59
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,5 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
1
|
+
/** Cooked GPU streams with lossless byte transport by default. Optional precision
|
|
2
|
+
* reduction happens at cook time; the decoder decompresses into final float buffers
|
|
3
|
+
* without topology, color, normal or layout rebuilding. */
|
|
3
4
|
import { MeshoptEncoder, MeshoptDecoder } from 'meshoptimizer';
|
|
4
5
|
export async function encodeGpuGeometry(raw, precisionBits = 0) {
|
|
5
6
|
if (precisionBits &&
|
|
@@ -22,7 +23,7 @@ export async function encodeGpuGeometry(raw, precisionBits = 0) {
|
|
|
22
23
|
const bytes = raw.subarray(offset, offset + count * stride);
|
|
23
24
|
const indexStream = streamIndex++ === 4;
|
|
24
25
|
const filtered = precisionBits && !indexStream && count
|
|
25
|
-
? MeshoptEncoder.encodeFilterExp(new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), count, stride, precisionBits, '
|
|
26
|
+
? MeshoptEncoder.encodeFilterExp(new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), count, stride, precisionBits, 'SharedComponent')
|
|
26
27
|
: bytes;
|
|
27
28
|
streams.push(count
|
|
28
29
|
? indexStream
|
|
@@ -39,6 +39,10 @@ export interface PropMesh {
|
|
|
39
39
|
environment?: GPUTexture;
|
|
40
40
|
/** Caller-owned OpenGL (+Y) tangent normal map, linear format. */
|
|
41
41
|
normalMap?: GPUTexture;
|
|
42
|
+
/** Thin-glass transmission [0,1]. Use alpha < 1 and depthWrite false. */
|
|
43
|
+
transmission?: number;
|
|
44
|
+
/** Display-referred albedo render texture, bypassing lighting/tone mapping. */
|
|
45
|
+
unlit?: boolean;
|
|
42
46
|
/** Caller-owned linear occlusion/roughness/metalness map (RGB). */
|
|
43
47
|
ormMap?: GPUTexture;
|
|
44
48
|
normalScale?: number;
|
package/dist/assets/gpuProps.js
CHANGED
|
@@ -34,7 +34,7 @@ struct Inst { m: mat4x4<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32>, d3: v
|
|
|
34
34
|
// alpha-test cutoff (0 ⇒ no test, which is every model that predates it).
|
|
35
35
|
// mat = opacity, cutoff, roughness (-1 = legacy), metalness.
|
|
36
36
|
// coat = clearcoat, reflection strength, unused, unused.
|
|
37
|
-
struct Mat { mat: vec4<f32>, coat: vec4<f32>, maps: vec4<f32>, surface: vec4<f32>, paint: vec4<f32> };
|
|
37
|
+
struct Mat { mat: vec4<f32>, coat: vec4<f32>, maps: vec4<f32>, surface: vec4<f32>, paint: vec4<f32>, optics: vec4<f32> };
|
|
38
38
|
@group(2) @binding(2) var<uniform> mtl: Mat;
|
|
39
39
|
@group(2) @binding(3) var environmentTex: texture_2d<f32>;
|
|
40
40
|
@group(2) @binding(4) var normalTex: texture_2d<f32>;
|
|
@@ -330,7 +330,20 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
|
330
330
|
let f = clamp(1.0 - exp(-dist * u.fog.w), 0.0, 1.0);
|
|
331
331
|
// mtl.mat.x is the model's opacity, 1 for every model that does not set it — the same constant
|
|
332
332
|
// this returned before, so the opaque pipeline draws exactly what it always did.
|
|
333
|
-
|
|
333
|
+
var opacity = mtl.mat.x;
|
|
334
|
+
// Thin glazing reflects more at grazing angles and transmits the rendered
|
|
335
|
+
// scene at normal incidence. This does not approximate thick-glass refraction.
|
|
336
|
+
if (mtl.optics.x > 0.0) {
|
|
337
|
+
let V = normalize(u.cam.xyz-i.world);
|
|
338
|
+
let nv = clamp(abs(dot(N,V)),0.0,1.0);
|
|
339
|
+
let F = 0.04 + 0.96*pow(1.0-nv,5.0);
|
|
340
|
+
opacity = clamp(1.0-mtl.optics.x*(1.0-F),0.0,1.0);
|
|
341
|
+
let radiance = environment(reflect(-V,N),max(mtl.mat.z,0.045));
|
|
342
|
+
lit = linearToSrgb(radiance/(vec3(1.0)+radiance*0.35));
|
|
343
|
+
}
|
|
344
|
+
// A display-referred render texture (rear-view camera) is already lit.
|
|
345
|
+
if (mtl.optics.y > 0.5) { return vec4(tex.rgb, mtl.mat.x); }
|
|
346
|
+
return vec4(mix(lit, u.fog.xyz, f), opacity);
|
|
334
347
|
}`;
|
|
335
348
|
// Depth-only occluder pass: instanced prop depth from the sun's ortho view (so trees/rocks cast shadows).
|
|
336
349
|
// Depth-only occluder. It MUST apply the identical sway, or the shadows stay put while the leaves
|
|
@@ -963,7 +976,7 @@ export class GpuPropsRenderer {
|
|
|
963
976
|
const alpha = m.alpha ?? 1;
|
|
964
977
|
const cutout = m.cutout ?? 0;
|
|
965
978
|
const matBuf = dev.createBuffer({
|
|
966
|
-
size:
|
|
979
|
+
size: 96,
|
|
967
980
|
usage: U.UNIFORM | U.COPY_DST,
|
|
968
981
|
});
|
|
969
982
|
const materialValues = new Float32Array([
|
|
@@ -987,6 +1000,10 @@ export class GpuPropsRenderer {
|
|
|
987
1000
|
Math.max(1, m.flakeScale ?? 320),
|
|
988
1001
|
Math.max(0, Math.min(1, m.pearlStrength ?? 0)),
|
|
989
1002
|
0,
|
|
1003
|
+
Math.max(0, Math.min(1, m.transmission ?? 0)),
|
|
1004
|
+
m.unlit ? 1 : 0,
|
|
1005
|
+
0,
|
|
1006
|
+
0,
|
|
990
1007
|
]);
|
|
991
1008
|
dev.queue.writeBuffer(matBuf, 0, materialValues);
|
|
992
1009
|
return {
|