MCPcopy
hub / github.com/zju3dv/4K4D / eval_sh

Function eval_sh

easyvolcap/utils/sh_utils.py:643–727  ·  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.n

(deg: int, sh: torch.Tensor, dirs: torch.Tensor)

Source from the content-addressed store, hash-verified

641
642@torch.jit.script
643def eval_sh(deg: int, sh: torch.Tensor, dirs: torch.Tensor):
644 """
645 Evaluate spherical harmonics at unit directions
646 using hardcoded SH polynomials.
647 Works with torch/np/jnp.
648 ... Can be 0 or more batch dimensions.
649
650 Args:
651 deg: int SH deg. Currently, 0-3 supported
652 sh: jnp.ndarray SH coeffs [..., C, (deg + 1) ** 2]
653 dirs: jnp.ndarray unit directions [..., 3]
654
655 Returns:
656 [..., C]
657 """
658 C0 = 0.28209479177387814
659 C1 = 0.4886025119029199
660 C2 = [
661 1.0925484305920792,
662 -1.0925484305920792,
663 0.31539156525252005,
664 -1.0925484305920792,
665 0.5462742152960396
666 ]
667 C3 = [
668 -0.5900435899266435,
669 2.890611442640554,
670 -0.4570457994644658,
671 0.3731763325901154,
672 -0.4570457994644658,
673 1.445305721320277,
674 -0.5900435899266435
675 ]
676 C4 = [
677 2.5033429417967046,
678 -1.7701307697799304,
679 0.9461746957575601,
680 -0.6690465435572892,
681 0.10578554691520431,
682 -0.6690465435572892,
683 0.47308734787878004,
684 -1.7701307697799304,
685 0.6258357354491761,
686 ]
687
688 assert deg <= 4 and deg >= 0
689 assert (deg + 1) ** 2 == sh.shape[-1]
690 C = sh.shape[-2]
691
692 result = C0 * sh[..., 0]
693 if deg > 0:
694 x, y, z = dirs[..., 0:1], dirs[..., 1:2], dirs[..., 2:3]
695 result = (result -
696 C1 * y * sh[..., 1] +
697 C1 * z * sh[..., 2] -
698 C1 * x * sh[..., 3])
699 if deg > 1:
700 xx, yy, zz = x * x, y * y, z * z

Callers 6

renderFunction · 0.90
naive_renderFunction · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
get_rgbMethod · 0.90
sh_utils.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected