kwea123 / nerf_pl

NeRF (Neural Radiance Fields) and NeRF in the Wild using pytorch-lightning
https://www.youtube.com/playlist?list=PLDV2CyUo4q-K02pNEyDr7DYpTQuka3mbV
MIT License
2.74k stars 483 forks source link

Why do you need transpose c2w to get rays_d? #43

Closed zhangjian94cn closed 4 years ago

zhangjian94cn commented 4 years ago

rays_d = directions @ c2w[:, :3].T # (H, W, 3) transpose c2w to make it row-major order?

kwea123 commented 4 years ago

since directions is (X, 3) (X can be multi-dimensional), normally if we want to multiply a 3x3 rotation matrix to the left we do:

R @ directions.T

but this gives a tensor of shape (3, X) which we need to transpose again. So finally what we want is

(R @ directions.T).T

which becomes

directions @ R.T

So the R.T is not actually multiplying the transpose of R, you know what I mean. This is a concise way for me if you understand this procedure.

zhangjian94cn commented 4 years ago

Thank you very much!