shader

class pytorch3d.renderer.mesh.shader.HardPhongShader(device: Union[str, torch.device] = 'cpu', cameras: Optional[pytorch3d.renderer.utils.TensorProperties] = None, lights: Optional[pytorch3d.renderer.utils.TensorProperties] = None, materials: Optional[pytorch3d.renderer.materials.Materials] = None, blend_params: Optional[pytorch3d.renderer.blending.BlendParams] = None)[source]

Per pixel lighting - the lighting model is applied using the interpolated coordinates and normals for each pixel. The blending function hard assigns the color of the closest face for each pixel.

To use the default values, simply initialize the shader with the desired device e.g.

to(device: Union[str, torch.device])[source]
forward(fragments: pytorch3d.renderer.mesh.rasterizer.Fragments, meshes: pytorch3d.structures.meshes.Meshes, **kwargs) → torch.Tensor[source]
class pytorch3d.renderer.mesh.shader.SoftPhongShader(device: Union[str, torch.device] = 'cpu', cameras: Optional[pytorch3d.renderer.utils.TensorProperties] = None, lights: Optional[pytorch3d.renderer.utils.TensorProperties] = None, materials: Optional[pytorch3d.renderer.materials.Materials] = None, blend_params: Optional[pytorch3d.renderer.blending.BlendParams] = None)[source]

Per pixel lighting - the lighting model is applied using the interpolated coordinates and normals for each pixel. The blending function returns the soft aggregated color using all the faces per pixel.

To use the default values, simply initialize the shader with the desired device e.g.

to(device: Union[str, torch.device])[source]
forward(fragments: pytorch3d.renderer.mesh.rasterizer.Fragments, meshes: pytorch3d.structures.meshes.Meshes, **kwargs) → torch.Tensor[source]
class pytorch3d.renderer.mesh.shader.HardGouraudShader(device: Union[str, torch.device] = 'cpu', cameras: Optional[pytorch3d.renderer.utils.TensorProperties] = None, lights: Optional[pytorch3d.renderer.utils.TensorProperties] = None, materials: Optional[pytorch3d.renderer.materials.Materials] = None, blend_params: Optional[pytorch3d.renderer.blending.BlendParams] = None)[source]

Per vertex lighting - the lighting model is applied to the vertex colors and the colors are then interpolated using the barycentric coordinates to obtain the colors for each pixel. The blending function hard assigns the color of the closest face for each pixel.

To use the default values, simply initialize the shader with the desired device e.g.

to(device: Union[str, torch.device])[source]
forward(fragments: pytorch3d.renderer.mesh.rasterizer.Fragments, meshes: pytorch3d.structures.meshes.Meshes, **kwargs) → torch.Tensor[source]
class pytorch3d.renderer.mesh.shader.SoftGouraudShader(device: Union[str, torch.device] = 'cpu', cameras: Optional[pytorch3d.renderer.utils.TensorProperties] = None, lights: Optional[pytorch3d.renderer.utils.TensorProperties] = None, materials: Optional[pytorch3d.renderer.materials.Materials] = None, blend_params: Optional[pytorch3d.renderer.blending.BlendParams] = None)[source]

Per vertex lighting - the lighting model is applied to the vertex colors and the colors are then interpolated using the barycentric coordinates to obtain the colors for each pixel. The blending function returns the soft aggregated color using all the faces per pixel.

To use the default values, simply initialize the shader with the desired device e.g.

to(device: Union[str, torch.device])[source]
forward(fragments: pytorch3d.renderer.mesh.rasterizer.Fragments, meshes: pytorch3d.structures.meshes.Meshes, **kwargs) → torch.Tensor[source]
pytorch3d.renderer.mesh.shader.TexturedSoftPhongShader(device: Union[str, torch.device] = 'cpu', cameras: Optional[pytorch3d.renderer.utils.TensorProperties] = None, lights: Optional[pytorch3d.renderer.utils.TensorProperties] = None, materials: Optional[pytorch3d.renderer.materials.Materials] = None, blend_params: Optional[pytorch3d.renderer.blending.BlendParams] = None)[source]

TexturedSoftPhongShader class has been DEPRECATED. Use SoftPhongShader instead. Preserving TexturedSoftPhongShader as a function for backwards compatibility.

class pytorch3d.renderer.mesh.shader.HardFlatShader(device: Union[str, torch.device] = 'cpu', cameras: Optional[pytorch3d.renderer.utils.TensorProperties] = None, lights: Optional[pytorch3d.renderer.utils.TensorProperties] = None, materials: Optional[pytorch3d.renderer.materials.Materials] = None, blend_params: Optional[pytorch3d.renderer.blending.BlendParams] = None)[source]

Per face lighting - the lighting model is applied using the average face position and the face normal. The blending function hard assigns the color of the closest face for each pixel.

To use the default values, simply initialize the shader with the desired device e.g.

to(device: Union[str, torch.device])[source]
forward(fragments: pytorch3d.renderer.mesh.rasterizer.Fragments, meshes: pytorch3d.structures.meshes.Meshes, **kwargs) → torch.Tensor[source]
class pytorch3d.renderer.mesh.shader.SoftSilhouetteShader(blend_params: Optional[pytorch3d.renderer.blending.BlendParams] = None)[source]

Calculate the silhouette by blending the top K faces for each pixel based on the 2d euclidean distance of the center of the pixel to the mesh face.

Use this shader for generating silhouettes similar to SoftRasterizer [0].

Note

To be consistent with SoftRasterizer, initialize the RasterizationSettings for the rasterizer with blur_radius = np.log(1. / 1e-4 - 1.) * blend_params.sigma

[0] Liu et al, ‘Soft Rasterizer: A Differentiable Renderer for Image-based
3D Reasoning’, ICCV 2019
forward(fragments: pytorch3d.renderer.mesh.rasterizer.Fragments, meshes: pytorch3d.structures.meshes.Meshes, **kwargs) → torch.Tensor[source]

Only want to render the silhouette so RGB values can be ones. There is no need for lighting or texturing