Function JobBuild.MortonCode3D
Child index BuildNode would pick for p at each of the top levels, root level in the high bits.
uint MortonCode3D (
float3 | p | |
float3 | boundsMin | |
float3 | boundsMax | |
int | levels |
Child index BuildNode would pick for p at each of the top levels, root level in the high bits.
Contract: bit group (levels-1-d) of the result is the child index of the node containing p at depth d, for every d < levels.
Repeats the exact (min+max)*0.5 sequence that BuildNode splits on and QueryRec prunes by, rather than scaling p into a fixed grid. A scaled code disagrees with that sequence for a position within a few ulp of a cell boundary, which files the agent under a node whose bounds exclude it, and QueryRec would then prune the node away and never find it.
Branchless because the comparisons are near 50/50 on any realistic crowd. Written with ifs it costs two mispredicts per level per agent, which is enough to dominate the whole build.