Skip to content

A triangle's texel density is the hit's to compute - #185

Merged
yujiaxu-ops merged 6 commits into
mainfrom
hit-computes
Nov 22, 2026
Merged

yujiaxu-ops merged 6 commits into
mainfrom
hit-computes

Conversation

@yujiaxu-ops

@yujiaxu-ops yujiaxu-ops commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Every triangle carried a constant for its mip choice (half the log of its UV area over its area), made when the scene was built. An instance added an offset for its scale; the skinning pass and the particle passes wrote the constant again each pose and frame. Now the kernel takes it from the triangle where it is hit: its two edges as it stands in the world, and its UVs (mesh_density). Nothing stores or writes it; the attributes' first x word and the instance record's third info word are spare.

It is the first step of moving the geometry to shared vertices and indices: a pass that skins a vertex cannot keep a value a triangle.

A texture's level is one division and one logarithm now (mesh_lod: the density, a footprint's square, what else divides); it was three logarithms.

What changes in a picture:

  • Under a uniform scale, rounding only. Five scenes rendered offline against the build before: four the same bytes, one with 23 of 921,600 pixels off by 6 steps at most.
  • An instance scaled otherwise has its triangles' own density now. Its offset was the cube root of its volume's scale.
  • A fault of the build before: a shadow ray through glass on a scaled instance added the instance's offset twice, so a pane's colour or transmission map was read some levels off (a pane scaled to 1 / 32: five too high). A test holds it.

Measured

GPU time a frame at 1080p on twelve scenes, three alternated pairs against main after a run thrown away:

against main
a scene of cutout foliage +0.6 to +0.8 %
a scene of textured glass +0.3 to +0.7 %
a scene of many emitters -0.65 % in each pair
the other nine within 0.5 % on average, either way

The foliage's cost is the cutout test of a candidate hit, which reads its triangle's edges too where its material has an alpha map: until the geometry step, where it reads the vertices anyway. The pictures' quality figures are main's.

With a logarithm a term, as this was first written, the frame cost up to 1.7 % more on the scenes with textures or cutouts. A build with the same kernel under another function name read as main: the cost was the arithmetic's form.

Checks

  • The kernel's own mesh_density and mesh_lod, their text run on the GPU for 512 triangles (a millimetre to a hundred metres, UVs from a hundredth of the texture to a hundred repeats, ones without area) against 64-bit values.
  • Render tests, natively and under software traversal: a checker on an instance scaled 32 times (a square's inside reads its colour; a level five too high reads grey); the checker in a cutout's alpha on one scaled 256 times; a shadow through a pane with a colour map, the pane scaled 1 / 32 and 32 times. The first of the two fails on the build before.
  • The unit tests and the render tests, natively and under software traversal, beside main's on the same machine: 216 unit tests pass both ways; 268 render tests natively; under software traversal the 23 that fail on main, and no other.
  • 12 mutations: eight of the two functions fail the unit test, four of the places that use them fail a render test.
  • Not held by a test: the density a light sample, a material function's input and a translucent particle read, and the ray's angle a surface's level is divided by. A wrong level there changes noise, or sharpens: no mean sees it.
  • Not run on Vulkan yet.

🤖 Generated with Claude Code


Note

Medium Risk
Touches core path-tracing texture LOD, cutouts, glass, and lighting across many shader paths; visual output can change on non-uniform scales though tests and near-parity on uniform scenes limit regression risk.

Overview
Texture mip level is derived at the hit instead of from precomputed constants in triangle x.x and instance info.z. The path tracer adds mesh_density (world edge lengths and UVs) and refactors mesh_lod to one log from density and footprint; glass, shading, alpha cutouts, emitters, and translucent particles all use this path.

Build and update passes stop writing texel density: scene build, instance_attr, skinning, and both particle shaders drop lod_k / lod_offset; those GPU words are now spare. Non-uniform instance scale gets per-triangle density in world space and fixes double-application of LOD on shadow rays through scaled glass.

Coverage adds a GPU compute check of the two functions against 64-bit reference (512 triangles) and render tests for checker textures, alpha cutouts, and glass shadows on heavily scaled instances.

Reviewed by Cursor Bugbot for commit e3bec15. Bugbot is set up for automated code reviews on this repo. Configure here.

@yujiaxu-ops
yujiaxu-ops marked this pull request as ready for review November 22, 2026 05:32
@yujiaxu-ops
yujiaxu-ops merged commit 66c0fa8 into main Nov 22, 2026
9 checks passed
@yujiaxu-ops
yujiaxu-ops deleted the hit-computes branch November 22, 2026 05:47
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