utils

pypbr.utils

This module provides utility functions for color space conversions between sRGB and linear space. These functions are used in Physically Based Rendering (PBR) pipelines to ensure correct color representation during material rendering and shading computations.

Functions:

srgb_to_linear: Converts an sRGB texture to linear space.

linear_to_srgb: Converts a linear texture to sRGB space.

rotate_normals: Rotates the normals in a normal map by a given angle.

invert_normal: Inverts the Y component of the normal map.

compute_normal_from_height: Computes the normal map from a height map.

compute_height_from_normal: Computes the height map from a normal map.

pypbr.utils.compute_height_from_normal(normal_map: FloatTensor, scale: float = 1.0) FloatTensor[source]

Compute the height map from the normal map using Poisson reconstruction.

Parameters:

scale (float) – Scaling factor for the gradients.

Returns:

Returns self for method chaining.

Return type:

MaterialBase

pypbr.utils.compute_normal_from_height(height_map: FloatTensor, scale: float = 1.0) FloatTensor[source]

Compute the normal map from the height map.

Parameters:
  • height_map (torch.FloatTensor) – The height map tensor.

  • scale (float) – The scaling factor for the height map gradients. Controls the strength of the normals.

Returns:

The normal map tensor.

Return type:

torch.FloatTensor

pypbr.utils.invert_normal(normals: FloatTensor) FloatTensor[source]

Invert the Y component of the normal map. The normal map should be normalized.

Returns:

The inverted normal map.

Return type:

torch.FloatTensor

pypbr.utils.linear_to_srgb(texture: Tensor) Tensor[source]

Convert a linear texture to sRGB space.

Parameters:

texture (torch.Tensor) – The linear texture of shape (…, C, H, W).

Returns:

The texture in sRGB space.

Return type:

torch.Tensor

pypbr.utils.rotate_normals(normal_map: FloatTensor, angle: float) FloatTensor[source]

Rotate the normals in the normal map by the given angle.

Parameters:
  • normal_map (torch.FloatTensor) – The normal map tensor.

  • angle (float) – The rotation angle in degrees.

Returns:

The adjusted normal map.

Return type:

torch.FloatTensor

pypbr.utils.srgb_to_linear(texture: Tensor) Tensor[source]

Convert an sRGB texture to linear space.

Parameters:

texture (torch.Tensor) – The sRGB texture of shape (…, C, H, W).

Returns:

The texture in linear space.

Return type:

torch.Tensor