ugly-game 0.14.24 → 0.14.25

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.
@@ -933,15 +933,16 @@ const MATS = array<vec4f, 15>(
933
933
  vec4f(0.35, 64.0, 0.50, 0.0), vec4f(0.60, -1.0, 1.000, 0.0), vec4f(0.00, 0.000, 0.0, 0.0),
934
934
  vec4f(0.90, 128.0, 0.80, 1.0), vec4f(1.00, 0.0, 0.333, 0.0), vec4f(0.00, 0.000, 0.0, 0.0),
935
935
  vec4f(0.90, 256.0, 1.00, 0.0), vec4f(1.00, -1.0, 1.000, 0.0), vec4f(1.00, 0.045, 0.0, 0.0),
936
- vec4f(0.08, 16.0, 0.15, 0.0), vec4f(1.00, 1.0, 0.300, 1.0), vec4f(0.00, 0.000, 0.0, 0.0),
936
+ vec4f(0.08, 16.0, 0.15, 0.0), vec4f(1.00, 1.0, 0.120, 1.0), vec4f(0.00, 0.000, 0.0, 0.0),
937
937
  );
938
938
  // ⚠️ Wood's tile scale is 0.22, not 0.5, and that was set by LOOKING. A shipped human stands ~16.6
939
939
  // kit units, so 0.5 repeats the grain about eight times head to foot — fine enough that at any
940
940
  // normal camera distance it averages into a flat tan and the character reads as bare skin. 0.22 is
941
- // closer to four repeats, which is a plank rather than a veneer. It then moved again to 0.30 when
942
- // wood went CYLINDRICAL: the scale now multiplies a RADIUS rather than a linear coordinate, and a
943
- // torso is only ~1.5 kit units thick, so the value that gave four bands across a body gave almost
944
- // no variation at all across its radius and the rings disappeared.
941
+ // closer to four repeats, which is a plank rather than a veneer. Then 0.30 when wood went
942
+ // CYLINDRICAL, and now 0.12 - because the cylindrical mapping's across-the-body axis is an ANGLE,
943
+ // which is scale-INVARIANT (one turn is one repeat however the position is scaled). So this number
944
+ // no longer sets the grain's fineness at all; it only sets how many repeats run up the HEIGHT, and
945
+ // fewer means longer, more coherent grain lines. Wood grain runs long.
945
946
  fn luma(c: vec3f) -> f32 { return dot(c, vec3f(0.2126, 0.7152, 0.0722)); }
946
947
  // TRIPLANAR: three samples of the same tiling map, blended by the bind-space normal.
947
948
  //
@@ -979,17 +980,27 @@ fn triplanar(layer: i32, p: vec3f, dx: vec3f, dy: vec3f, n: vec3f) -> vec3f {
979
980
  // around the trunk and the fibre runs the length of it, exactly as in the log the figure came from.
980
981
  // Same bind-space trick the hair's uvs2 uses, and for the same reason.
981
982
  fn cylindrical(layer: i32, p: vec3f, dx: vec3f, dy: vec3f) -> vec3f {
982
- let r = length(p.xz);
983
- // ⚠️ Gradients carried through by the chain rule rather than dropped. d(r)/dx is the radial
984
- // direction dotted with the position derivative; without it this needs implicit derivatives and
985
- // is back in the uniform-control-flow trap textureSampleGrad exists to avoid.
986
- let radial = select(vec2f(1.0, 0.0), p.xz / max(r, 1e-6), r > 1e-6);
987
- let drx = dot(dx.xz, radial);
988
- let dry = dot(dy.xz, radial);
983
+ // ⚠️ THE ANGLE AROUND THE AXIS, NOT THE RADIUS, and using the radius is why the first cylindrical
984
+ // wood looked flat. On a limb the visible face sits at a nearly CONSTANT radius, so a radial
985
+ // coordinate barely moves across the surface you are looking at - and the texture's fine axis,
986
+ // which is what carries the grain, therefore produced almost no variation at all. The body came
987
+ // out smooth tan with a hint of striping.
988
+ //
989
+ // Angle moves right across a limb, so the fine axis becomes visible detail: grain lines that run
990
+ // the length of the figure and change as you go around it. This is the hair's uvs2 mapping, for
991
+ // the same reason it was chosen there.
992
+ let r2 = dot(p.xz, p.xz);
993
+ let theta = atan2(p.z, p.x) * 0.15915494 + 0.5; // 1/(2*pi)
994
+ // ⚠️ ANALYTIC gradient, not dpdx of the angle. atan2 jumps by a full turn at +/-pi, and a screen
995
+ // derivative taken across that jump is enormous - it would select the coarsest mip along a seam
996
+ // line down the body. d(theta)/ds = (x*dz - z*dx) / (x^2 + z^2), which is continuous everywhere
997
+ // off the axis. The sampler repeats, so the VALUE wrapping is harmless once the gradient is right.
998
+ let gx = select(0.0, (p.x * dx.z - p.z * dx.x) / r2 * 0.15915494, r2 > 1e-12);
999
+ let gy = select(0.0, (p.x * dy.z - p.z * dy.x) / r2 * 0.15915494, r2 > 1e-12);
989
1000
  return textureSampleGrad(
990
1001
  matTex, skinSamp,
991
- vec2f(p.y, r), layer,
992
- vec2f(dx.y, drx), vec2f(dy.y, dry),
1002
+ vec2f(p.y, theta), layer,
1003
+ vec2f(dx.y, gx), vec2f(dy.y, gy),
993
1004
  ).rgb;
994
1005
  }
995
1006
  @fragment fn fs(i: VOut) -> @location(0) vec4f {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.14.24",
3
+ "version": "0.14.25",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {