ugly-game 0.15.50 → 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 +16 -0
- package/dist/assets/gpuProps.js +68 -8
- package/package.json +1 -1
|
@@ -39,6 +39,20 @@ export interface PropMesh {
|
|
|
39
39
|
normalScale?: number;
|
|
40
40
|
/** Repetition for normal/ORM maps; albedo UVs are unchanged. */
|
|
41
41
|
detailRepeat?: number;
|
|
42
|
+
/** Albedo tiling, independent of detailRepeat. Defaults to 1. */
|
|
43
|
+
albedoRepeat?: number;
|
|
44
|
+
/** Dielectric F0 multiplier in [0,1]. Metals retain their conductor response. */
|
|
45
|
+
specularIntensity?: number;
|
|
46
|
+
/** Soft grazing-angle fiber reflection, 0..1; default 0. */
|
|
47
|
+
sheen?: number;
|
|
48
|
+
/** Roughness of the clear lacquer layer; default 0.12. */
|
|
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;
|
|
42
56
|
positions: Float32Array;
|
|
43
57
|
normals: Float32Array;
|
|
44
58
|
colors: Float32Array;
|
|
@@ -251,6 +265,8 @@ export declare class GpuPropsRenderer {
|
|
|
251
265
|
* getting this wrong is the classic washed-out-albedo bug.
|
|
252
266
|
*/
|
|
253
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;
|
|
254
270
|
setModels(meshes: PropMesh[]): void;
|
|
255
271
|
/**
|
|
256
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> };
|
|
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>;
|
|
@@ -250,7 +250,7 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
|
250
250
|
// Albedo modulates the vertex colour rather than replacing it, so the StyleGuide role tint and the
|
|
251
251
|
// per-instance hue jitter still act on a textured prop — and an untextured one samples the 1x1
|
|
252
252
|
// white fallback and is unchanged.
|
|
253
|
-
let tex = textureSample(albedoTex, albedoSamp, i.uv);
|
|
253
|
+
let tex = textureSample(albedoTex, albedoSamp, i.uv * mtl.surface.w);
|
|
254
254
|
// ALPHA TEST, before any shading is paid for. mtl.mat.y is 0 for every model that does not ask for
|
|
255
255
|
// one, and tex.a is 1 on the white fallback, so an untextured or opaque model never discards.
|
|
256
256
|
if (tex.a < mtl.mat.y) { discard; }
|
|
@@ -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;
|
|
@@ -287,8 +291,22 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
|
287
291
|
let ao=select(1.0,orm.r,mtl.maps.y>0.5);
|
|
288
292
|
let diffuse = albedo * ambient * (0.6 + 0.4*max(N.y,0.0)) * (1.0-metal)*ao;
|
|
289
293
|
let coatF = fresnel(vec3(0.04),nv) * mtl.coat.x;
|
|
290
|
-
let coating = environment(R,
|
|
291
|
-
|
|
294
|
+
let coating = environment(R,mtl.surface.z) * coatF * mtl.coat.y;
|
|
295
|
+
// A soft fiber lobe distinguishes woven upholstery from a glossy dielectric.
|
|
296
|
+
// Neutral defaults preserve the existing PBR response in other consumers.
|
|
297
|
+
let sheen = albedo * mtl.surface.y * (u.sunCol.xyz * nl * sh * pow(1.0-vh,5.0)
|
|
298
|
+
+ ambient * pow(1.0-nv,3.0) * 0.65) * (1.0-metal) * ao;
|
|
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;
|
|
292
310
|
// Smooth highlight compression preserves saturated paint rather than
|
|
293
311
|
// clipping reflected softboxes to a flat white patch.
|
|
294
312
|
lit = linearToSrgb(hdr / (vec3(1.0) + hdr * 0.35));
|
|
@@ -761,6 +779,38 @@ export class GpuPropsRenderer {
|
|
|
761
779
|
}
|
|
762
780
|
return tex;
|
|
763
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
|
+
}
|
|
764
814
|
setModels(meshes) {
|
|
765
815
|
const dev = this.device, U = GPUBufferUsage;
|
|
766
816
|
for (const p of this.models) {
|
|
@@ -847,10 +897,10 @@ export class GpuPropsRenderer {
|
|
|
847
897
|
const alpha = m.alpha ?? 1;
|
|
848
898
|
const cutout = m.cutout ?? 0;
|
|
849
899
|
const matBuf = dev.createBuffer({
|
|
850
|
-
size:
|
|
900
|
+
size: 80,
|
|
851
901
|
usage: U.UNIFORM | U.COPY_DST,
|
|
852
902
|
});
|
|
853
|
-
|
|
903
|
+
const materialValues = new Float32Array([
|
|
854
904
|
alpha,
|
|
855
905
|
cutout,
|
|
856
906
|
m.roughness ?? -1,
|
|
@@ -863,11 +913,21 @@ export class GpuPropsRenderer {
|
|
|
863
913
|
m.ormMap ? 1 : 0,
|
|
864
914
|
m.normalScale ?? 1,
|
|
865
915
|
m.detailRepeat ?? 1,
|
|
866
|
-
|
|
916
|
+
Math.max(0, Math.min(1, m.specularIntensity ?? 1)),
|
|
917
|
+
Math.max(0, Math.min(1, m.sheen ?? 0)),
|
|
918
|
+
Math.max(0.045, Math.min(1, m.clearcoatRoughness ?? 0.12)),
|
|
919
|
+
m.albedoRepeat ?? 1,
|
|
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);
|
|
867
926
|
return {
|
|
868
927
|
alpha,
|
|
869
928
|
cutout,
|
|
870
929
|
matBuf,
|
|
930
|
+
materialValues,
|
|
871
931
|
ownsTex,
|
|
872
932
|
firstIndex,
|
|
873
933
|
baseVertex,
|