View source on GitHub |
Rasterization with differentiable occlusion using rasterize-then-splat.
tfg.rendering.splat.rasterize_then_splat(
vertices: type_alias.TensorLike,
triangles: type_alias.TensorLike,
attributes: Dict[str, type_alias.TensorLike],
view_projection_matrix: type_alias.TensorLike,
image_size: Tuple[int, int],
shading_function: Callable[[Dict[str, tf.Tensor]], tf.Tensor],
num_layers=1,
return_extra_buffers=False,
backend: enum.Enum = tfg.rendering.rasterization_backend.RasterizationBackends.CPU
,
name='rasterize_then_splat'
)
Rasterizes the input triangles to produce surface point samples, applies a user-specified shading function, then splats the shaded point samples onto the pixel grid.
The attributes are arbitrary per-vertex quantities (colors, normals, texture
coordinates, etc.). The rasterization step interpolates these attributes
across triangles to produce a dictionary of per-pixel interpolated attributes
buffers with shapes [H, W, K]
where K
is the number of channels of the
input attribute. This dictionary is passed to the user-provided
shading_function
, which performs shading and outputs a [H, W, 4]
buffer of RGBA colors. The result of the shader is replaced with (0,0,0,0) for
background pixels.
In the common case that the attributes are RGBA vertex colors, the shading
function may just pass the rasterized attributes through (i.e.,
shading_function = lambda x: x['color']
where color
is an RGBA attribute).
Returns | |
---|---|
a [A1, ..., An, H, W, 4] tensor of RGBA values.
|