ugly-game 0.15.47 → 0.15.48
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 +73 -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,36 @@ 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
|
+
let stripA = exp(-pow((r.x - 0.48) / (0.07 + width), 2.0)) * smoothstep(-0.1, 0.3, r.y);
|
|
200
|
+
let stripB = exp(-pow((r.z + 0.38) / (0.045 + width), 2.0)) * smoothstep(0.0, 0.3, r.y);
|
|
201
|
+
c += vec3(1.6, 1.5, 1.35) * top * 0.55;
|
|
202
|
+
c += vec3(2.5, 2.35, 2.1) * (stripA + stripB) * (1.0 - rough * 0.7);
|
|
203
|
+
return c;
|
|
204
|
+
}
|
|
205
|
+
fn fresnel(f0: vec3<f32>, cosTheta: f32) -> vec3<f32> {
|
|
206
|
+
return f0 + (vec3(1.0) - f0) * pow(1.0 - clamp(cosTheta, 0.0, 1.0), 5.0);
|
|
207
|
+
}
|
|
208
|
+
fn ggx(nh: f32, nv: f32, nl: f32, rough: f32) -> f32 {
|
|
209
|
+
let a2 = pow(rough, 4.0);
|
|
210
|
+
let den = nh * nh * (a2 - 1.0) + 1.0;
|
|
211
|
+
let D = a2 / max(3.14159265 * den * den, 0.00001);
|
|
212
|
+
let k = pow(rough + 1.0, 2.0) / 8.0;
|
|
213
|
+
let G = (nv / max(nv * (1.0-k) + k, 0.0001)) * (nl / max(nl * (1.0-k) + k, 0.0001));
|
|
214
|
+
return D * G / max(4.0 * nv * nl, 0.0001);
|
|
215
|
+
}
|
|
216
|
+
fn srgbToLinear(c: vec3<f32>) -> vec3<f32> {
|
|
217
|
+
return select(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), c > vec3(0.04045));
|
|
218
|
+
}
|
|
219
|
+
fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
220
|
+
return select(c * 12.92, 1.055 * pow(max(c, vec3(0.0)), vec3(1.0/2.4)) - 0.055, c > vec3(0.0031308));
|
|
221
|
+
}
|
|
190
222
|
@fragment fn fs(i: VO) -> @location(0) vec4<f32> {
|
|
191
223
|
let N = normalize(i.n);
|
|
192
224
|
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 +239,36 @@ fn hsvShift(c: vec3<f32>, hue: f32, sat: f32, val: f32) -> vec3<f32> {
|
|
|
207
239
|
}
|
|
208
240
|
base = hsvShift(base, u.grade.x, max(u.grade.y, 0.0), max(u.grade.z, 0.0));
|
|
209
241
|
let spec = u.surf.z;
|
|
210
|
-
|
|
242
|
+
var lit = base * (u.amb.xyz * ff + d * u.sunCol.xyz * sh * (1.0 + spec * 0.6))
|
|
211
243
|
+ base * u.surf.w; // emissive — bioluminescence on dark worlds
|
|
244
|
+
if (mtl.mat.z >= 0.0) {
|
|
245
|
+
let V = normalize(u.cam.xyz - i.world);
|
|
246
|
+
let L = -normalize(u.sun.xyz);
|
|
247
|
+
let H = normalize(L + V);
|
|
248
|
+
let nv = max(dot(N, V), 0.001);
|
|
249
|
+
let nl = max(dot(N, L), 0.0);
|
|
250
|
+
let nh = max(dot(N, H), 0.0);
|
|
251
|
+
let vh = max(dot(V, H), 0.0);
|
|
252
|
+
let rough = clamp(mtl.mat.z, 0.045, 1.0);
|
|
253
|
+
let metal = clamp(mtl.mat.w, 0.0, 1.0);
|
|
254
|
+
// Vertex/instance tints are display sRGB, while albedo textures use sRGB GPU
|
|
255
|
+
// formats (and arrive decoded). Legacy props keep their historical path.
|
|
256
|
+
let albedo = srgbToLinear(i.c) * tex.rgb;
|
|
257
|
+
let f0 = mix(vec3(0.04), albedo, metal);
|
|
258
|
+
let F = fresnel(f0, vh);
|
|
259
|
+
let kd = (vec3(1.0)-F) * (1.0-metal);
|
|
260
|
+
let direct = (kd * albedo / 3.14159265 + F * ggx(nh,nv,nl,rough)) * u.sunCol.xyz * nl * sh * 2.5;
|
|
261
|
+
let R = reflect(-V,N);
|
|
262
|
+
let env = studioEnv(R,rough) * mtl.coat.y;
|
|
263
|
+
let reflected = env * fresnel(f0,nv) * (1.0-rough*0.6);
|
|
264
|
+
let diffuse = albedo * u.amb.xyz * (0.6 + 0.4*max(N.y,0.0)) * (1.0-metal);
|
|
265
|
+
let coatF = fresnel(vec3(0.04),nv) * mtl.coat.x;
|
|
266
|
+
let coating = studioEnv(R,0.12) * coatF * mtl.coat.y;
|
|
267
|
+
let hdr = (direct + diffuse + reflected) * (vec3(1.0)-coatF) + coating;
|
|
268
|
+
// Smooth highlight compression preserves saturated paint rather than
|
|
269
|
+
// clipping reflected softboxes to a flat white patch.
|
|
270
|
+
lit = linearToSrgb(hdr / (vec3(1.0) + hdr * 0.35));
|
|
271
|
+
}
|
|
212
272
|
let dist = length(i.world - u.cam.xyz);
|
|
213
273
|
let f = clamp(1.0 - exp(-dist * u.fog.w), 0.0, 1.0);
|
|
214
274
|
// mtl.mat.x is the model's opacity, 1 for every model that does not set it — the same constant
|
|
@@ -758,10 +818,19 @@ export class GpuPropsRenderer {
|
|
|
758
818
|
const alpha = m.alpha ?? 1;
|
|
759
819
|
const cutout = m.cutout ?? 0;
|
|
760
820
|
const matBuf = dev.createBuffer({
|
|
761
|
-
size:
|
|
821
|
+
size: 32,
|
|
762
822
|
usage: U.UNIFORM | U.COPY_DST,
|
|
763
823
|
});
|
|
764
|
-
dev.queue.writeBuffer(matBuf, 0, new Float32Array([
|
|
824
|
+
dev.queue.writeBuffer(matBuf, 0, new Float32Array([
|
|
825
|
+
alpha,
|
|
826
|
+
cutout,
|
|
827
|
+
m.roughness ?? -1,
|
|
828
|
+
m.metalness ?? 0,
|
|
829
|
+
m.clearcoat ?? 0,
|
|
830
|
+
m.reflectionStrength ?? 1,
|
|
831
|
+
0,
|
|
832
|
+
0,
|
|
833
|
+
]));
|
|
765
834
|
return {
|
|
766
835
|
alpha,
|
|
767
836
|
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
|
+
}
|