ugly-game 0.14.18 → 0.14.20

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.
@@ -901,13 +901,22 @@ const LUMA_GAIN: f32 = 1.2428;
901
901
  //
902
902
  // exp and scale are written as 1 on the rows that do not use them: a WGSL const array has no empty
903
903
  // cell, and pow(0, 0) is a value nobody should have to reason about.
904
- const MATS = array<vec4f, 10>(
905
- vec4f(0.00, 1.0, 0.00, 0.0), vec4f(0.00, -1.0, 1.000, 0.0),
906
- vec4f(0.35, 64.0, 0.50, 0.0), vec4f(0.60, -1.0, 1.000, 0.0),
907
- vec4f(0.90, 128.0, 0.80, 1.0), vec4f(1.00, 0.0, 0.333, 0.0),
908
- vec4f(0.90, 256.0, 1.00, 0.0), vec4f(1.00, -1.0, 1.000, 0.0),
909
- vec4f(0.08, 16.0, 0.15, 0.0), vec4f(1.00, 1.0, 0.500, 0.0),
904
+ // b.w is the PROJECTION MODE for the material texture: 0 = triplanar, 1 = cylindrical about the
905
+ // body's long axis. c.x is how far FRESNEL drives the output ALPHA - see the glass note in fs.
906
+ const MATS = array<vec4f, 15>(
907
+ vec4f(0.00, 1.0, 0.00, 0.0), vec4f(0.00, -1.0, 1.000, 0.0), vec4f(0.00, 0.0, 0.0, 0.0),
908
+ vec4f(0.35, 64.0, 0.50, 0.0), vec4f(0.60, -1.0, 1.000, 0.0), vec4f(0.00, 0.0, 0.0, 0.0),
909
+ vec4f(0.90, 128.0, 0.80, 1.0), vec4f(1.00, 0.0, 0.333, 0.0), vec4f(0.00, 0.0, 0.0, 0.0),
910
+ vec4f(0.90, 256.0, 1.00, 0.0), vec4f(1.00, -1.0, 1.000, 0.0), vec4f(1.00, 0.0, 0.0, 0.0),
911
+ vec4f(0.08, 16.0, 0.15, 0.0), vec4f(1.00, 1.0, 0.300, 1.0), vec4f(0.00, 0.0, 0.0, 0.0),
910
912
  );
913
+ // ⚠️ Wood's tile scale is 0.22, not 0.5, and that was set by LOOKING. A shipped human stands ~16.6
914
+ // kit units, so 0.5 repeats the grain about eight times head to foot — fine enough that at any
915
+ // normal camera distance it averages into a flat tan and the character reads as bare skin. 0.22 is
916
+ // closer to four repeats, which is a plank rather than a veneer. It then moved again to 0.30 when
917
+ // wood went CYLINDRICAL: the scale now multiplies a RADIUS rather than a linear coordinate, and a
918
+ // torso is only ~1.5 kit units thick, so the value that gave four bands across a body gave almost
919
+ // no variation at all across its radius and the rings disappeared.
911
920
  fn luma(c: vec3f) -> f32 { return dot(c, vec3f(0.2126, 0.7152, 0.0722)); }
912
921
  // TRIPLANAR: three samples of the same tiling map, blended by the bind-space normal.
913
922
  //
@@ -933,9 +942,35 @@ fn triplanar(layer: i32, p: vec3f, dx: vec3f, dy: vec3f, n: vec3f) -> vec3f {
933
942
  let z = textureSampleGrad(matTex, skinSamp, p.xy, layer, dx.xy, dy.xy).rgb;
934
943
  return x * w.x + y * w.y + z * w.z;
935
944
  }
945
+ // CYLINDRICAL, about the body's own long axis - the projection a thing CARVED FROM A LOG needs.
946
+ //
947
+ // ⚠️ Triplanar is wrong for wood, and it looked it. A 2D tile whose rings run along texture-V maps
948
+ // V to HEIGHT on a chest (the +Z plane wins there), so the rings came out as horizontal bands
949
+ // stacked up the torso - a figure made of discs - and then flipped direction on the arms, where the
950
+ // +X plane wins and V maps to depth instead. Direction that changes with which way a surface
951
+ // happens to face is the one thing a grain must never do.
952
+ //
953
+ // Radius from the axis drives the RINGS and height drives the FIBRE, so a growth ring is a shell
954
+ // around the trunk and the fibre runs the length of it, exactly as in the log the figure came from.
955
+ // Same bind-space trick the hair's uvs2 uses, and for the same reason.
956
+ fn cylindrical(layer: i32, p: vec3f, dx: vec3f, dy: vec3f) -> vec3f {
957
+ let r = length(p.xz);
958
+ // ⚠️ Gradients carried through by the chain rule rather than dropped. d(r)/dx is the radial
959
+ // direction dotted with the position derivative; without it this needs implicit derivatives and
960
+ // is back in the uniform-control-flow trap textureSampleGrad exists to avoid.
961
+ let radial = select(vec2f(1.0, 0.0), p.xz / max(r, 1e-6), r > 1e-6);
962
+ let drx = dot(dx.xz, radial);
963
+ let dry = dot(dy.xz, radial);
964
+ return textureSampleGrad(
965
+ matTex, skinSamp,
966
+ vec2f(p.y, r), layer,
967
+ vec2f(dx.y, drx), vec2f(dy.y, dry),
968
+ ).rgb;
969
+ }
936
970
  @fragment fn fs(i: VOut) -> @location(0) vec4f {
937
- let a = MATS[i.mat * 2u];
938
- let b = MATS[i.mat * 2u + 1u];
971
+ let a = MATS[i.mat * 3u];
972
+ let b = MATS[i.mat * 3u + 1u];
973
+ let c = MATS[i.mat * 3u + 2u];
939
974
  let n = normalize(i.n);
940
975
  let l = -normalize(u.sun.xyz);
941
976
  let d = clamp(dot(n, l), 0.0, 1.0);
@@ -966,7 +1001,13 @@ fn triplanar(layer: i32, p: vec3f, dx: vec3f, dy: vec3f, n: vec3f) -> vec3f {
966
1001
  let crl = length(cr);
967
1002
  let bn = select(vec3f(0.0, 0.0, 1.0), cr / crl, crl > 1e-20);
968
1003
  var matC = vec3f(1.0);
969
- if (i32(b.y) >= 0) { matC = triplanar(i32(b.y), i.rest * b.z, rdx * b.z, rdy * b.z, bn); }
1004
+ if (i32(b.y) >= 0) {
1005
+ if (b.w > 0.5) {
1006
+ matC = cylindrical(i32(b.y), i.rest * b.z, rdx * b.z, rdy * b.z);
1007
+ } else {
1008
+ matC = triplanar(i32(b.y), i.rest * b.z, rdx * b.z, rdy * b.z, bn);
1009
+ }
1010
+ }
970
1011
  let base = detail * matC * i.tint.rgb;
971
1012
 
972
1013
  let v = normalize(u.cam.xyz - i.world);
@@ -986,13 +1027,37 @@ fn triplanar(layer: i32, p: vec3f, dx: vec3f, dy: vec3f, n: vec3f) -> vec3f {
986
1027
  // between gold and yellow plastic with a white highlight sitting on it.
987
1028
  let specCol = mix(vec3f(1.0), base, a.w);
988
1029
  let spec = (a.x + fres) * pow(max(ndh, 0.0), a.y) * specCol * u.sunCol.xyz * sh;
989
- let lit = base * (1.0 - a.w) * (u.amb.xyz + d * u.sunCol.xyz * sh) + spec;
1030
+ // ⚠️ A METAL STILL RECEIVES THE AMBIENT TERM, and the first cut of this did not. Driving diffuse
1031
+ // to zero by metalness is right for the SUN — a metal has no diffuse lobe — but this renderer has
1032
+ // no environment map, and u.amb is the only stand-in for one it has. Zeroing both left a metal
1033
+ // character as a BLACK SILHOUETTE with a single hot spot where the sun happened to mirror, which
1034
+ // is what a metal with nothing to reflect genuinely looks like and is useless as a material.
1035
+ // Tinted by the base colour, because what a metal reflects takes its colour.
1036
+ //
1037
+ // Found by LOOKING at it. Every assertion in the GPU harness passed on the black version: it was
1038
+ // view-dependent, it peaked on the mirror axis, it differed from every other row.
1039
+ let env = base * a.w * u.amb.xyz;
1040
+ let lit = base * (1.0 - a.w) * (u.amb.xyz + d * u.sunCol.xyz * sh) + env + spec;
990
1041
 
991
1042
  let dist = length(i.world - u.cam.xyz);
992
1043
  let f = clamp(1.0 - exp(-dist * u.fog.w), 0.0, 1.0);
993
- // tint.w is the opacity. It is 1 for everyone on the opaque pipeline, where the target has no
994
- // blend state and the channel is ignored, so the two pipelines run the SAME fragment shader.
995
- return vec4f(mix(lit, u.fog.xyz, f), i.tint.w);
1044
+ // ⚠️ GLASS GETS ITS ALPHA FROM FRESNEL, and a flat alpha is why the first cut read as a ghost
1045
+ // rather than as glass. A sheet of glass is nearly CLEAR face-on and nearly OPAQUE at a grazing
1046
+ // angle; that falloff is most of what the eye uses to recognise the material, and with a constant
1047
+ // 0.35 everywhere the body simply faded out evenly and disappeared into the grass.
1048
+ //
1049
+ // The raw Schlick term is reused rather than recomputed - fres above is already
1050
+ // fresnel x pow(1 - n.v, 5), so dividing out the strength recovers the geometric part.
1051
+ //
1052
+ // ⚠️ NOT refraction. Nothing here bends what is behind the body: this pass composites into the
1053
+ // scene colour with loadOp 'load' and never receives a sampleable copy of it, so there is nothing
1054
+ // to distort. A rim is what is reachable without that copy.
1055
+ //
1056
+ // c.x is 0 for every other row, so alpha is exactly tint.w for them - and material 0 is
1057
+ // untouched, which is the invariant the whole table is built around.
1058
+ let rim = select(0.0, fres / max(a.z, 1e-4), a.z > 0.0);
1059
+ let alpha = clamp(mix(i.tint.w, 1.0, c.x * rim), 0.0, 1.0);
1060
+ return vec4f(mix(lit, u.fog.xyz, f), alpha);
996
1061
  }`;
997
1062
  const INITIAL_MERGE_ENTRIES = 4096;
998
1063
  export class GpuCrowdRenderer {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.14.18",
3
+ "version": "0.14.20",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {