MCPcopy Create free account
hub / github.com/NVlabs/InstantSplat / eval_sh

Function eval_sh

utils/sh_utils.py:57–112  ·  view source on GitHub ↗

Evaluate spherical harmonics at unit directions using hardcoded SH polynomials. Works with torch/np/jnp. ... Can be 0 or more batch dimensions. Args: deg: int SH deg. Currently, 0-3 supported sh: jnp.ndarray SH coeffs [..., C, (deg + 1) ** 2] dirs: jnp.nd

(deg, sh, dirs)

Source from the content-addressed store, hash-verified

55
56
57def eval_sh(deg, sh, dirs):
58 """
59 Evaluate spherical harmonics at unit directions
60 using hardcoded SH polynomials.
61 Works with torch/np/jnp.
62 ... Can be 0 or more batch dimensions.
63 Args:
64 deg: int SH deg. Currently, 0-3 supported
65 sh: jnp.ndarray SH coeffs [..., C, (deg + 1) ** 2]
66 dirs: jnp.ndarray unit directions [..., 3]
67 Returns:
68 [..., C]
69 """
70 assert deg <= 4 and deg >= 0
71 coeff = (deg + 1) ** 2
72 assert sh.shape[-1] >= coeff
73
74 result = C0 * sh[..., 0]
75 if deg > 0:
76 x, y, z = dirs[..., 0:1], dirs[..., 1:2], dirs[..., 2:3]
77 result = (result -
78 C1 * y * sh[..., 1] +
79 C1 * z * sh[..., 2] -
80 C1 * x * sh[..., 3])
81
82 if deg > 1:
83 xx, yy, zz = x * x, y * y, z * z
84 xy, yz, xz = x * y, y * z, x * z
85 result = (result +
86 C2[0] * xy * sh[..., 4] +
87 C2[1] * yz * sh[..., 5] +
88 C2[2] * (2.0 * zz - xx - yy) * sh[..., 6] +
89 C2[3] * xz * sh[..., 7] +
90 C2[4] * (xx - yy) * sh[..., 8])
91
92 if deg > 2:
93 result = (result +
94 C3[0] * y * (3 * xx - yy) * sh[..., 9] +
95 C3[1] * xy * z * sh[..., 10] +
96 C3[2] * y * (4 * zz - xx - yy)* sh[..., 11] +
97 C3[3] * z * (2 * zz - 3 * xx - 3 * yy) * sh[..., 12] +
98 C3[4] * x * (4 * zz - xx - yy) * sh[..., 13] +
99 C3[5] * z * (xx - yy) * sh[..., 14] +
100 C3[6] * x * (xx - 3 * yy) * sh[..., 15])
101
102 if deg > 3:
103 result = (result + C4[0] * xy * (xx - yy) * sh[..., 16] +
104 C4[1] * yz * (3 * xx - yy) * sh[..., 17] +
105 C4[2] * xy * (7 * zz - 1) * sh[..., 18] +
106 C4[3] * yz * (7 * zz - 3) * sh[..., 19] +
107 C4[4] * (zz * (35 * zz - 30) + 3) * sh[..., 20] +
108 C4[5] * xz * (7 * zz - 3) * sh[..., 21] +
109 C4[6] * (xx - yy) * (7 * zz - 1) * sh[..., 22] +
110 C4[7] * xz * (xx - 3 * yy) * sh[..., 23] +
111 C4[8] * (xx * (xx - 3 * yy) - yy * (3 * xx - yy)) * sh[..., 24])
112 return result
113
114def RGB2SH(rgb):

Callers 2

renderFunction · 0.90
renderFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected