def create_lights(opt_renderer_texture_lights): """ Create lights specified by opt, if no sun or point lights are given, create the tri-color lights. Currently only supports the same lights for all batches """ from DSS.core.lighting import (DirectionalLights, PointLights) ambient_color = torch.tensor( opt_renderer_texture_lights.ambient_color).view(1, -1, 3) specular_color = torch.tensor( opt_renderer_texture_lights.specular_color).view(1, -1, 3) diffuse_color = torch.tensor( opt_renderer_texture_lights.diffuse_color).view(1, -1, 3) if opt_renderer_texture_lights['type'] == "sun": direction = torch.tensor(opt_renderer_texture_lights.direction).view( 1, -1, 3) lights = DirectionalLights(ambient_color=ambient_color, diffuse_color=diffuse_color, specular_color=specular_color, direction=direction) elif opt_renderer_texture_lights['type'] == 'point': location = torch.tensor(opt_renderer_texture_lights.location).view( 1, -1, 3) lights = PointLights(ambient_color=ambient_color, diffuse_color=diffuse_color, specular_color=specular_color, location=location) return lights
def get_light_for_view(cams, has_specular): # create tri-color lights and a specular+diffuse shader ambient_color = torch.FloatTensor((((0.6, 0.6, 0.6), ), )) diffuse_color = torch.FloatTensor((((0.2, 0.2, 0.2), ), )) if opt.has_specular: specular_color = 0.15 * diffuse_color diffuse_color *= 0.85 else: specular_color = (((0, 0, 0), ), ) elev = torch.FloatTensor(((random.randint(10, 90), ), )) azim = torch.FloatTensor(((random.randint(0, 360)), )) elev = math.pi / 180.0 * elev azim = math.pi / 180.0 * azim x = torch.cos(elev) * torch.sin(azim) y = torch.sin(elev) z = torch.cos(elev) * torch.cos(azim) light_directions = torch.stack([x, y, z], dim=-1) # transform from camera to world light_directions = cams.get_world_to_view_transform().inverse( ).transform_points(light_directions) if not point_lights: lights = DirectionalLights(ambient_color=ambient_color, diffuse_color=diffuse_color, specular_color=specular_color, direction=light_directions) else: location = light_directions * 5 lights = PointLights(ambient_color=ambient_color, diffuse_color=diffuse_color, specular_color=specular_color, location=location) return lights
def get_tri_color_lights_for_view(cams, has_specular=False, point_lights=True): """ Create RGB lights direction in the half dome The direction is given in the same coordinates as the pointcloud Args: cams Returns: Lights with three RGB light sources (B: right, G: left, R: bottom) """ import math from DSS.core.lighting import (DirectionalLights, PointLights) from pytorch3d.renderer.cameras import look_at_rotation from pytorch3d.transforms import Rotate elev = torch.tensor(((30, 30, 30), ), device=cams.device) azim = torch.tensor(((-60, 60, 180), ), device=cams.device) elev = math.pi / 180.0 * elev azim = math.pi / 180.0 * azim x = torch.cos(elev) * torch.sin(azim) y = torch.sin(elev) z = torch.cos(elev) * torch.cos(azim) light_directions = torch.stack([x, y, z], dim=-1) cam_pos = cams.get_camera_center() R = look_at_rotation(torch.zeros_like(cam_pos), at=F.normalize(torch.cross(cam_pos, torch.rand_like(cam_pos)), dim=-1), up=cam_pos) light_directions = Rotate(R=R.transpose( 1, 2), device=cams.device).transform_points(light_directions) # trimesh.Trimesh(vertices=torch.cat([cam_pos, light_directions[0]], dim=0).cpu().numpy(), process=False).export('tests/outputs/light_dir.ply') ambient_color = torch.FloatTensor((((0.2, 0.2, 0.2), ), )) diffuse_color = torch.FloatTensor((( (0.0, 0.0, 0.8), (0.0, 0.8, 0.0), (0.8, 0.0, 0.0), ), )) if has_specular: specular_color = 0.15 * diffuse_color diffuse_color *= 0.85 else: specular_color = (( (0, 0, 0), (0, 0, 0), (0, 0, 0), ), ) if not point_lights: lights = DirectionalLights(ambient_color=ambient_color, diffuse_color=diffuse_color, specular_color=specular_color, direction=light_directions) else: location = light_directions * 5 lights = PointLights(ambient_color=ambient_color, diffuse_color=diffuse_color, specular_color=specular_color, location=location) return lights
# Refer to raster_points.py for explanations of these parameters. raster_settings = RasterizationSettings( image_size=opt.image_size, blur_radius=0.0, faces_per_pixel=5, # this setting controls whether naive or coarse-to-fine rasterization is used bin_size=None, max_faces_per_bin=None # this setting is for coarse rasterization ) renderer = MeshRenderer( rasterizer=MeshRasterizer(raster_settings=raster_settings), shader=HardFlatShader(device=device)) if opt.point_lights: template_lights = PointLights() else: template_lights = DirectionalLights() # pcl_dict = {'points': pointclouds.points_padded[0].cpu().numpy()} data_dict = { "cameras_type": '.'.join([ camera_sampler.camera_type.__module__, camera_sampler.camera_type.__name__ ]), "cameras_params": camera_params, "lights_type": '.'.join([ template_lights.__module__, template_lights.__class__.__name__