Skip to content

Make hidden geometry sampling independent of scene shape ordering - #13

Open
matla91 wants to merge 1 commit into
diegoroyo:mainfrom
matla91:fix/deterministic-hgs-shape-order
Open

Make hidden geometry sampling independent of scene shape ordering#13
matla91 wants to merge 1 commit into
diegoroyo:mainfrom
matla91:fix/deterministic-hgs-shape-order

Conversation

@matla91

@matla91 matla91 commented Aug 18, 2026

Copy link
Copy Markdown

The hidden-geometry sampling distribution is currently built in the order returned by scene.shapes(). The sampled distribution index is then used directly with scene.shapes_dr(). If the shape order changes, the same HGS sample can therefore select a different physical shape.

This change sorts the HGS categories by shape.id() when all scene shapes have unique, non-empty IDs. It stores the corresponding original shape indices and maps the sampled category back to the correct index before gathering from scene.shapes_dr(). Scenes without unique, non-empty IDs keep the previous behavior.

Regression test

I added a test that builds the same scene twice, with the two hidden shapes declared in opposite orders, and evaluates the same HGS sample in both scenes.

On the current main branch:

shape_a, shape_b -> [-2.0, 0.0, 1.0]
shape_b, shape_a -> [ 1.25, 0.0, 1.0]

With this patch:

shape_a, shape_b -> [-2.0, 0.0, 1.0]
shape_b, shape_a -> [-2.0, 0.0, 1.0]

The sampling PDF is unchanged.

The regression test passes with llvm_ad_rgb and cuda_ad_rgb. I also ran it in 10 fresh processes on each backend; all runs passed.

pytest still reports the existing failure in tests/integration/test_nlos.py, where the test calls prepare_transient(). That method is not present on the current TransientNLOSPath, and I reproduced the same failure on main before making this change.

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