Open Nodli opened 2 years ago
The issue is also present in PhysX version 3.4. https://github.com/Nodli/PhysX-3.4/blob/5e42a5f112351a223c19c17bb331e6c55037b8eb/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightField.cpp#L765
Thanks for reporting this. The fix looks good. Looking into the origins of this bug, it seems it stems from trying to avoid a performance penalty converting floats to ints on Xbox 360.
The vertex index in Gu::HeightField::computeCellCoordinates is computed in 32-bit floating point and the lack of precision causes indexing errors. Indexing errors of 1 start appearing on GuHeightField with a size between 4000x4000 and 5000x5000. For example a GuHeighField with 8193 columns can see x = 5720 and z = 7826 which means vertexIndex should be 5720*8193+7826 = 46871786 but the floating point representation only allows 46871784 or 46871788 as values. Wrong indexing causes issues when trying to compute normals or determine the orientation of the tesselation of a GuHeightField.