<p>I am using the SAH-BVH from PBRT-v3, it works fine for triangle-mesh, especially for dense mesh.</p>
<p>But here is a problem. If I added Cornell box while building the BVH tree, the BVH performance will drop to only 20% as before. The Cornell box is only 6 rectangles. Why does it behave in this way? Because it's a big box containing everything? How to improve it?</p>

CC BY-SA 4.0
2020-09-03T15:09:38.160Z
How do you measure that performance drop exactly? There are many possible explanations and knowing this would help narrow it down to the more likely ones.
Olivier
CC BY-SA 4.0
2020-09-03T15:44:17.763Z
I am doing GPU ray tracing in shader. It will drop from 50+fps to 10-fps. @Olivier
iaomw
CC BY-SA 4.0
2020-09-04T14:42:26.157Z
Does your screen go from mostly empty without the box to being filled by a cornell box? Or is the difference there no matter how you place the camera? Are you rendering only primary rays or some number of bounces?
Olivier
CC BY-SA 4.0
2020-09-04T15:55:27.293Z
The mesh takes 50% screen, the box will take 80% maybe. Yeah, it has max 32 bouncing number. @Olivier
iaomw
CC BY-SA 4.0
2020-09-05T16:03:23.167Z
How big are the triangles of the box's walls? If you subdivide them 2 or 3 times, you'll notice an increase in performance but still not upto the original level. The walls will almost always lower the performance of the bvh as they are more a form of a container. You'll get faster performance by checking 12 triangles (assuming 2 per wall) separately instead of dumping them inside a bvh.
gallickgunner
CC BY-SA 4.0
2020-09-05T16:04:36.280Z
The thing is, usually you expand the BVH nodes after constructing it. So if the triangles are big, the nodes will expand and overlap a lot more decreasing the efficiency a lot.
gallickgunner
CC BY-SA 4.0
2020-09-05T18:18:47.713Z
The box is not using any triangles, it's a collection of rect. @gallickgunner
iaomw
CC BY-SA 4.0
2020-09-05T18:37:22.787Z
@iaomw - sorry didn't understand. Do you mean you are doing ray-rectangle intersections in the leaf nodes? Even if that's the case, the point is if you expand the nodes after construction they'll overlap reducing the efficiency.
gallickgunner
CC BY-SA 4.0
2020-09-05T23:21:39.920Z
What do you mean by expand? @gallickgunner
iaomw
CC BY-SA 4.0
2020-09-06T07:07:51.003Z
@iaomw - BVH is object subdivision not space, so there will be nodes that overlap. So after you construct the bvh you don't only expand but I guess the proper word would be "fit" (expand/shrink) the node to its contents.
gallickgunner
CC BY-SA 4.0
2020-09-06T07:17:25.167Z
I think I'm failing to express the key point here. Look at it this way. The key points to making efficient BVHs are, nodes should have minimal volumes, and pruning at the top level should prune the entire subtree of that child node. Now imagine a cornell box scene with a small teapot inside. If you try to dump the large walls inside the BVH these 2 points take a hit since dumping any wall to any node will make it expand it's width or height or both to that of the root Bounding node. So either you subdivide the walls or take them out of the bvh
gallickgunner
CC BY-SA 4.0
2020-09-06T23:40:28.147Z
So, it better to divide big shape into small triangles. But how small it should be? @gallickgunner
iaomw
CC BY-SA 4.0
2020-09-07T06:59:59.510Z
@iaomw - They can be big, but not as big as the root container itself. Take the scenario of the cornell box. The cornell box itself is the root node so it's walls kinda form up the walls of the root node itself. So when you try to insert any of the walls in a child node the node expands to the size of the root node in any or all of the 3 dimensions. Now assuming you are building a binary bvh, this calls for a poor hierarchy. If we had a bvh with 7 child nodes per level, then we could perhaps assign a subtree for each of the walls and the the 7th to cover up the space inside those walls.
gallickgunner
<raytracing><bounding-volume-hierarchy>
BVH works fine, but why does it slow down a lot when using Cornell Box? How to improve it?
iaomw
# BVH works fine, but why does it slow down a lot when using Cornell Box? How to improve it?

(Asked by: username_0 on 2020-09-03)

I am using the SAH-BVH from PBRT-v3, it works fine for triangle-mesh, especially for dense mesh.

But here is a problem. If I added Cornell box while building the BVH tree, the BVH performance will drop to only 20% as before. The Cornell box is only 6 rectangles. Why does it behave in this way? Because it's a big box containing everything? How to improve it?

**Tags:** raytracing, bounding-volume-hierarchy

> **Comments:**
> **username_1**: How do you measure that performance drop exactly? There are many possible explanations and knowing this would help narrow it down to the more likely ones.  
> **username_0**: I am doing GPU ray tracing in shader. It will drop from 50+fps to 10-fps. @username_1  
> **username_1**: Does your screen go from mostly empty without the box to being filled by a cornell box? Or is the difference there no matter how you place the camera? Are you rendering only primary rays or some number of bounces?  
> **username_0**: The mesh takes 50% screen, the box will take 80% maybe. Yeah, it has max 32 bouncing number. @username_1  
> **username_2**: How big are the triangles of the box's walls? If you subdivide them 2 or 3 times, you'll notice an increase in performance but still not upto the original level. The walls will almost always lower the performance of the bvh as they are more a form of a container. You'll get faster performance by checking 12 triangles (assuming 2 per wall) separately instead of dumping them inside a bvh.  
> **username_2**: The thing is, usually you expand the BVH nodes after constructing it. So if the triangles are big, the nodes will expand and overlap a lot more decreasing the efficiency a lot.  
> **username_0**: The box is not using any triangles, it's a collection of rect. @username_2  
> **username_2**: @username_0 - sorry didn't understand. Do you mean you are doing ray-rectangle intersections in the leaf nodes? Even if that's the case, the point is if you expand the nodes after construction they'll overlap reducing the efficiency.  
> **username_0**: What do you mean by expand? @username_2  
> **username_2**: @username_0 - BVH is object subdivision not space, so there will be nodes that overlap. So after you construct the bvh you don't only expand but I guess the proper word would be "fit" (expand/shrink) the node to its contents.  
> **username_2**: I think I'm failing to express the key point here. Look at it this way. The key points to making efficient BVHs are, nodes should have minimal volumes, and pruning at the top level should prune the entire subtree of that child node. Now imagine a cornell box scene with a small teapot inside. If you try to dump the large walls inside the BVH these 2 points take a hit since dumping any wall to any node will make it expand it's width or height or both to that of the root Bounding node. So either you subdivide the walls or take them out of the bvh  
> **username_0**: So, it better to divide big shape into small triangles. But how small it should be? @username_2  
> **username_2**: @username_0 - They can be big, but not as big as the root container itself. Take the scenario of the cornell box. The cornell box itself is the root node so it's walls kinda form up the walls of the root node itself. So when you try to insert any of the walls in a child node the node expands to the size of the root node in any or all of the 3 dimensions. Now assuming you are building a binary bvh, this calls for a poor hierarchy. If we had a bvh with 7 child nodes per level, then we could perhaps assign a subtree for each of the walls and the the 7th to cover up the space inside those walls.  

---

## 0 answers

