Skip to content

P1.4c1: texCoord per texture slot (second uv set), depends on #103 - #128

Open
DennisSmolek wants to merge 2 commits into
mainfrom
issue-52-texcoord1
Open

DennisSmolek wants to merge 2 commits into
mainfrom
issue-52-texcoord1

Conversation

@DennisSmolek

Copy link
Copy Markdown
Member

Part of #52 (P1.4c1, the per-slot texCoord half). Depends on #103 (issue-52-texture-transform): this branch is cut from it, so the diff against main also shows #103's commit until that merges; this PR's own commit is the last one.

What changed

  • Second uv set in the surface data. SceneCopyMesh.uvs1 (glTF TEXCOORD_1), stored only when a mesh has it (SurfaceLayout.uvs1, 2 floats per vertex after the tangent, MESH_FLAG.HAS_UVS1). A scene without it keeps its vertex stride.
  • Per-slot set. TextureInput.texCoord 1 sets bit 31 of the slot record's last word (bit 30: a normal map read from it); TextureLayout.uvSets gates all kernel text, so every kernel without a set-1 slot is byte-identical (all 355 node bench/size-snapshot.ts files, diff -rq empty). New variants tex-uvset1 46.9 KB, tex-xf-uvset1 47.8 KB, wavefront shade 35.7 / 36.6 KB.
  • Shader. rtSurface writes two module-scope privates, rtUv1 (uv1, and the set-1 / set-0 uv density ratio) and rtUv1Frame; rtTexSampleRecord / rtTexLodOf read them for a set-1 record, so none of the ~10 call sites changed (V600). The cone footprint comes from the right set, and a normal map on set 1 is turned into set 0's tangent frame per triangle (rtUvFrame, twin uvFrameMatrix, V602; exact for conformal uv maps).
  • Loader. uvSets: 'first' | 'slot' (default first = today's behaviour; also uvTransform is now passed through loadGltf). slot keeps the first slot's set as uvs and the first other set as uvs1, each texture entry says which it reads (V601). Also fixes a P1.4c1: KHR_texture_transform per texture slot in the shader #103 key collision: an image whose first use had no transform and whose second had one got the same key t0 twice.
  • Bench / export. TextureDesc.texCoord, MeshDesc.uv1, web glb TEXCOORD_1 (exporters/gltf.ts, readGlbMeshes), file geometry attribute uvs1, alpha-card classification reads the slot's set. pbrt / Mitsuba exports throw on texCoord 1 (V603). ReSTIR and MaterialX refuse set-1 slots; PtMegakernel.setScene throws on a kernel / scene-copy layout mismatch (V604).

Verified (correctness only; load 36, best effort)

node bench/runner/run.ts --page texture-texcoord-check --no-lock --load-wait 0 (7 s, M5 Pro, Chrome 158):

  • rtSurface vs the CPU twins on 2000 hits (three rotated instances, one with a mirrored uv1, one without a second set): uv / uv1 / density ratio / frame matrix within 1.3e-7; four slots' lookups within 5e-3 (limit 1e-2), lod 5e-7.
  • Set 1 vs the same map baked into set 0, whole image, both schedulers: colour relMSE 0, colour + normal map 2.6e-15; controls differ by 0.69 / 0.59 (the check can fail).
  • Closed form, colour on set 0 and emission on set 1 with its own mapping: 1828 flat pixels, worst relative deviation 0, both schedulers.

Unit tests: texture-texcoord.test.ts (new), gltf-scene.test.ts (loader), restir.test.ts; pnpm typecheck shows only the pre-existing @pmndrs/vdb errors; vitest on packages/raytracer, packages/pathtracer, bench/scenes, bench/exporters, bench/adapters passes (the 4 @pmndrs/vdb files cannot load in a fresh worktree).

For the maintainer

  • A/B to decide the loader default (uvSets first vs slot): needs a Tier 1 scene with texCoord 1. Khronos MultiUVTest is not in MANIFEST.json (not pinned here: needs the pin procedure); once it is, node bench/runner/run.ts --page texture-texcoord-check plus its golden.
  • Open: the same image with two transforms or sets stores two layers (V504).

DIVERGES V600-V604, TASKS P1.4c1 and a CLAUDE.md trap are updated.

🤖 Generated with Claude Code

DennisSmolek and others added 2 commits December 2, 2026 02:50
TextureInput.uvTransform (2x3 matrix) goes into the slot record (3 vec4u in a
scene that has one, TextureLayout.transforms; byte-identical scene copy and
kernels otherwise). rtTexSampleRecord reads at M uv, the cone footprint is
scaled by the matrix magnification, a normal map's tangent frame is turned.
Loader option uvTransform 'bake' (default) | 'slot'; bench TextureDesc.uvTransform,
MeshDesc.uv.matrix, alpha-card classification, exporters throw on it.
Check page texture-transform-check; DIVERGES V500-V504. Part of #52.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a and the shader)

TextureInput.texCoord 1 reads the mesh's second uv set (SceneCopyMesh.uvs1, opt-in per mesh:
SurfaceLayout.uvs1). Bit 31/30 of the slot record's last word, TextureLayout.uvSets gates all
kernel text (every existing kernel byte-identical). rtSurface writes rtUv1 / rtUv1Frame (V600),
set-1 cone footprint and normal-map frame follow (V602). Loader uvSets 'first' | 'slot' (V601),
bench TextureDesc.texCoord / MeshDesc.uv1, web export TEXCOORD_1, native exports throw (V603),
ReSTIR / MaterialX refuse (V604). Page texture-texcoord-check. Part of #52.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant