ugly-game 0.15.51 → 0.15.53
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 +68 -7
- 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>;
|
|
@@ -134,7 +134,7 @@ fn pcfLayer(world: vec3<f32>, ndl: f32, layer: i32, inside: ptr<function, bool>)
|
|
|
134
134
|
}
|
|
135
135
|
*inside = true;
|
|
136
136
|
let bias = max(0.0006 * (1.0 - ndl), 0.0004) * (1.0 + f32(layer) * 1.5);
|
|
137
|
-
let texel = 1.0 /
|
|
137
|
+
let texel = 1.0 / vec2<f32>(textureDimensions(shadowMap));
|
|
138
138
|
var s = 0.0;
|
|
139
139
|
for (var dy = -1; dy <= 1; dy = dy + 1) {
|
|
140
140
|
for (var dx = -1; dx <= 1; dx = dx + 1) {
|
|
@@ -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,22 @@ 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
|
+
// Unresolved flakes contribute their average coverage instead of vanishing
|
|
307
|
+
// at normal viewing distances. Resolved glints stay attached to the object.
|
|
308
|
+
let sparkle = mix(0.045,smoothstep(0.91,1.0,grain),coverage)*mtl.paint.x;
|
|
309
|
+
let flakeLobe = ggx(nh,nv,nl,max(rough,0.28))*nl*sh;
|
|
310
|
+
let flakes = (u.sunCol.xyz*flakeLobe*0.32 + environment(R,max(rough,0.28))*0.14)
|
|
311
|
+
* mtl.paint.x * mix(vec3(1.0),albedo,0.35)
|
|
312
|
+
+ (u.sunCol.xyz*pow(nh,72.0)*nl*sh*3.0 + env*0.18)
|
|
313
|
+
* sparkle * mix(vec3(1.0),albedo,0.35);
|
|
314
|
+
let hdr = (flakes + direct + diffuse * (1.0-mtl.surface.y*0.12) + reflected + sheen) * (vec3(1.0)-coatF) + coating;
|
|
296
315
|
// Smooth highlight compression preserves saturated paint rather than
|
|
297
316
|
// clipping reflected softboxes to a flat white patch.
|
|
298
317
|
lit = linearToSrgb(hdr / (vec3(1.0) + hdr * 0.35));
|
|
@@ -685,6 +704,10 @@ export class GpuPropsRenderer {
|
|
|
685
704
|
format: 'depth32float',
|
|
686
705
|
depthWriteEnabled: true,
|
|
687
706
|
depthCompare: 'less',
|
|
707
|
+
// Offset the caster by its rasterized slope: a constant receiver bias
|
|
708
|
+
// alone leaves diagonal self-shadow bands on shallow curved panels.
|
|
709
|
+
depthBias: 2,
|
|
710
|
+
depthBiasSlopeScale: 2,
|
|
688
711
|
},
|
|
689
712
|
});
|
|
690
713
|
this.uBuf = device.createBuffer({
|
|
@@ -765,6 +788,38 @@ export class GpuPropsRenderer {
|
|
|
765
788
|
}
|
|
766
789
|
return tex;
|
|
767
790
|
}
|
|
791
|
+
/** Change scalar PBR properties without rebuilding geometry or texture bindings. */
|
|
792
|
+
setMaterial(model, surface) {
|
|
793
|
+
const packed = this.models.at(model);
|
|
794
|
+
if (model < 0 || !packed)
|
|
795
|
+
throw new RangeError(`Unknown prop model ${model}`);
|
|
796
|
+
const fields = {
|
|
797
|
+
roughness: 2,
|
|
798
|
+
metalness: 3,
|
|
799
|
+
clearcoat: 4,
|
|
800
|
+
reflectionStrength: 5,
|
|
801
|
+
specularIntensity: 12,
|
|
802
|
+
clearcoatRoughness: 14,
|
|
803
|
+
metalFlakes: 16,
|
|
804
|
+
flakeScale: 17,
|
|
805
|
+
pearlStrength: 18,
|
|
806
|
+
};
|
|
807
|
+
let changed = false;
|
|
808
|
+
for (const [key, index] of Object.entries(fields)) {
|
|
809
|
+
const value = surface[key];
|
|
810
|
+
if (value === undefined || !Number.isFinite(value))
|
|
811
|
+
continue;
|
|
812
|
+
const bounded = key === 'flakeScale'
|
|
813
|
+
? Math.max(1, value)
|
|
814
|
+
: Math.max(0, Math.min(1, value));
|
|
815
|
+
if (Math.abs(packed.materialValues[index] - bounded) < 1e-7)
|
|
816
|
+
continue;
|
|
817
|
+
packed.materialValues[index] = bounded;
|
|
818
|
+
changed = true;
|
|
819
|
+
}
|
|
820
|
+
if (changed)
|
|
821
|
+
this.device.queue.writeBuffer(packed.matBuf, 0, packed.materialValues);
|
|
822
|
+
}
|
|
768
823
|
setModels(meshes) {
|
|
769
824
|
const dev = this.device, U = GPUBufferUsage;
|
|
770
825
|
for (const p of this.models) {
|
|
@@ -851,10 +906,10 @@ export class GpuPropsRenderer {
|
|
|
851
906
|
const alpha = m.alpha ?? 1;
|
|
852
907
|
const cutout = m.cutout ?? 0;
|
|
853
908
|
const matBuf = dev.createBuffer({
|
|
854
|
-
size:
|
|
909
|
+
size: 80,
|
|
855
910
|
usage: U.UNIFORM | U.COPY_DST,
|
|
856
911
|
});
|
|
857
|
-
|
|
912
|
+
const materialValues = new Float32Array([
|
|
858
913
|
alpha,
|
|
859
914
|
cutout,
|
|
860
915
|
m.roughness ?? -1,
|
|
@@ -871,11 +926,17 @@ export class GpuPropsRenderer {
|
|
|
871
926
|
Math.max(0, Math.min(1, m.sheen ?? 0)),
|
|
872
927
|
Math.max(0.045, Math.min(1, m.clearcoatRoughness ?? 0.12)),
|
|
873
928
|
m.albedoRepeat ?? 1,
|
|
874
|
-
|
|
929
|
+
Math.max(0, Math.min(1, m.metalFlakes ?? 0)),
|
|
930
|
+
Math.max(1, m.flakeScale ?? 320),
|
|
931
|
+
Math.max(0, Math.min(1, m.pearlStrength ?? 0)),
|
|
932
|
+
0,
|
|
933
|
+
]);
|
|
934
|
+
dev.queue.writeBuffer(matBuf, 0, materialValues);
|
|
875
935
|
return {
|
|
876
936
|
alpha,
|
|
877
937
|
cutout,
|
|
878
938
|
matBuf,
|
|
939
|
+
materialValues,
|
|
879
940
|
ownsTex,
|
|
880
941
|
firstIndex,
|
|
881
942
|
baseVertex,
|