| 111 | |
| 112 | |
| 113 | def convert_SH( |
| 114 | shs_view, |
| 115 | viewpoint_camera, |
| 116 | pc: GaussianModel, |
| 117 | position: torch.tensor, |
| 118 | rotation: torch.tensor = None, |
| 119 | ): |
| 120 | shs_view = shs_view.transpose(1, 2).view(-1, 3, (pc.max_sh_degree + 1) ** 2) |
| 121 | dir_pp = position - viewpoint_camera.camera_center.repeat(shs_view.shape[0], 1) |
| 122 | if rotation is not None: |
| 123 | n = rotation.shape[0] |
| 124 | dir_pp[:n] = torch.matmul(rotation, dir_pp[:n].unsqueeze(2)).squeeze(2) |
| 125 | |
| 126 | dir_pp_normalized = dir_pp / dir_pp.norm(dim=1, keepdim=True) |
| 127 | sh2rgb = eval_sh(pc.active_sh_degree, shs_view, dir_pp_normalized) |
| 128 | colors_precomp = torch.clamp_min(sh2rgb + 0.5, 0.0) |
| 129 | |
| 130 | return colors_precomp |