ugly-game 0.15.47 → 0.15.49
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/assets/gpuProps.d.ts +7 -0
- package/dist/assets/gpuProps.js +76 -4
- package/dist/flightTestFixture.d.mts +2 -0
- package/dist/flightTestFixture.mjs +57 -0
- package/dist/gpuShadow.d.ts +1133 -0
- package/dist/gpuShadow.js +4463 -0
- package/package.json +16 -17
|
@@ -23,6 +23,13 @@ export interface PropWorld {
|
|
|
23
23
|
valueLift: number;
|
|
24
24
|
}
|
|
25
25
|
export interface PropMesh {
|
|
26
|
+
/** Opt-in metallic/roughness shading. Omitted preserves legacy matte lighting. */
|
|
27
|
+
roughness?: number;
|
|
28
|
+
metalness?: number;
|
|
29
|
+
/** Clear lacquer layer over the base material, 0..1. */
|
|
30
|
+
clearcoat?: number;
|
|
31
|
+
/** Analytic studio/sky reflection strength. Defaults to 1 for PBR materials. */
|
|
32
|
+
reflectionStrength?: number;
|
|
26
33
|
positions: Float32Array;
|
|
27
34
|
normals: Float32Array;
|
|
28
35
|
colors: Float32Array;
|
package/dist/assets/gpuProps.js
CHANGED
|
@@ -32,7 +32,9 @@ struct Inst { m: mat4x4<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32>, d3: v
|
|
|
32
32
|
// PER-MODEL material. Group 2 is already the per-model group (the albedo lives here), so opacity
|
|
33
33
|
// rides along rather than needing a fourth group or a dynamic offset. mat.x is alpha, mat.y is the
|
|
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
|
+
// coat = clearcoat, reflection strength, unused, unused.
|
|
37
|
+
struct Mat { mat: vec4<f32>, coat: vec4<f32> };
|
|
36
38
|
@group(2) @binding(2) var<uniform> mtl: Mat;
|
|
37
39
|
@group(1) @binding(0) var shadowMap: texture_depth_2d_array; // the SAME cascaded sun shadow map the terrain cubes sample
|
|
38
40
|
@group(1) @binding(1) var shadowSamp: sampler_comparison;
|
|
@@ -187,6 +189,39 @@ fn hsvShift(c: vec3<f32>, hue: f32, sat: f32, val: f32) -> vec3<f32> {
|
|
|
187
189
|
let g = dot(rot, vec3(0.299, 0.587, 0.114));
|
|
188
190
|
return clamp(mix(vec3(g, g, g), rot, sat) * val, vec3(0.0), vec3(4.0));
|
|
189
191
|
}
|
|
192
|
+
// Analytic studio/sky environment: view-dependent reflections without a downloaded
|
|
193
|
+
// cubemap. This is an approximate image-based light, not scene ray tracing.
|
|
194
|
+
fn studioEnv(r: vec3<f32>, rough: f32) -> vec3<f32> {
|
|
195
|
+
let horizon = smoothstep(-0.15, 0.45, r.y);
|
|
196
|
+
var c = mix(vec3(0.12, 0.11, 0.09), vec3(0.58, 0.68, 0.80), horizon);
|
|
197
|
+
let width = 0.015 + rough * rough * 0.28;
|
|
198
|
+
let top = smoothstep(0.68 - width, 0.68 + width, r.y);
|
|
199
|
+
// Tall softboxes extend below the horizon: eye-level vertical panels reflect
|
|
200
|
+
// directions below the camera, so overhead-only lights cannot reveal their gloss.
|
|
201
|
+
let panelHeight = smoothstep(-0.8, -0.55, r.y) * (1.0-smoothstep(0.65, 0.95, r.y));
|
|
202
|
+
let stripA = exp(-pow((r.x - 0.48) / (0.12 + width), 2.0)) * panelHeight;
|
|
203
|
+
let stripB = exp(-pow((r.z + 0.38) / (0.09 + width), 2.0)) * panelHeight;
|
|
204
|
+
c += vec3(1.6, 1.5, 1.35) * top * 0.55;
|
|
205
|
+
c += vec3(2.5, 2.35, 2.1) * (stripA + stripB) * (1.0 - rough * 0.7);
|
|
206
|
+
return c;
|
|
207
|
+
}
|
|
208
|
+
fn fresnel(f0: vec3<f32>, cosTheta: f32) -> vec3<f32> {
|
|
209
|
+
return f0 + (vec3(1.0) - f0) * pow(1.0 - clamp(cosTheta, 0.0, 1.0), 5.0);
|
|
210
|
+
}
|
|
211
|
+
fn ggx(nh: f32, nv: f32, nl: f32, rough: f32) -> f32 {
|
|
212
|
+
let a2 = pow(rough, 4.0);
|
|
213
|
+
let den = nh * nh * (a2 - 1.0) + 1.0;
|
|
214
|
+
let D = a2 / max(3.14159265 * den * den, 0.00001);
|
|
215
|
+
let k = pow(rough + 1.0, 2.0) / 8.0;
|
|
216
|
+
let G = (nv / max(nv * (1.0-k) + k, 0.0001)) * (nl / max(nl * (1.0-k) + k, 0.0001));
|
|
217
|
+
return D * G / max(4.0 * nv * nl, 0.0001);
|
|
218
|
+
}
|
|
219
|
+
fn srgbToLinear(c: vec3<f32>) -> vec3<f32> {
|
|
220
|
+
return select(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), c > vec3(0.04045));
|
|
221
|
+
}
|
|
222
|
+
fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
223
|
+
return select(c * 12.92, 1.055 * pow(max(c, vec3(0.0)), vec3(1.0/2.4)) - 0.055, c > vec3(0.0031308));
|
|
224
|
+
}
|
|
190
225
|
@fragment fn fs(i: VO) -> @location(0) vec4<f32> {
|
|
191
226
|
let N = normalize(i.n);
|
|
192
227
|
let ff = select(1.0, 0.5 + 0.85 * fixedFill(N, u.up.xyz), u.up.w > 0.5); // fixed fill (fall back to flat amb if no up)
|
|
@@ -207,8 +242,36 @@ fn hsvShift(c: vec3<f32>, hue: f32, sat: f32, val: f32) -> vec3<f32> {
|
|
|
207
242
|
}
|
|
208
243
|
base = hsvShift(base, u.grade.x, max(u.grade.y, 0.0), max(u.grade.z, 0.0));
|
|
209
244
|
let spec = u.surf.z;
|
|
210
|
-
|
|
245
|
+
var lit = base * (u.amb.xyz * ff + d * u.sunCol.xyz * sh * (1.0 + spec * 0.6))
|
|
211
246
|
+ base * u.surf.w; // emissive — bioluminescence on dark worlds
|
|
247
|
+
if (mtl.mat.z >= 0.0) {
|
|
248
|
+
let V = normalize(u.cam.xyz - i.world);
|
|
249
|
+
let L = -normalize(u.sun.xyz);
|
|
250
|
+
let H = normalize(L + V);
|
|
251
|
+
let nv = max(dot(N, V), 0.001);
|
|
252
|
+
let nl = max(dot(N, L), 0.0);
|
|
253
|
+
let nh = max(dot(N, H), 0.0);
|
|
254
|
+
let vh = max(dot(V, H), 0.0);
|
|
255
|
+
let rough = clamp(mtl.mat.z, 0.045, 1.0);
|
|
256
|
+
let metal = clamp(mtl.mat.w, 0.0, 1.0);
|
|
257
|
+
// Vertex/instance tints are display sRGB, while albedo textures use sRGB GPU
|
|
258
|
+
// formats (and arrive decoded). Legacy props keep their historical path.
|
|
259
|
+
let albedo = srgbToLinear(i.c) * tex.rgb;
|
|
260
|
+
let f0 = mix(vec3(0.04), albedo, metal);
|
|
261
|
+
let F = fresnel(f0, vh);
|
|
262
|
+
let kd = (vec3(1.0)-F) * (1.0-metal);
|
|
263
|
+
let direct = (kd * albedo / 3.14159265 + F * ggx(nh,nv,nl,rough)) * u.sunCol.xyz * nl * sh * 2.5;
|
|
264
|
+
let R = reflect(-V,N);
|
|
265
|
+
let env = studioEnv(R,rough) * mtl.coat.y;
|
|
266
|
+
let reflected = env * fresnel(f0,nv) * (1.0-rough*0.6);
|
|
267
|
+
let diffuse = albedo * u.amb.xyz * (0.6 + 0.4*max(N.y,0.0)) * (1.0-metal);
|
|
268
|
+
let coatF = fresnel(vec3(0.04),nv) * mtl.coat.x;
|
|
269
|
+
let coating = studioEnv(R,0.12) * coatF * mtl.coat.y;
|
|
270
|
+
let hdr = (direct + diffuse + reflected) * (vec3(1.0)-coatF) + coating;
|
|
271
|
+
// Smooth highlight compression preserves saturated paint rather than
|
|
272
|
+
// clipping reflected softboxes to a flat white patch.
|
|
273
|
+
lit = linearToSrgb(hdr / (vec3(1.0) + hdr * 0.35));
|
|
274
|
+
}
|
|
212
275
|
let dist = length(i.world - u.cam.xyz);
|
|
213
276
|
let f = clamp(1.0 - exp(-dist * u.fog.w), 0.0, 1.0);
|
|
214
277
|
// mtl.mat.x is the model's opacity, 1 for every model that does not set it — the same constant
|
|
@@ -758,10 +821,19 @@ export class GpuPropsRenderer {
|
|
|
758
821
|
const alpha = m.alpha ?? 1;
|
|
759
822
|
const cutout = m.cutout ?? 0;
|
|
760
823
|
const matBuf = dev.createBuffer({
|
|
761
|
-
size:
|
|
824
|
+
size: 32,
|
|
762
825
|
usage: U.UNIFORM | U.COPY_DST,
|
|
763
826
|
});
|
|
764
|
-
dev.queue.writeBuffer(matBuf, 0, new Float32Array([
|
|
827
|
+
dev.queue.writeBuffer(matBuf, 0, new Float32Array([
|
|
828
|
+
alpha,
|
|
829
|
+
cutout,
|
|
830
|
+
m.roughness ?? -1,
|
|
831
|
+
m.metalness ?? 0,
|
|
832
|
+
m.clearcoat ?? 0,
|
|
833
|
+
m.reflectionStrength ?? 1,
|
|
834
|
+
0,
|
|
835
|
+
0,
|
|
836
|
+
]));
|
|
765
837
|
return {
|
|
766
838
|
alpha,
|
|
767
839
|
cutout,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FLIGHT_CHANNELS } from './flightTypes';
|
|
2
|
+
const emptyCounts = () => Object.fromEntries(FLIGHT_CHANNELS.map((channel) => [channel, 0]));
|
|
3
|
+
export function fixtureCapture() {
|
|
4
|
+
const channels = Object.fromEntries(FLIGHT_CHANNELS.map((channel) => [channel, []]));
|
|
5
|
+
channels.inputs = [
|
|
6
|
+
{ sequence: 2, monotonicMs: 2, tick: 0, kind: 0, flags: 0, payload: new Uint8Array([7]) },
|
|
7
|
+
];
|
|
8
|
+
channels.lifecycle = [
|
|
9
|
+
{ sequence: 1, monotonicMs: 1, tick: null, kind: 2, flags: 0, payload: new Uint8Array([8]) },
|
|
10
|
+
];
|
|
11
|
+
return {
|
|
12
|
+
header: {
|
|
13
|
+
recorderSchema: 1,
|
|
14
|
+
gameSchema: 2,
|
|
15
|
+
checkpointSchema: 3,
|
|
16
|
+
inputSchema: 4,
|
|
17
|
+
app: 'test',
|
|
18
|
+
buildId: 'build',
|
|
19
|
+
sessionId: 'session',
|
|
20
|
+
startedAtMs: 1,
|
|
21
|
+
capturedAtMs: 2,
|
|
22
|
+
capturedAtMonotonicMs: 2,
|
|
23
|
+
capturedAtTick: 0,
|
|
24
|
+
tickRate: 60,
|
|
25
|
+
environment: { runtime: 'node' },
|
|
26
|
+
reason: ['manual'],
|
|
27
|
+
},
|
|
28
|
+
anchor: {
|
|
29
|
+
requestId: 1,
|
|
30
|
+
tick: 0,
|
|
31
|
+
monotonicMs: 0,
|
|
32
|
+
schema: 3,
|
|
33
|
+
checkpoint: new Uint8Array([1, 2, 3]),
|
|
34
|
+
rng: new Uint32Array([4, 5]),
|
|
35
|
+
encodedBytes: 3,
|
|
36
|
+
transferBytes: 3,
|
|
37
|
+
},
|
|
38
|
+
channels,
|
|
39
|
+
truncation: {
|
|
40
|
+
dropped: emptyCounts(),
|
|
41
|
+
droppedBytes: emptyCounts(),
|
|
42
|
+
rejectedOversize: emptyCounts(),
|
|
43
|
+
},
|
|
44
|
+
replay: { status: 'unverified' },
|
|
45
|
+
selfTelemetry: {
|
|
46
|
+
calls: 1,
|
|
47
|
+
averageMs: 0.01,
|
|
48
|
+
p95Ms: 0.02,
|
|
49
|
+
p99Ms: 0.02,
|
|
50
|
+
maxMs: 0.02,
|
|
51
|
+
retainedBytes: 100,
|
|
52
|
+
checkpointRequests: 1,
|
|
53
|
+
checkpointFailures: 0,
|
|
54
|
+
checkpointMs: 1,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|