|
Post by poster on Jan 12, 2021 20:36:00 GMT
Not sure where I am going awry here. I am working in the bonus chapter for the bounding boxes and BVH, and all the tests are passing. However, calling divide on a triangle shape does not result in any kind of speedup. Even a scene with a teapot is no faster, let alone the dragon image. What threshold values should I be using here? Is calling divide not enough, perhaps?
|
|
|
Post by inventordave on Jan 13, 2021 20:19:05 GMT
I have been away from the raytracer for a while, and I'm a bit of an idiot at the best of times, but I assume your BVH generator code utilises a variable that defines how many individual shapes aggregated together the algorithm will store in a single subdivision (leaf bounding box in the BVH data structure). For example, in my raytracer implementation with BVH implemented, I have a global that includes a member variable "divideValue" that by default I have assigned the value 500 (for a structure such as a teapot - I assume you're using the standard mesh file - this is a reasonable number). This means that a leaf bounding box in the generated BVH structure contains 500 triangles from the mesh.
I am going to guess your equivalent defined value may not be set to a suitable value (maybe it's not set, or it's set to a really low number, ~1).
I cannot see your codebase, so I dont know anything about how you implemented the BVH algorithm, but if all the tests are definitely passing, it seems very likely the error in your scene configuration is that you havent set a reasonable value for the number of triangles in each leaf box of the BVH data structure.
Maybe I'm a complete idiot, but without having access to your code, that's the most obvious place to look.
|
|
|
Post by poster on Jan 15, 2021 13:18:15 GMT
Actually, that is helpful. I will play around with those values you mentioned further and see what I get.
|
|
|
Post by jdunlap on Jan 25, 2021 5:47:51 GMT
In order to help you determine this, make sure that you are timing the render only. If you include the overall time, including dividing the triangles, you may not see an overall increase. If you separate the timing of the render, though, you may find that the render is faster, but too low of a threshold is causing the division of the triangles to take a long time. Look at these timings separately to find a good threshold value that balances the two.
|
|
cmo
New Member
Posts: 6
|
Post by cmo on Feb 6, 2021 2:32:46 GMT
I didn't have much speed up from the BVH either. I ran a profiler against my code, and the problem was my implementation. Specifically this bit of psuedo from the bonus chapter:
function bounds_of(group) let box ← bounding_box(empty)
for each child of group let cbox ← parent_space_bounds_of(child) add cbox to box end for
return box end function
That 'parent_space_bounds_of' function does a lot of matrix multiplication (8 in total, one for each vertex of the cube). And this code was getting called everytime a group intersection needed checked.
So I changed it to calculate once and store the value. That led to a pretty serious speedup, and everything seems to work ok still. The psuedo code would look something like:
function bounds_of(group)
if group.box != null return group.box end if let box ← bounding_box(empty)
for each child of group let cbox ← parent_space_bounds_of(child) add cbox to box end for
group.box = box
return box end function Hope that helps!
-C
|
|
|
Post by jaredp on Feb 11, 2021 19:29:57 GMT
That 'parent_space_bounds_of' function does a lot of matrix multiplication (8 in total, one for each vertex of the cube). And this code was getting called everytime a group intersection needed checked. This was exactly what I ran into as well. It took a bit of head scratching before I realized it. Having to recursively get the parent bounds for each child is going to take forever. My solution was to just store a bounding box in my Group object and update it when adding a child to the group (and walk the parent chain to update the bounds on each parent as well). That way, your Group's intersect function just has to call intersect on its local bounding box.
|
|