ugly-game 0.15.74 → 0.15.75

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.
@@ -1,7 +1,10 @@
1
1
  /// <reference types="@webgpu/types" preserve="true" />
2
+ export { WET_RIND_WGSL } from './wetRind.js';
3
+ export { INTERIOR_LIGHT_WGSL } from './interiorLight.js';
2
4
  import { type DepthConvention } from '../depthConvention.js';
3
5
  import { type PropInspectionChannel } from './propInspection.js';
4
6
  export type { PropInspectionChannel } from './propInspection.js';
7
+ export { THIN_TISSUE_WGSL } from './thinTissue.js';
5
8
  export declare const MAX_CASCADES = 4;
6
9
  export declare const MAX_PROP_POINT_LIGHTS = 8;
7
10
  /** Caller-selected local lights, in the same rebased coordinates as frame().
@@ -139,6 +142,12 @@ export interface PropMesh {
139
142
  * with distance. Unlike `unlit`, vertex colours count.
140
143
  */
141
144
  glow?: boolean;
145
+ /** Normal-incidence optical depth of the clear or tissue rind over a luminous
146
+ * source. On glow materials a positive value attenuates its linear radiance
147
+ * by the viewing path length. Zero keeps the display-referred glow path. */
148
+ interiorOpticalDepth?: number;
149
+ /** Local height of the wet contact zone above model y=0. Omitted for dry material. */
150
+ wetRindHeight?: number;
142
151
  /** Caller-owned linear occlusion/roughness/metalness map (RGB). */
143
152
  ormMap?: GPUTexture;
144
153
  normalScale?: number;
@@ -6,9 +6,15 @@
6
6
  // ─────────────────────────────────────────────────────────────────────────────
7
7
  // The cull reuses the SAME plane extraction the rest of the engine uses. A second, local copy of
8
8
  // Gribb-Hartmann is exactly how a cull ends up disagreeing with the projection it is culling for.
9
+ import { WET_RIND_WGSL } from './wetRind.js';
10
+ export { WET_RIND_WGSL } from './wetRind.js';
11
+ import { INTERIOR_LIGHT_WGSL } from './interiorLight.js';
12
+ export { INTERIOR_LIGHT_WGSL } from './interiorLight.js';
9
13
  import { frustumPlanes } from '../mat4';
10
14
  import { FORWARD_DEPTH, nearerCompare, } from '../depthConvention.js';
11
15
  import { inspectionFragment, propInspectionChannels, PropInspectionGeometry, } from './propInspection.js';
16
+ import { THIN_TISSUE_WGSL } from './thinTissue.js';
17
+ export { THIN_TISSUE_WGSL } from './thinTissue.js';
12
18
  export const MAX_CASCADES = 4; // must match gpuShadow's
13
19
  export const MAX_PROP_POINT_LIGHTS = 8;
14
20
  const POINT_LIGHT_WORDS = 4 + MAX_PROP_POINT_LIGHTS * 16;
