Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Anyone knows what kind of BVH is used in Unity's new Physics?

Discussion in 'Physics Previews' started by torano, Jul 16, 2019.

  1. torano

    torano

    Joined:
    Apr 7, 2017
    Posts:
    46
    I am trying to implement some Bounding Volume Hierarchy(BVH) in parallel using Job System for my own intersection/raycasting system, and searching ways to do that, I found Unity already has it in the Physics package! so I thought why not learn from it. But the problem is I don't know what kind of BVH is actually used.

    I tried to understand how it is built by reading codes in BoundingVolumeHierarchy.cs & BoundingVolumeHierarchyBuilder.cs but I couldn't get it. There are only a few comments and there is no explanation about BVH in the documents, so it is pretty difficult to understand how BVH is built. (Also, since it is a preview package, I can't run it line by line with debugging. It is hard to even find where a function is used from the function in Visual Studio because "Find All References" doesn't work.)
    Can anyone help me learn about Unity's BVH structure a bit?
     
  2. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
  3. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    Hi torano, it's an AABB tree. Each node has an AABB that contains all of that node's descendants. Leaf nodes' AABBs contain the things stored in the tree, for example rigid bodies in the broadphase or triangles in a mesh. Nodes have four children each. There are multiple ways to build the tree, one popular method is the surface area heuristic.
     
  4. torano

    torano

    Joined:
    Apr 7, 2017
    Posts:
    46
    trying to figure it out a week but not
     
  5. torano

    torano

    Joined:
    Apr 7, 2017
    Posts:
    46
    Sorry guys for my late reply. My comment was regarded as spam-like for some reason. I can't reply yet though I can post just a comment.
     
  6. torano

    torano

    Joined:
    Apr 7, 2017
    Posts:
    46
    To AlanMattano, BVH is a tree structure to search a specific primitive efficiently and there are a lot of ways to build.
     
  7. torano

    torano

    Joined:
    Apr 7, 2017
    Posts:
    46
    To MaxAbernethy, AABB tree is just like BVH, and there are a lot of ways to build if I am not mistaken, right? How it is built actually in the physics package?
    I learned a little bit of BVH already reading PBRT book(only BVH part), so I know how to build a basic BVH like building BVH recursively with SAH, building LBVH/HLBVH with morton codes. But Unity seems to use another way from the code I guess.