ashawkey / torch-ngp

A pytorch CUDA extension implementation of instant-ngp (sdf and nerf), with a GUI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

One question about march_rays

brabbitdousha opened this issue · 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);
        }
commented

@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.

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