@@ -46,7 +52,7 @@ struct Inst { m: mat4x4<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32>, d3: v
46
52
  // alpha-test cutoff (0 ⇒ no test, which is every model that predates it).
47
53
  // mat = opacity, cutoff, roughness (-1 = legacy), metalness.
48
54
  // coat = clearcoat, reflection strength, unused, unused.
49
- struct Mat { mat: vec4<f32>, coat: vec4<f32>, maps: vec4<f32>, surface: vec4<f32>, paint: vec4<f32>, optics: vec4<f32> };
55
+ struct Mat { mat: vec4<f32>, coat: vec4<f32>, maps: vec4<f32>, surface: vec4<f32>, paint: vec4<f32>, optics: vec4<f32>, medium: vec4<f32> };
50
56
  @group(2) @binding(2) var<uniform> mtl: Mat;
51
57
  @group(2) @binding(3) var environmentTex: texture_2d<f32>;
52
58
  @group(2) @binding(4) var normalTex: texture_2d<f32>;
@@ -351,8 +357,17 @@ fn srgbToLinear(c: vec3<f32>) -> vec3<f32> {
351
357
  fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
352
358
  return select(c * 12.92, 1.055 * pow(max(c, vec3(0.0)), vec3(1.0/2.4)) - 0.055, c > vec3(0.0031308));
353
359
  }
354
- fn effectiveRoughness(orm:vec3<f32>) -> f32 {
355
- return clamp(mtl.mat.z * select(1.0,orm.g,mtl.maps.y>0.5), 0.045, 1.0);
360
+ ${INTERIOR_LIGHT_WGSL}
361
+ fn propEmission(tex: vec3<f32>, pigment: vec3<f32>, normal: vec3<f32>, world: vec3<f32>) -> vec3<f32> {
362
+ if (mtl.medium.x <= 0.0) { return tex*pigment; }
363
+ let view = normalize(u.cam.xyz-world);
364
+ return tex*srgbToLinear(max(pigment,vec3(0.0)))*buriedLightEscape(dot(normal,view),mtl.medium.x);
365
+ }
366
+ ${WET_RIND_WGSL}
367
+ fn effectiveRoughness(orm:vec3<f32>, localY:f32) -> f32 {
368
+ let dry = clamp(mtl.mat.z * select(1.0,orm.g,mtl.maps.y>0.5), 0.045, 1.0);
369
+ if (mtl.medium.y > 0.0) { return wetRindRoughness(dry,wetRindCoverage(localY,mtl.medium.y,dry)); }
370
+ return dry;
356
371
  }
357
372
  fn effectiveAO(orm:vec3<f32>) -> f32 { return select(1.0,orm.r,mtl.maps.y>0.5); }
358
373
  fn surfaceOpacity(n:vec3<f32>, world:vec3<f32>) -> f32 {
@@ -361,6 +376,7 @@ fn surfaceOpacity(n:vec3<f32>, world:vec3<f32>) -> f32 {
361
376
  let F = 0.04 + 0.96*pow(1.0-nv,5.0);
362
377
  return clamp(1.0-mtl.optics.x*(1.0-F),0.0,1.0);
363
378
  }
379
+ ${THIN_TISSUE_WGSL}
364
380
  @fragment fn fs(i: VO) -> @location(0) vec4<f32> {
365
381
  var N = normalize(i.n);
366
382
  let materialUV=i.uv*mtl.maps.w;
@@ -398,6 +414,10 @@ fn surfaceOpacity(n:vec3<f32>, world:vec3<f32>) -> f32 {
398
414
  }
399
415
  base = hsvShift(base, u.grade.x, max(u.grade.y, 0.0), max(u.grade.z, 0.0));
400
416
  ${inspect ? inspectionFragment : ''}
417
+ if (mtl.optics.y > 1.5) {
418
+ let fog = clamp(1.0-exp(-length(i.world-u.cam.xyz)*u.fog.w),0.0,1.0);
419
+ return vec4(mix(propEmission(tex.rgb,i.c,normalize(i.n),i.world),u.fog.xyz,fog),mtl.mat.x);
420
+ }
401
421
  let spec = u.surf.z;
402
422
  var lit = base * (u.amb.xyz * ff + d * u.sunCol.xyz * sh * (1.0 + spec * 0.6))
403
423
  + base * u.surf.w; // emissive — bioluminescence on dark worlds
@@ -412,7 +432,7 @@ fn surfaceOpacity(n:vec3<f32>, world:vec3<f32>) -> f32 {
412
432
  let nl = max(dot(N, L), 0.0);
413
433
  let nh = max(dot(N, H), 0.0);
414
434
  let vh = max(dot(V, H), 0.0);
415
- let rough = effectiveRoughness(orm);
435
+ let rough = effectiveRoughness(orm, i.l.y);
416
436
  let metal = clamp(mtl.mat.w * select(1.0,orm.b,mtl.maps.y>0.5), 0.0, 1.0);
417
437
  // Vertex/instance tints are display sRGB, while albedo textures use sRGB GPU
418
438
  // formats (and arrive decoded). Legacy props keep their historical path.
@@ -424,8 +444,11 @@ fn surfaceOpacity(n:vec3<f32>, world:vec3<f32>) -> f32 {
424
444
  + pearlTint * mtl.paint.z * (0.035 + 0.13*pow(1.0-nv,2.0));
425
445
  let F = fresnel(f0, vh);
426
446
  let kd = (vec3(1.0)-F) * (1.0-metal);
427
- let diffuseCosine = mix(nl,max(-dot(N,L),0.0),mtl.optics.z);
428
- let direct = (kd * albedo * diffuseCosine / 3.14159265 + F * ggx(nh,nv,nl,rough) * nl) * u.sunCol.xyz * sh * 2.5;
447
+ var diffuseLight = albedo * nl;
448
+ if (mtl.optics.z > 0.0) {
449
+ diffuseLight = thinTissueDiffuse(albedo, nl, normalize(i.n), L, V, mtl.optics.z);
450
+ }
451
+ let direct = (kd * diffuseLight / 3.14159265 + F * ggx(nh,nv,nl,rough) * nl) * u.sunCol.xyz * sh * 2.5;
429
452
  let R = reflect(-V,N);
430
453
  let env = environment(R,rough) * mtl.coat.y;
431
454
  let reflected = env * fresnel(f0,nv) * (1.0-rough*0.6);
@@ -441,7 +464,7 @@ fn surfaceOpacity(n:vec3<f32>, world:vec3<f32>) -> f32 {
441
464
  let diffuse = albedo * ambient * skyOcclusion * (1.0-metal)*ao;
442
465
  let coatF = fresnel(vec3(0.04),nv) * mtl.coat.x;
443
466
  var coating = environment(R,mtl.surface.z) * coatF * mtl.coat.y;
444
- if (mtl.optics.w > 0.0 && mtl.coat.x > 0.0) {
467
+ if (mtl.optics.w > 0.0 && mtl.coat.x > 0.0 && mtl.optics.x <= 0.0) {
445
468
  // A wet film reflects the directional key as well as the environment.
446
469
  // The key follows incident radiance and receiver shadows in world space.
447
470
  let amount = mtl.coat.x*mtl.optics.w*directCoat(N,nh,nv,nl,mtl.surface.z);
@@ -496,16 +519,31 @@ fn surfaceOpacity(n:vec3<f32>, world:vec3<f32>) -> f32 {
496
519
  let f = clamp(1.0 - exp(-dist * u.fog.w), 0.0, 1.0);
497
520
  // mtl.mat.x is the model's opacity, 1 for every model that does not set it — the same constant
498
521
  // this returned before, so the opaque pipeline draws exactly what it always did.
499
- let opacity = surfaceOpacity(N,i.world);
522
+ var opacity = surfaceOpacity(N,i.world);
500
523
  // Thin glazing reflects more at grazing angles and transmits the rendered
501
524
  // scene at normal incidence. This does not approximate thick-glass refraction.
502
525
  if (mtl.optics.x > 0.0) {
503
526
  let V = normalize(u.cam.xyz-i.world);
504
- let radiance = environment(reflect(-V,N),max(mtl.mat.z,0.045));
527
+ var radiance = environment(reflect(-V,N),max(mtl.mat.z,0.045));
528
+ if (mtl.optics.w > 0.0 && mtl.coat.x > 0.0) {
529
+ let L = -normalize(u.sun.xyz);
530
+ let halfVector = L+V;
531
+ let H = halfVector*inverseSqrt(max(dot(halfVector,halfVector),0.00000001));
532
+ let nl = max(dot(N,L),0.0);
533
+ let nv = max(dot(N,V),0.001);
534
+ let spec = directCoat(N,max(dot(N,H),0.0),nv,nl,mtl.surface.z);
535
+ let keyReflection = u.sunCol.xyz*(sh*2.5*mtl.optics.w*mtl.coat.x*spec)
536
+ *fresnel(vec3(0.04),max(dot(V,H),0.0));
537
+ // Express the bright key lobe as coverage on an LDR blended target.
538
+ // Otherwise its peak clips before the small Fresnel alpha is applied.
539
+ let glint = 1.0-exp(-max(keyReflection.r,max(keyReflection.g,keyReflection.b))*u.look.y);
540
+ let combined = opacity+(1.0-opacity)*glint;
541
+ radiance = (radiance*opacity+keyReflection)/max(combined,0.04);
542
+ opacity = combined;
543
+ }
505
544
  lit = toneMap(radiance);
506
545
  }
507
546
  // A display-referred render texture (rear-view camera) is already lit.
508
- if (mtl.optics.y > 1.5) { return vec4(mix(tex.rgb * i.c, u.fog.xyz, f), mtl.mat.x); }
509
547
  if (mtl.optics.y > 0.5) { return vec4(tex.rgb, mtl.mat.x); }
510
548
  return vec4(mix(lit, u.fog.xyz, f), opacity);
511
549
  }`;
@@ -1254,7 +1292,7 @@ export class GpuPropsRenderer {
1254
1292
  const alpha = m.alpha ?? 1;
1255
1293
  const cutout = m.cutout ?? 0;
1256
1294
  const matBuf = dev.createBuffer({
1257
- size: 96,
1295
+ size: 112,
1258
1296
  usage: U.UNIFORM | U.COPY_DST,
1259
1297
  });
1260
1298
  const materialValues = new Float32Array([
@@ -1282,6 +1320,10 @@ export class GpuPropsRenderer {
1282
1320
  m.unlit ? 1 : m.glow ? 2 : 0,
1283
1321
  Math.max(0, Math.min(1, m.diffuseTransmission ?? 0)),
1284
1322
  Math.max(0, Math.min(1, m.directClearcoat ?? 0)),
1323
+ Math.max(0, Math.min(8, m.interiorOpticalDepth ?? 0)),
1324
+ Math.max(0, m.wetRindHeight ?? 0),
1325
+ 0,
1326
+ 0,
1285
1327
  ]);
1286
1328
  dev.queue.writeBuffer(matBuf, 0, materialValues);
1287
1329
  return {
@@ -0,0 +1,4 @@
1
+ /** Beer–Lambert escape through a thin non-emitting rind around a luminous
2
+ * chamber. At grazing incidence the tangent path is limited to eight times
3
+ * the normal thickness; real curved layers have a finite tangent chord. */
4
+ export declare const INTERIOR_LIGHT_WGSL = "\nfn buriedLightEscape(viewCosine: f32, opticalDepth: f32) -> f32 {\n return exp(-opticalDepth / max(abs(viewCosine), 0.125));\n}\n";
@@ -0,0 +1,8 @@
1
+ /** Beer–Lambert escape through a thin non-emitting rind around a luminous
2
+ * chamber. At grazing incidence the tangent path is limited to eight times
3
+ * the normal thickness; real curved layers have a finite tangent chord. */
4
+ export const INTERIOR_LIGHT_WGSL = /* wgsl */ `
5
+ fn buriedLightEscape(viewCosine: f32, opticalDepth: f32) -> f32 {
6
+ return exp(-opticalDepth / max(abs(viewCosine), 0.125));
7
+ }
8
+ `;
@@ -1,7 +1,7 @@
1
1
  import type { PropMesh } from './gpuProps.js';
2
2
  export declare const propInspectionChannels: readonly ["lit", "albedo", "normal", "roughness", "emissive", "ao", "clay", "wireframe", "density", "uv", "batch"];
3
3
  export type PropInspectionChannel = (typeof propInspectionChannels)[number];
4
- export declare const inspectionFragment = "\n if (u.grade.w > 0.5) {\n let channel = u32(u.grade.w);\n let opacity = surfaceOpacity(N,i.world);\n let albedo = select(base, srgbToLinear(i.c) * tex.rgb, mtl.mat.z >= 0.0);\n var display = vec3(0.0);\n switch channel {\n case 1u: { return vec4(select(albedo, tex.rgb, mtl.optics.y == 1.0),opacity); }\n case 2u: {\n let backTissue = mtl.optics.z>0.0 && dot(i.n,u.cam.xyz-i.world)<0.0;\n display=select(N,-N,backTissue)*0.5+0.5;\n }\n case 3u: { display=vec3(select(1.0,effectiveRoughness(orm),mtl.mat.z>=0.0)); }\n case 4u: {\n var emission = select(vec3(0.0), base*u.surf.w, mtl.mat.z<0.0);\n if (mtl.optics.y > 1.5) { emission = tex.rgb * i.c; }\n return vec4(emission,opacity);\n }\n case 5u: { display=vec3(select(1.0,effectiveAO(orm),mtl.mat.z>=0.0)); }\n case 6u: {\n // White diffuse clay shows the smooth geometry normals alone.\n let geoN = normalize(i.n);\n let nl = max(0.0,dot(geoN,-normalize(u.sun.xyz)));\n var ambient = u.amb.xyz * (0.6+0.4*max(geoN.y,0.0));\n if (u.look.z>0.0) { ambient=textureSampleLevel(sceneEnvTex,albedoSamp,equirectUV(geoN),u.look2.w).rgb*u.look.z; }\n return vec4(toneMap(vec3(0.76)*(ambient+u.sunCol.xyz*nl*sh*2.5/3.14159265)),1.0);\n }\n case 7u: {\n let dx=dpdx(i.bary); let dy=dpdy(i.bary);\n let dist=i.bary / max(sqrt(dx*dx+dy*dy),vec3(1e-6));\n let edge=1.0-smoothstep(0.0,1.15,min(dist.x,min(dist.y,dist.z)));\n display=mix(vec3(0.12,0.15,0.18),vec3(0.87,0.96,1.0),edge);\n }\n case 8u: {\n // The determinant maps one screen pixel to a fraction of the unit barycentric triangle (area 0.5).\n // A <=1 px\u00B2 triangle is hot, >=256 px\u00B2 cool. Area follows the actual posed projection.\n let dx=dpdx(i.bary.xy); let dy=dpdy(i.bary.xy);\n let area=0.5/max(abs(dx.x*dy.y-dx.y*dy.x),1e-10);\n let t=clamp(log2(max(area,1.0))/8.0,0.0,1.0);\n display=mix(mix(vec3(1.0,0.22,0.12),vec3(1.0,0.88,0.23),clamp(t*2.0,0.0,1.0)),\n vec3(0.12,0.36,0.87),clamp(t*2.0-1.0,0.0,1.0));\n }\n case 9u: {\n let uv=i.uv * mtl.surface.w;\n let q=uv*8.0;\n let w=clamp(fwidth(q),vec2(0.001),vec2(1.0));\n let band=clamp((abs(fract(q*0.5+0.25)-0.5)*4.0-1.0)/w,vec2(-1.0),vec2(1.0));\n let checker = 0.5+0.5*band.x*band.y;\n display=mix(vec3(0.14,0.18,0.24),vec3(0.77,0.85,0.92),checker);\n }\n default: {\n display = vec3(0.55)+0.37*cos(6.2831853*(mtl.paint.w*0.618034+vec3(0.0,0.34,0.66)));\n }\n }\n return vec4(select(display,srgbToLinear(display),u.pointMeta.y>0.5),opacity);\n }\n";
4
+ export declare const inspectionFragment = "\n if (u.grade.w > 0.5) {\n let channel = u32(u.grade.w);\n let opacity = surfaceOpacity(N,i.world);\n let albedo = select(base, srgbToLinear(i.c) * tex.rgb, mtl.mat.z >= 0.0);\n var display = vec3(0.0);\n switch channel {\n case 1u: { return vec4(select(albedo, tex.rgb, mtl.optics.y == 1.0),opacity); }\n case 2u: {\n let backTissue = mtl.optics.z>0.0 && dot(i.n,u.cam.xyz-i.world)<0.0;\n display=select(N,-N,backTissue)*0.5+0.5;\n }\n case 3u: { display=vec3(select(1.0,effectiveRoughness(orm, i.l.y),mtl.mat.z>=0.0)); }\n case 4u: {\n var emission = select(vec3(0.0), base*u.surf.w, mtl.mat.z<0.0);\n if (mtl.optics.y > 1.5) { emission = propEmission(tex.rgb,i.c,normalize(i.n),i.world); }\n return vec4(emission,opacity);\n }\n case 5u: { display=vec3(select(1.0,effectiveAO(orm),mtl.mat.z>=0.0)); }\n case 6u: {\n // White diffuse clay shows the smooth geometry normals alone.\n let geoN = normalize(i.n);\n let nl = max(0.0,dot(geoN,-normalize(u.sun.xyz)));\n var ambient = u.amb.xyz * (0.6+0.4*max(geoN.y,0.0));\n if (u.look.z>0.0) { ambient=textureSampleLevel(sceneEnvTex,albedoSamp,equirectUV(geoN),u.look2.w).rgb*u.look.z; }\n return vec4(toneMap(vec3(0.76)*(ambient+u.sunCol.xyz*nl*sh*2.5/3.14159265)),1.0);\n }\n case 7u: {\n let dx=dpdx(i.bary); let dy=dpdy(i.bary);\n let dist=i.bary / max(sqrt(dx*dx+dy*dy),vec3(1e-6));\n let edge=1.0-smoothstep(0.0,1.15,min(dist.x,min(dist.y,dist.z)));\n display=mix(vec3(0.12,0.15,0.18),vec3(0.87,0.96,1.0),edge);\n }\n case 8u: {\n // The determinant maps one screen pixel to a fraction of the unit barycentric triangle (area 0.5).\n // A <=1 px\u00B2 triangle is hot, >=256 px\u00B2 cool. Area follows the actual posed projection.\n let dx=dpdx(i.bary.xy); let dy=dpdy(i.bary.xy);\n let area=0.5/max(abs(dx.x*dy.y-dx.y*dy.x),1e-10);\n let t=clamp(log2(max(area,1.0))/8.0,0.0,1.0);\n display=mix(mix(vec3(1.0,0.22,0.12),vec3(1.0,0.88,0.23),clamp(t*2.0,0.0,1.0)),\n vec3(0.12,0.36,0.87),clamp(t*2.0-1.0,0.0,1.0));\n }\n case 9u: {\n let uv=i.uv * mtl.surface.w;\n let q=uv*8.0;\n let w=clamp(fwidth(q),vec2(0.001),vec2(1.0));\n let band=clamp((abs(fract(q*0.5+0.25)-0.5)*4.0-1.0)/w,vec2(-1.0),vec2(1.0));\n let checker = 0.5+0.5*band.x*band.y;\n display=mix(vec3(0.14,0.18,0.24),vec3(0.77,0.85,0.92),checker);\n }\n default: {\n display = vec3(0.55)+0.37*cos(6.2831853*(mtl.paint.w*0.618034+vec3(0.0,0.34,0.66)));\n }\n }\n return vec4(select(display,srgbToLinear(display),u.pointMeta.y>0.5),opacity);\n }\n";
5
5
  export declare class PropInspectionGeometry {
6
6
  private readonly device;
7
7
  private readonly meshes;
@@ -25,10 +25,10 @@ export const inspectionFragment = /* wgsl */ `
25
25
  let backTissue = mtl.optics.z>0.0 && dot(i.n,u.cam.xyz-i.world)<0.0;
26
26
  display=select(N,-N,backTissue)*0.5+0.5;
27
27
  }
28
- case 3u: { display=vec3(select(1.0,effectiveRoughness(orm),mtl.mat.z>=0.0)); }
28
+ case 3u: { display=vec3(select(1.0,effectiveRoughness(orm, i.l.y),mtl.mat.z>=0.0)); }
29
29
  case 4u: {
30
30
  var emission = select(vec3(0.0), base*u.surf.w, mtl.mat.z<0.0);
31
- if (mtl.optics.y > 1.5) { emission = tex.rgb * i.c; }
31
+ if (mtl.optics.y > 1.5) { emission = propEmission(tex.rgb,i.c,normalize(i.n),i.world); }
32
32
  return vec4(emission,opacity);
33
33
  }
34
34
  case 5u: { display=vec3(select(1.0,effectiveAO(orm),mtl.mat.z>=0.0)); }
@@ -0,0 +1,4 @@
1
+ /** Single-scattering approximation for a pigmented sheet. Input pigment and
2
+ * output are linear RGB; the caller supplies light colour, visibility and its
3
+ * BRDF normalisation. This term has no energy source in darkness. */
4
+ export declare const THIN_TISSUE_WGSL = "\nfn thinTissueDiffuse(pigment: vec3<f32>, detailCosine: f32, geometricNormal: vec3<f32>,\n lightDir: vec3<f32>, viewDir: vec3<f32>, amount: f32) -> vec3<f32> {\n let N = faceForward(geometricNormal, -viewDir, geometricNormal);\n let back = max(-dot(N, lightDir), 0.0);\n let reflected = pigment * detailCosine * (1.0 - amount);\n // The incident and exit paths through tissue grow at grazing incidence.\n // A bounded rational attenuation preserves the pigment's absorption hue\n // while avoiding a thickness texture or high-frequency normal-map shimmer.\n let exitCos = abs(dot(N, viewDir));\n let excessPath = (1.0 - back) / (0.35 + back) + 0.5 * (1.0 - exitCos) / (0.35 + exitCos);\n let dye = clamp(pigment, vec3<f32>(0.0), vec3<f32>(1.0));\n let peak = max(max(dye.r, dye.g), dye.b);\n let transmitted = dye * inverseSqrt(max(peak, 0.12)) / (1.0 + (1.0 - dye) * (0.25 + excessPath));\n // A broad forward lobe makes a lamp seen through a membrane read\n // differently from a lamp reflected off it.\n let forward = max(-dot(lightDir, viewDir), 0.0);\n let phase = 0.68 + 1.16 * forward * forward;\n return reflected + transmitted * (amount * back * phase);\n}";
@@ -0,0 +1,23 @@
1
+ /** Single-scattering approximation for a pigmented sheet. Input pigment and
2
+ * output are linear RGB; the caller supplies light colour, visibility and its
3
+ * BRDF normalisation. This term has no energy source in darkness. */
4
+ export const THIN_TISSUE_WGSL = /* wgsl */ `
5
+ fn thinTissueDiffuse(pigment: vec3<f32>, detailCosine: f32, geometricNormal: vec3<f32>,
6
+ lightDir: vec3<f32>, viewDir: vec3<f32>, amount: f32) -> vec3<f32> {
7
+ let N = faceForward(geometricNormal, -viewDir, geometricNormal);
8
+ let back = max(-dot(N, lightDir), 0.0);
9
+ let reflected = pigment * detailCosine * (1.0 - amount);
10
+ // The incident and exit paths through tissue grow at grazing incidence.
11
+ // A bounded rational attenuation preserves the pigment's absorption hue
12
+ // while avoiding a thickness texture or high-frequency normal-map shimmer.
13
+ let exitCos = abs(dot(N, viewDir));
14
+ let excessPath = (1.0 - back) / (0.35 + back) + 0.5 * (1.0 - exitCos) / (0.35 + exitCos);
15
+ let dye = clamp(pigment, vec3<f32>(0.0), vec3<f32>(1.0));
16
+ let peak = max(max(dye.r, dye.g), dye.b);
17
+ let transmitted = dye * inverseSqrt(max(peak, 0.12)) / (1.0 + (1.0 - dye) * (0.25 + excessPath));
18
+ // A broad forward lobe makes a lamp seen through a membrane read
19
+ // differently from a lamp reflected off it.
20
+ let forward = max(-dot(lightDir, viewDir), 0.0);
21
+ let phase = 0.68 + 1.16 * forward * forward;
22
+ return reflected + transmitted * (amount * back * phase);
23
+ }`;
@@ -0,0 +1,4 @@
1
+ /** Capillary contact near the base of grounded material. The incoming dry
2
+ * roughness varies the width of the wet front and leaves grains visible
3
+ * through the film. Caller supplies local height above the support plane. */
4
+ export declare const WET_RIND_WGSL = "\nfn wetRindCoverage(localY: f32, rindHeight: f32, dryRoughness: f32) -> f32 {\n return 1.0 - smoothstep(0.68 + 0.32 * dryRoughness, 1.14 + 0.32 * dryRoughness, localY / max(rindHeight, 0.00001));\n}\nfn wetRindRoughness(dry: f32, coverage: f32) -> f32 {\n return mix(dry, min(dry, 0.14 + dry * 0.16), coverage);\n}\n";
@@ -0,0 +1,11 @@
1
+ /** Capillary contact near the base of grounded material. The incoming dry
2
+ * roughness varies the width of the wet front and leaves grains visible
3
+ * through the film. Caller supplies local height above the support plane. */
4
+ export const WET_RIND_WGSL = /* wgsl */ `
5
+ fn wetRindCoverage(localY: f32, rindHeight: f32, dryRoughness: f32) -> f32 {
6
+ return 1.0 - smoothstep(0.68 + 0.32 * dryRoughness, 1.14 + 0.32 * dryRoughness, localY / max(rindHeight, 0.00001));
7
+ }
8
+ fn wetRindRoughness(dry: f32, coverage: f32) -> f32 {
9
+ return mix(dry, min(dry, 0.14 + dry * 0.16), coverage);
10
+ }
11
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.74",
3
+ "version": "0.15.75",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {