Check for Intersections
Created a more efficient way to check for intersections within meshes in Maya. This included intersections between different meshes, intersections within the same mesh's faces, and intersections in the UVs.
Embree was used as a fast BVH solution for finding intersections. It also required some updates of our TBB package in order to use a later version of Embree with the collision functionality. The process included transferring the polygon information from Maya to Embree, checking for intersections for each edge with the rest of the scene using Embree, and gathering those resulting intersecting faces and displaying them in Maya. Used openMP for parallelization and speeding up the process. Other improvements include adding a method for just quickly finding whether two meshes intersect each other. Check for bounding box intersection between meshes before going into Embree calculations. Have each mesh be a different Embree scene (to avoid repetition checks for the same mesh).
Embree could not handle 2D intersections well so a different solution was needed for UV intersections. Approaches tested were: using Embree but instead of using the default triangles uses user-defined shapes (edges) so I could specify the bounding box and intersection methods; using Box2D to create an AABB tree and find intersections between 2D shapes; using Embree but changing the edges of the UVs to be perpendicular to the faces; using the collision functionality in Embree (instead of the intersection one). These methods either failed to correctly find the UV intersections or did not provided sufficient speed up to finding those intersections.
The approach that was used for checking for UV intersections was to use OpenGL to rasterize the UVs and check for any overlaps using a 2 pass method. This allowed us to run this check in the GPU but required some additional tweaking. To avoid the edges giving false overlaps with itself, and additional pass was added were just the edges are drawn into a texture, and that texture is used to discard overlaps that occur at the edges. For UVs that are extremely detailed and small, which might not be drawn in the rasterization, I divided the UVs into different sections, making sure the groups would fill out the entire scene, so that each pass will have more detail and draw those small UV faces too. I used NVIDIA Nsight to profile the results and find areas that slowed down the process to improve them. For example, the ssbo in the glsl shader and the framebuffers with attached textures.
In addition, for this OpenGL process, we integrated all the mesh IDs in a texture as bits, so for every pixel in the texture I have the IDs of the meshes that tried to draw that pixel. There is a limit of 128 IDs I can store per texture (4 color values of 32 bits each) so if there are more than 128 meshes, I create the additinoal needed texture and combine the results from all textures. I encoded the mesh IDs by blending the colors being draw using bitwise operations. Then I decode the pixels individually in the CPU. This ended up being a bit slow to get the results, so instead I changed it to be done in a fragment shader (so it's done in the GPU instead). I changed the rasterization process to be done per-UDIM also for more accuracy.
Decided to use the Embree collision method for UV self-intersections. Required TBB updates. Tested how this would affect our different packages for TBB, Embree, and OpenVDB.
Integrated this new approach for finding intersections into our tool for finding intersections of an animation.
Used:
-
C++
-
Maya's C++ API
-
Embree
-
TBB
-
OpenGL
-
OpenMP
-
NVIDIA Nsight