MCPcopy Create free account
hub / github.com/LeapLabTHU/ActiveNeRF / ndc_rays

Function ndc_rays

run_nerf_helpers.py:184–201  ·  view source on GitHub ↗
(H, W, focal, near, rays_o, rays_d)

Source from the content-addressed store, hash-verified

182
183
184def ndc_rays(H, W, focal, near, rays_o, rays_d):
185 # Shift ray origins to near plane
186 t = -(near + rays_o[...,2]) / rays_d[...,2]
187 rays_o = rays_o + t[...,None] * rays_d
188
189 # Projection
190 o0 = -1./(W/(2.*focal)) * rays_o[...,0] / rays_o[...,2]
191 o1 = -1./(H/(2.*focal)) * rays_o[...,1] / rays_o[...,2]
192 o2 = 1. + 2. * near / rays_o[...,2]
193
194 d0 = -1./(W/(2.*focal)) * (rays_d[...,0]/rays_d[...,2] - rays_o[...,0]/rays_o[...,2])
195 d1 = -1./(H/(2.*focal)) * (rays_d[...,1]/rays_d[...,2] - rays_o[...,1]/rays_o[...,2])
196 d2 = -2. * near / rays_o[...,2]
197
198 rays_o = torch.stack([o0,o1,o2], -1)
199 rays_d = torch.stack([d0,d1,d2], -1)
200
201 return rays_o, rays_d
202
203
204# Hierarchical sampling (section 5.2)

Callers 1

renderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected