Wednesday, 1 May 2024

Select Occluded Faces Tool

During my time on Total War: Three Kingdoms a request came in from the art team to have a 3ds Max tool which would select all hidden faces on a mesh.
This surprisingly turned out to be a very interesting problem to solve. On the surface, it deceptively appeared to be a simple solve but in reality it was quite complex and required some creative ideas to solve it.
I tried a number of ideas, from voxelising the mesh, to firing rays out from each face to calculate whether they're covered by other parts of the geometry, but both didn't give accurate results and/or would take far too long to calculate.
The final chosen solution first involved ensuring the mesh was automatically UV unwrapped so each face had a unique area allocated to it on a texture page.
The second stage was to the render out an ambient occlusion map.
Once the AO map had been created it was just a simple matter of going through each triangle and checking to see if all the AO pixels covering it were black. If they were then it was safe to assume the face was fully hidden (occluded) and therefore could be added to the final occluded face selection.
The tool also offered the option to adjust the accuracy level. This just meant it would give more leniency when checking if all the pixels were black on each triangle i.e. pixels lighter than pure black.
There was also another option to pick a 'terrain' mesh. This would be a grid grid with height offsets. Any faces from the selected mesh which fell under this terrain mesh would also be included in the final occluded face selection.

No comments:

Post a Comment