dilevin / computer-graphics-bounding-volume-hierarchy

Computer Graphics Assignment about Bounding Volume Hierarchies
6 stars 5 forks source link

Confusion regarding the ray box intersection #65

Open junior-stack opened 9 months ago

junior-stack commented 9 months ago

By reading the description of function ray_intersect_box, I am not sure how I can check if the ray hits something inside a box. Based on the description of AABB tree, I assume the bounding box partitions the list of objects in the scene. In that case, I assume the bounding box will store a list of leaf objects or internal node objects(other bounding boxes) in its class field. However, after I check the BoundingBox.h, I found it only contains the max_corner and min_corner, even in the insert_box_into_box, we are just modifying the box's corner cordinate instead of storing one box into another box. So I am a little confused how I can access the bounding boxes or objects that is inside a bounding box called A. Do I loop through all the bounding boxes in the scene and compare the max and min corners with the max and min corners to check if each box is in A?

Zhecheng-Wang commented 9 months ago

Indeed, BoundingBox.h only contains the geometry information of the box.

You are referring to the AABBTree class that defines the basic building component of AABB. Every AABBTree node contains a left subtree and a right subtree, and is inherited from Object struct that contains a BoundingBox. See code here.

junior-stack commented 9 months ago

Yes, I have seen this code. So my question is we are given only the geometry information of the box in ray_intersect_box, how do we determine the AABBTree node Object in the child node of the box? I don't quite understand this logic

Zhecheng-Wang commented 9 months ago

For ray_intersect_box, it is just checking one ray intersecting with one (geometric) box, so it can't do what you just described. I think you are thinking about a recursive function that checks ray intersection with a box and its subtree nodes? That would be AABBTree::ray_intersect.

junior-stack commented 9 months ago

So if I just check the box that is passed to this function, what does the sentence in the bracket "careful: if the ray or min_t lands inside the box this could still hit something stored inside the box, so this counts as a hit" mean? I thought it also needs to check ray intersection between the box inside the box that is passed to the function and ray?

Zhecheng-Wang commented 9 months ago

That's referring to the case if someone is doing a ray-box intersection as if the box is a surface-only geometry (hollow inside so rays stopped inside don't "hit"). We want a ray-volumetric box intersection check. As you have seen, there is no further information that can help you deduce subtree information from the BoundingBox class.