ugly-game 0.15.51 → 0.15.52
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 +8 -0
- package/dist/assets/gpuProps.js +58 -6
- package/package.json +1 -1
|
@@ -47,6 +47,12 @@ export interface PropMesh {
|
|
|
47
47
|
sheen?: number;
|
|
48
48
|
/** Roughness of the clear lacquer layer; default 0.12. */
|
|
49
49
|
clearcoatRoughness?: number;
|
|
50
|
+
/** Stable fine metallic flake strength; zero disables. */
|
|
51
|
+
metalFlakes?: number;
|
|
52
|
+
/** Flake cells per object-space unit (usually meters). Default 320. */
|
|
53
|
+
flakeScale?: number;
|
|
54
|
+
/** Angle-dependent warm/cool pearl reflection, 0..1. */
|
|
55
|
+
pearlStrength?: number;
|
|
50
56
|
positions: Float32Array;
|
|
51
57
|
normals: Float32Array;
|
|
52
58
|
colors: Float32Array;
|
|
@@ -259,6 +265,8 @@ export declare class GpuPropsRenderer {
|
|
|
259
265
|
* getting this wrong is the classic washed-out-albedo bug.
|
|
260
266
|
*/
|
|
261
267
|
private uploadAlbedo;
|
|
268
|
+
/** Change scalar PBR properties without rebuilding geometry or texture bindings. */
|
|
269
|
+
setMaterial(model: number, surface: Pick<PropMesh, 'roughness' | 'metalness' | 'clearcoat' | 'clearcoatRoughness' | 'reflectionStrength' | 'specularIntensity' | 'metalFlakes' | 'flakeScale' | 'pearlStrength'>): void;
|
|
262
270
|
setModels(meshes: PropMesh[]): void;
|
|
263
271
|
/**
|
|
264
272
|
* Group instances by model and upload the per-model instance buffers.
|
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> };
|
|
37
|
+
struct Mat { mat: vec4<f32>, coat: vec4<f32>, maps: vec4<f32>, surface: vec4<f32>, paint: 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>;
|
|
@@ -276,7 +276,11 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
|
276
276
|
// Vertex/instance tints are display sRGB, while albedo textures use sRGB GPU
|
|
277
277
|
// formats (and arrive decoded). Legacy props keep their historical path.
|
|
278
278
|
let albedo = srgbToLinear(i.c) * tex.rgb;
|
|
279
|
-
|
|
279
|
+
// Pearl pigments produce a restrained warm/cool angular reflection under
|
|
280
|
+
// clear lacquer; this is an appearance approximation, not spectral matching.
|
|
281
|
+
let pearlTint = mix(vec3(1.0,0.86,0.65),vec3(0.65,0.84,1.0),pow(1.0-nv,0.7));
|
|
282
|
+
let f0 = mix(vec3(0.04 * mtl.surface.x), albedo, metal)
|
|
283
|
+
+ pearlTint * mtl.paint.z * (0.035 + 0.13*pow(1.0-nv,2.0));
|
|
280
284
|
let F = fresnel(f0, vh);
|
|
281
285
|
let kd = (vec3(1.0)-F) * (1.0-metal);
|
|
282
286
|
let direct = (kd * albedo / 3.14159265 + F * ggx(nh,nv,nl,rough)) * u.sunCol.xyz * nl * sh * 2.5;
|
|
@@ -292,7 +296,17 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
|
292
296
|
// Neutral defaults preserve the existing PBR response in other consumers.
|
|
293
297
|
let sheen = albedo * mtl.surface.y * (u.sunCol.xyz * nl * sh * pow(1.0-vh,5.0)
|
|
294
298
|
+ ambient * pow(1.0-nv,3.0) * 0.65) * (1.0-metal) * ao;
|
|
295
|
-
|
|
299
|
+
// Object-space flakes stay attached to the panel. Fade subpixel grains
|
|
300
|
+
// rather than letting a distant or moving vehicle shimmer with aliasing.
|
|
301
|
+
let flakeP = i.l * mtl.paint.y;
|
|
302
|
+
let footprint = max(length(dpdx(flakeP)),length(dpdy(flakeP)));
|
|
303
|
+
let cell = floor(flakeP);
|
|
304
|
+
let grain = fract(sin(dot(cell,vec3(127.1,311.7,74.7)))*43758.5453);
|
|
305
|
+
let coverage = 1.0-smoothstep(0.45,1.8,footprint);
|
|
306
|
+
let sparkle = smoothstep(0.91,1.0,grain)*coverage*mtl.paint.x;
|
|
307
|
+
let flakes = (u.sunCol.xyz*pow(nh,72.0)*nl*sh*3.0 + env*0.18)
|
|
308
|
+
* sparkle * mix(vec3(1.0),albedo,0.35);
|
|
309
|
+
let hdr = (flakes + direct + diffuse * (1.0-mtl.surface.y*0.12) + reflected + sheen) * (vec3(1.0)-coatF) + coating;
|
|
296
310
|
// Smooth highlight compression preserves saturated paint rather than
|
|
297
311
|
// clipping reflected softboxes to a flat white patch.
|
|
298
312
|
lit = linearToSrgb(hdr / (vec3(1.0) + hdr * 0.35));
|
|
@@ -765,6 +779,38 @@ export class GpuPropsRenderer {
|
|
|
765
779
|
}
|
|
766
780
|
return tex;
|
|
767
781
|
}
|
|
782
|
+
/** Change scalar PBR properties without rebuilding geometry or texture bindings. */
|
|
783
|
+
setMaterial(model, surface) {
|
|
784
|
+
const packed = this.models.at(model);
|
|
785
|
+
if (model < 0 || !packed)
|
|
786
|
+
throw new RangeError(`Unknown prop model ${model}`);
|
|
787
|
+
const fields = {
|
|
788
|
+
roughness: 2,
|
|
789
|
+
metalness: 3,
|
|
790
|
+
clearcoat: 4,
|
|
791
|
+
reflectionStrength: 5,
|
|
792
|
+
specularIntensity: 12,
|
|
793
|
+
clearcoatRoughness: 14,
|
|
794
|
+
metalFlakes: 16,
|
|
795
|
+
flakeScale: 17,
|
|
796
|
+
pearlStrength: 18,
|
|
797
|
+
};
|
|
798
|
+
let changed = false;
|
|
799
|
+
for (const [key, index] of Object.entries(fields)) {
|
|
800
|
+
const value = surface[key];
|
|
801
|
+
if (value === undefined || !Number.isFinite(value))
|
|
802
|
+
continue;
|
|
803
|
+
const bounded = key === 'flakeScale'
|
|
804
|
+
? Math.max(1, value)
|
|
805
|
+
: Math.max(0, Math.min(1, value));
|
|
806
|
+
if (Math.abs(packed.materialValues[index] - bounded) < 1e-7)
|
|
807
|
+
continue;
|
|
808
|
+
packed.materialValues[index] = bounded;
|
|
809
|
+
changed = true;
|
|
810
|
+
}
|
|
811
|
+
if (changed)
|
|
812
|
+
this.device.queue.writeBuffer(packed.matBuf, 0, packed.materialValues);
|
|
813
|
+
}
|
|
768
814
|
setModels(meshes) {
|
|
769
815
|
const dev = this.device, U = GPUBufferUsage;
|
|
770
816
|
for (const p of this.models) {
|
|
@@ -851,10 +897,10 @@ export class GpuPropsRenderer {
|
|
|
851
897
|
const alpha = m.alpha ?? 1;
|
|
852
898
|
const cutout = m.cutout ?? 0;
|
|
853
899
|
const matBuf = dev.createBuffer({
|
|
854
|
-
size:
|
|
900
|
+
size: 80,
|
|
855
901
|
usage: U.UNIFORM | U.COPY_DST,
|
|
856
902
|
});
|
|
857
|
-
|
|
903
|
+
const materialValues = new Float32Array([
|
|
858
904
|
alpha,
|
|
859
905
|
cutout,
|
|
860
906
|
m.roughness ?? -1,
|
|
@@ -871,11 +917,17 @@ export class GpuPropsRenderer {
|
|
|
871
917
|
Math.max(0, Math.min(1, m.sheen ?? 0)),
|
|
872
918
|
Math.max(0.045, Math.min(1, m.clearcoatRoughness ?? 0.12)),
|
|
873
919
|
m.albedoRepeat ?? 1,
|
|
874
|
-
|
|
920
|
+
Math.max(0, Math.min(1, m.metalFlakes ?? 0)),
|
|
921
|
+
Math.max(1, m.flakeScale ?? 320),
|
|
922
|
+
Math.max(0, Math.min(1, m.pearlStrength ?? 0)),
|
|
923
|
+
0,
|
|
924
|
+
]);
|
|
925
|
+
dev.queue.writeBuffer(matBuf, 0, materialValues);
|
|
875
926
|
return {
|
|
876
927
|
alpha,
|
|
877
928
|
cutout,
|
|
878
929
|
matBuf,
|
|
930
|
+
materialValues,
|
|
879
931
|
ownsTex,
|
|
880
932
|
firstIndex,
|
|
881
933
|
baseVertex,
|