Render the scene. Background tensor (bg_color) must be on GPU!
(viewpoint_camera, pc : GaussianModel, pipe, bg_color : torch.Tensor, scaling_modifier = 1.0, override_color = None)
| 17 | from utils.sh_utils import eval_sh, eval_shfs_4d |
| 18 | |
| 19 | def render(viewpoint_camera, pc : GaussianModel, pipe, bg_color : torch.Tensor, scaling_modifier = 1.0, override_color = None): |
| 20 | """ |
| 21 | Render the scene. |
| 22 | |
| 23 | Background tensor (bg_color) must be on GPU! |
| 24 | """ |
| 25 | |
| 26 | # Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means |
| 27 | screenspace_points = torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda") + 0 |
| 28 | try: |
| 29 | screenspace_points.retain_grad() |
| 30 | except: |
| 31 | pass |
| 32 | |
| 33 | # Set up rasterization configuration |
| 34 | tanfovx = math.tan(viewpoint_camera.FoVx * 0.5) |
| 35 | tanfovy = math.tan(viewpoint_camera.FoVy * 0.5) |
| 36 | |
| 37 | raster_settings = GaussianRasterizationSettings( |
| 38 | image_height=int(viewpoint_camera.image_height), |
| 39 | image_width=int(viewpoint_camera.image_width), |
| 40 | tanfovx=tanfovx, |
| 41 | tanfovy=tanfovy, |
| 42 | bg=bg_color if not pipe.env_map_res else torch.zeros(3, device="cuda"), |
| 43 | scale_modifier=scaling_modifier, |
| 44 | viewmatrix=viewpoint_camera.world_view_transform, |
| 45 | projmatrix=viewpoint_camera.full_proj_transform, |
| 46 | sh_degree=pc.active_sh_degree, |
| 47 | sh_degree_t=pc.active_sh_degree_t, |
| 48 | campos=viewpoint_camera.camera_center, |
| 49 | timestamp=viewpoint_camera.timestamp, |
| 50 | time_duration=pc.time_duration[1]-pc.time_duration[0], |
| 51 | rot_4d=pc.rot_4d, |
| 52 | gaussian_dim=pc.gaussian_dim, |
| 53 | force_sh_3d=pc.force_sh_3d, |
| 54 | prefiltered=False, |
| 55 | debug=pipe.debug |
| 56 | ) |
| 57 | |
| 58 | rasterizer = GaussianRasterizer(raster_settings=raster_settings) |
| 59 | |
| 60 | means3D = pc.get_xyz |
| 61 | means2D = screenspace_points |
| 62 | opacity = pc.get_opacity |
| 63 | |
| 64 | # If precomputed 3d covariance is provided, use it. If not, then it will be computed from |
| 65 | # scaling / rotation by the rasterizer. |
| 66 | scales = None |
| 67 | scales_t = None |
| 68 | rotations = None |
| 69 | rotations_r = None |
| 70 | ts = None |
| 71 | cov3D_precomp = None |
| 72 | if pipe.compute_cov3D_python: |
| 73 | if pc.rot_4d: |
| 74 | cov3D_precomp, delta_mean = pc.get_current_covariance_and_mean_offset(scaling_modifier, viewpoint_camera.timestamp) |
| 75 | means3D = means3D + delta_mean |
| 76 | else: |
no test coverage detected