sxyu / svox2

Plenoxels: Radiance Fields without Neural Networks
BSD 2-Clause "Simplified" License
2.83k stars 360 forks source link

how to get zdepth in cuda code? #95

Open zhw-github opened 2 years ago

zhw-github commented 2 years ago

Hi, I have one question after reading the code. In svox2.py file,you define a volume_render_depth function?Then the note below says this is the absolute length along the ray, not the z-depth as usually expected.But how can i get the zdepth with changing you code. I think that this code is the key: while (t <= ray.tmax) {

pragma unroll 3

    for (int j = 0; j < 3; ++j) {
        ray.pos[j] = fmaf(t, ray.dir[j], ray.origin[j]);
        ray.pos[j] = min(max(ray.pos[j], 0.f), grid.size[j] - 1.f);
        ray.l[j] = min(static_cast<int32_t>(ray.pos[j]), grid.size[j] - 2);
        ray.pos[j] -= static_cast<float>(ray.l[j]);
    }

what does t and pos mean?

sxyu commented 1 year ago

Hi, converting length to Z-depth can be easily done in python. You can divide by the length of the ray for pixel (x, y) in {0, ... w-1} x {0, ... h-1}

X = (x+0.5-cx)/fx
Y = (y+0.5-cy)/fy
Z = 1
z_depth = length * 1/sqrt(X**2 + Y**2 + Z**2)