dilevin / computer-graphics-bounding-volume-hierarchy

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

how to handle the case when ray box intersection returns negative t value #87

Open junior-stack opened 8 months ago

junior-stack commented 8 months ago

For ray_intersect_box, when we compute negative txmin, tymix, tzmin using the method from textbook p302, do we return false in this function? Also, suppose the ray origin lies in the inside of the box, this could potentially lead to negative txmin or tymin or tzmin, do we also return false in this case?

Zhecheng-Wang commented 8 months ago

35. Yes and yes when considering default bound min_t = 0.

junior-stack commented 8 months ago

That confuses me because I think when the ray origin lies inside the box, we sometimes need to have ray_intersect_box returns true, even through this lead to negative txmin, tymin and tzmin. Consider the case when the ray origin lies inside the box of the root of AABB Tree Node

Zhecheng-Wang commented 8 months ago

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

you are right, for rays inside a box it should count as a hit.

junior-stack commented 8 months ago

So in this case, we have negative txmin but we return true. In conclusion, we should first check if ray origin is inside the box and if so, we return true. If not, we compute tvalues and compare it with the min_t and max_t?

Zhecheng-Wang commented 8 months ago

Also, suppose the ray origin lies in the inside of the box, this could potentially lead to negative txmin or tymin or tzmin, do we also return false in this case?

Actually, why would a ray inside a box return negative t? Given the box is solid, wouldn't t = 0?

If not, we compute tvalues and compare it with the min_t and max_t?

Yes.

junior-stack commented 8 months ago

The way I calculate t is based of the formula of the textbook, which is (xmin - xe) / xd. As you can imagine, if the ray origin lies inside the box, it would give me a negative value and thus the whole function return false

Zhecheng-Wang commented 8 months ago

pg. 299 algorithm doesn't show the case where the ray is inside a box -- if the box is solid, then the ray inside a box gives t_min = 0 and t_max = 0. Consider Figure. 12.24, with the ray origin in the solid box, the interval shrinks to a point on the real line.

Of course, consider this case as a special case is fine.