TensoRF icon indicating copy to clipboard operation
TensoRF copied to clipboard

Non-NDC Ray Sampling Logic

Open ayush29feb opened this issue 2 years ago • 1 comments

Hey, I am trying to understand this piece of code here. Would you mind explaining what exactly its trying to compute? What is rate_a/b & t_min. I might be rusty of on 3D geom

https://github.com/apchenstu/TensoRF/blob/main/models/tensorBase.py#L281-L284

ayush29feb avatar Jun 24 '22 07:06 ayush29feb

Hi @ayush29feb - I was just reading into that function also, so I'll try to lend my current understanding here related to the math:

  1. Re: your second question - rate_a and rate_b are the distances between sampled points on 2 separate rays. Specifically, the rays that go from each rays_o to the aabb[0] (aka the min_xyz, or the bottom-left corner of the axis-aligned bounding box) and aabb[1] (which conversely is the max_xyz point in the aabb) respectively.

  2. Re: t_min: so both rate_a and rate_b tell us the number of sampled points on each of the rays (I like to think of them as the number of "steps" we take along that ray).

  3. Then we take the element-wise minimum() of these two, which I think represents for each ray, along each of the xyz axes, it stores what was the least amount of steps needed to get inside the bounding box.

  4. Finally it calls amax() and passes -1 for the dim - so now it's just like the tensor before, but we're only taking the largest number of steps that was needed along any of the xyz axes (again, this is for when each ray first enters the bbox).

Hope this is helpful!

UPstartDeveloper avatar Jun 25 '22 20:06 UPstartDeveloper

The lines that you mentioned are used to filter rays that do not intersect the aabb. Here is a link with more details: https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection

mrmouss avatar Aug 12 '22 15:08 mrmouss

Sorry for opening this one, but I have a slightly related question to this non-ndc sampling logic: Is there a reason why you are using stepsize*(torch.arange(N_samples) + some noise) starting from bbox edge t_min (lines https://github.com/apchenstu/TensoRF/blob/main/models/tensorBase.py#L288-L293), instead of sampling in a (near,far) range as you did for sample_ray_ndc with linspace?

In this way, if I am not mistaken, you have a tradeoff between N_samples vs stepsize to cover whole bbox range (i.e. you need a lot of N_samples to cover full bbox if stepsize is really small)?

dsvilarkovic avatar Sep 09 '22 14:09 dsvilarkovic