ugly-game 0.15.71 → 0.15.73

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.
@@ -145,8 +145,13 @@ export interface PropMesh {
145
145
  specularIntensity?: number;
146
146
  /** Soft grazing-angle fiber reflection, 0..1; default 0. */
147
147
  sheen?: number;
148
+ /** Fraction of solar diffuse light transmitted through a thin pigmented sheet
149
+ * (leaf, fin, petal). Keeps opaque depth and visibility. Default 0. */
150
+ diffuseTransmission?: number;
148
151
  /** Roughness of the clear lacquer layer; default 0.12. */
149
152
  clearcoatRoughness?: number;
153
+ /** Fraction of the clearcoat's directional-light reflection, 0..1 (default 0). */
154
+ directClearcoat?: number;
150
155
  /** Stable fine metallic flake strength; zero disables. */
151
156
  metalFlakes?: number;
152
157
  /** Flake cells per object-space unit (usually meters). Default 320. */
@@ -394,7 +399,7 @@ export declare class GpuPropsRenderer {
394
399
  * model moves to the blended pipeline and out of shadowPass from the next frame, exactly as if
395
400
  * `setModels` had been given that alpha; back at 1 it is opaque and casts again.
396
401
  */
397
- setMaterial(model: number, surface: Pick<PropMesh, 'alpha' | 'roughness' | 'metalness' | 'clearcoat' | 'clearcoatRoughness' | 'reflectionStrength' | 'specularIntensity' | 'metalFlakes' | 'flakeScale' | 'pearlStrength'>): void;
402
+ setMaterial(model: number, surface: Pick<PropMesh, 'alpha' | 'roughness' | 'metalness' | 'clearcoat' | 'clearcoatRoughness' | 'directClearcoat' | 'reflectionStrength' | 'specularIntensity' | 'metalFlakes' | 'flakeScale' | 'pearlStrength'>): void;
398
403
  setModels(meshes: PropMesh[]): void;
399
404
  /**
400
405
  * Group instances by model and upload the per-model instance buffers.
@@ -329,6 +329,19 @@ fn ggx(nh: f32, nv: f32, nl: f32, rough: f32) -> f32 {
329
329
  let G = (nv / max(nv * (1.0-k) + k, 0.0001)) * (nl / max(nl * (1.0-k) + k, 0.0001));
330
330
  return D * G / max(4.0 * nv * nl, 0.0001);
331
331
  }
332
+ // Smith-GGX for the transparent dielectric layer. Widen the microfacet
333
+ // distribution by the normal variance across one pixel to retain unresolved
334
+ // key-light reflections when a curved surface becomes small on screen.
335
+ fn directCoat(n:vec3<f32>, nh:f32, nv:f32, nl:f32, rough:f32) -> f32 {
336
+ let dx = dpdx(n); let dy = dpdy(n);
337
+ let variance = min(0.18, 0.25*(dot(dx,dx)+dot(dy,dy)));
338
+ let a2 = min(1.0, pow(rough,4.0)+variance);
339
+ let denom = (1.0-nh*nh) + nh*nh*a2;
340
+ let D = a2 / max(3.14159265*denom*denom,1e-12);
341
+ let gv = nl*sqrt(a2+(1.0-a2)*nv*nv);
342
+ let gl = nv*sqrt(a2+(1.0-a2)*nl*nl);
343
+ return nl*D*0.5/max(gv+gl,0.0001);
344
+ }
332
345
  fn srgbToLinear(c: vec3<f32>) -> vec3<f32> {
333
346
  return select(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), c > vec3(0.04045));
334
347
  }
@@ -377,6 +390,9 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
377
390
  if (mtl.mat.z >= 0.0) {
378
391
  let V = normalize(u.cam.xyz - i.world);
379
392
  let L = -normalize(u.sun.xyz);
393
+ // Thin tissue scatters a share of the key light into the opposite
394
+ // hemisphere. Keep the surface opaque to visibility and retain its shadow.
395
+ if (mtl.optics.z > 0.0 && dot(i.n,V) < 0.0) { N = -N; }
380
396
  let H = normalize(L + V);
381
397
  let nv = max(dot(N, V), 0.001);
382
398
  let nl = max(dot(N, L), 0.0);
@@ -394,7 +410,8 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
394
410
  + pearlTint * mtl.paint.z * (0.035 + 0.13*pow(1.0-nv,2.0));
395
411
  let F = fresnel(f0, vh);
396
412
  let kd = (vec3(1.0)-F) * (1.0-metal);
397
- let direct = (kd * albedo / 3.14159265 + F * ggx(nh,nv,nl,rough)) * u.sunCol.xyz * nl * sh * 2.5;
413
+ let diffuseCosine = mix(nl,max(-dot(N,L),0.0),mtl.optics.z);
414
+ let direct = (kd * albedo * diffuseCosine / 3.14159265 + F * ggx(nh,nv,nl,rough) * nl) * u.sunCol.xyz * sh * 2.5;
398
415
  let R = reflect(-V,N);
399
416
  let env = environment(R,rough) * mtl.coat.y;
400
417
  let reflected = env * fresnel(f0,nv) * (1.0-rough*0.6);
@@ -409,7 +426,13 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
409
426
  let ao=select(1.0,orm.r,mtl.maps.y>0.5);
410
427
  let diffuse = albedo * ambient * skyOcclusion * (1.0-metal)*ao;
411
428
  let coatF = fresnel(vec3(0.04),nv) * mtl.coat.x;
412
- let coating = environment(R,mtl.surface.z) * coatF * mtl.coat.y;
429
+ var coating = environment(R,mtl.surface.z) * coatF * mtl.coat.y;
430
+ if (mtl.optics.w > 0.0 && mtl.coat.x > 0.0) {
431
+ // A wet film reflects the directional key as well as the environment.
432
+ // The key follows incident radiance and receiver shadows in world space.
433
+ let amount = mtl.coat.x*mtl.optics.w*directCoat(N,nh,nv,nl,mtl.surface.z);
434
+ coating += fresnel(vec3<f32>(0.04),vh)*amount*u.sunCol.xyz*sh*2.5;
435
+ }
413
436
  // A soft fiber lobe distinguishes woven upholstery from a glossy dielectric.
414
437
  // Neutral defaults preserve the existing PBR response in other consumers.
415
438
  let sheen = albedo * mtl.surface.y * (u.sunCol.xyz * nl * sh * pow(1.0-vh,5.0)
@@ -1074,6 +1097,7 @@ export class GpuPropsRenderer {
1074
1097
  reflectionStrength: 5,
1075
1098
  specularIntensity: 12,
1076
1099
  clearcoatRoughness: 14,
1100
+ directClearcoat: 23,
1077
1101
  metalFlakes: 16,
1078
1102
  flakeScale: 17,
1079
1103
  pearlStrength: 18,
@@ -1237,8 +1261,8 @@ export class GpuPropsRenderer {
1237
1261
  0,
1238
1262
  Math.max(0, Math.min(1, m.transmission ?? 0)),
1239
1263
  m.unlit ? 1 : m.glow ? 2 : 0,
1240
- 0,
1241
- 0,
1264
+ Math.max(0, Math.min(1, m.diffuseTransmission ?? 0)),
1265
+ Math.max(0, Math.min(1, m.directClearcoat ?? 0)),
1242
1266
  ]);
1243
1267
  dev.queue.writeBuffer(matBuf, 0, materialValues);
1244
1268
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.71",
3
+ "version": "0.15.73",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {