torch-ngp icon indicating copy to clipboard operation
torch-ngp copied to clipboard

One question about march_rays

Open brabbitdousha opened this issue 2 years ago • 2 comments

In raymarching.cu,I checked the kernel_march_rays function,and found the rdx,rdy,rdz, what if dx,dy or dz is zero ? I believe that would happen certain times.

const float ox = rays_o[0], oy = rays_o[1], oz = rays_o[2];
   const float dx = rays_d[0], dy = rays_d[1], dz = rays_d[2];
   const float rdx = 1 / dx, rdy = 1 / dy, rdz = 1 / dz;

It's used when skipping a large step

else {
            // calc distance to next voxel
            const float tx = (((nx + 0.5f + 0.5f * signf(dx)) * rH * 2 - 1) * mip_bound - x) * rdx;
            const float ty = (((ny + 0.5f + 0.5f * signf(dy)) * rH * 2 - 1) * mip_bound - y) * rdy;
            const float tz = (((nz + 0.5f + 0.5f * signf(dz)) * rH * 2 - 1) * mip_bound - z) * rdz;
            const float tt = t + fmaxf(0.0f, fminf(tx, fminf(ty, tz)));
            // step until next voxel
            do { 
                t += clamp(t * dt_gamma, dt_min, dt_max);
            } while (t < tt);
        }

brabbitdousha avatar Feb 06 '23 12:02 brabbitdousha

@brabbitdousha Hi, you are right. In that case, rdx will be infinity, and ruled out in the later fminf, so the behaviour is still correct. But the best way is to add an eps, I'll update it later.

ashawkey avatar Feb 15 '23 04:02 ashawkey

Thanks for replying,I was thinking the return value would be undefined,but infinity will be fine.Any way,thanks for your amazing work : )

brabbitdousha avatar Feb 15 '23 13:02 brabbitdousha