# tfg.rendering.barycentrics.differentiable_barycentrics

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/rendering/barycentrics.py#L25-L127) |

Computes differentiable barycentric coordinates from a Framebuffer.

    tfg.rendering.barycentrics.differentiable_barycentrics(
        framebuffer: https://www.tensorflow.org/graphics/api_docs/python/tfg/rendering/framebuffer/Framebuffer,
        clip_space_vertices: type_alias.TensorLike,
        triangles: type_alias.TensorLike,
        use_vectorized_map: bool = True
    ) -> https://www.tensorflow.org/graphics/api_docs/python/tfg/rendering/framebuffer/Framebuffer

The barycentric coordinates will be differentiable w.r.t. the input vertices.
Later, we may support derivatives w.r.t. pixel position for mip-mapping.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `framebuffer` | a multi-layer Framebuffer containing triangle ids and a foreground mask with shape \[batch, num_layers, height, width, 1\] |
| `clip_space_vertices` | a 2-D float32 tensor with shape \[vertex_count, 4\] or a 3-D tensor with shape \[batch, vertex_count, 4\] containing homogenous vertex positions (xyzw). |
| `triangles` | a 2-D int32 tensor with shape \[triangle_count, 3\] or a 3-D tensor with shape \[batch, triangle_count, 3\] containing per-triangle vertex indices in counter-clockwise order. |
| `use_vectorized_map` | If true uses vectorized_map otherwise uses map_fn. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| a copy of `framebuffer`, but the differentiable barycentric coordinates will replace any barycentric coordinates already in the `framebuffer`. ||

<br />