ugly-game 0.15.50 → 0.15.51

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.
@@ -39,6 +39,14 @@ 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;
42
50
  positions: Float32Array;
43
51
  normals: Float32Array;
44
52
  colors: Float32Array;
@@ -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> };
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,7 @@ 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
- let f0 = mix(vec3(0.04), albedo, metal);
279
+ let f0 = mix(vec3(0.04 * mtl.surface.x), albedo, metal);
280
280
  let F = fresnel(f0, vh);
281
281
  let kd = (vec3(1.0)-F) * (1.0-metal);
282
282
  let direct = (kd * albedo / 3.14159265 + F * ggx(nh,nv,nl,rough)) * u.sunCol.xyz * nl * sh * 2.5;
@@ -287,8 +287,12 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
287
287
  let ao=select(1.0,orm.r,mtl.maps.y>0.5);
288
288
  let diffuse = albedo * ambient * (0.6 + 0.4*max(N.y,0.0)) * (1.0-metal)*ao;
289
289
  let coatF = fresnel(vec3(0.04),nv) * mtl.coat.x;
290
- let coating = environment(R,0.12) * coatF * mtl.coat.y;
291
- let hdr = (direct + diffuse + reflected) * (vec3(1.0)-coatF) + coating;
290
+ let coating = environment(R,mtl.surface.z) * coatF * mtl.coat.y;
291
+ // A soft fiber lobe distinguishes woven upholstery from a glossy dielectric.
292
+ // Neutral defaults preserve the existing PBR response in other consumers.
293
+ let sheen = albedo * mtl.surface.y * (u.sunCol.xyz * nl * sh * pow(1.0-vh,5.0)
294
+ + ambient * pow(1.0-nv,3.0) * 0.65) * (1.0-metal) * ao;
295
+ let hdr = (direct + diffuse * (1.0-mtl.surface.y*0.12) + reflected + sheen) * (vec3(1.0)-coatF) + coating;
292
296
  // Smooth highlight compression preserves saturated paint rather than
293
297
  // clipping reflected softboxes to a flat white patch.
294
298
  lit = linearToSrgb(hdr / (vec3(1.0) + hdr * 0.35));
@@ -847,7 +851,7 @@ export class GpuPropsRenderer {
847
851
  const alpha = m.alpha ?? 1;
848
852
  const cutout = m.cutout ?? 0;
849
853
  const matBuf = dev.createBuffer({
850
- size: 48,
854
+ size: 64,
851
855
  usage: U.UNIFORM | U.COPY_DST,
852
856
  });
853
857
  dev.queue.writeBuffer(matBuf, 0, new Float32Array([
@@ -863,6 +867,10 @@ export class GpuPropsRenderer {
863
867
  m.ormMap ? 1 : 0,
864
868
  m.normalScale ?? 1,
865
869
  m.detailRepeat ?? 1,
870
+ Math.max(0, Math.min(1, m.specularIntensity ?? 1)),
871
+ Math.max(0, Math.min(1, m.sheen ?? 0)),
872
+ Math.max(0.045, Math.min(1, m.clearcoatRoughness ?? 0.12)),
873
+ m.albedoRepeat ?? 1,
866
874
  ]));
867
875
  return {
868
876
  alpha,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.50",
3
+ "version": "0.15.51",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {