blending

pypbr.blending

This module provides a set of classes and functions for blending Physically Based Rendering (PBR) materials in different ways. The blending can be done using masks, height maps, properties, or gradients, and can be applied through both class-based and functional approaches.

Contents:
  • Classes: Object-oriented blending methods.

  • Functional API: Function-based blending utilities for quick use.

Classes

The following classes are available for blending operations:

BlendFactory

Factory class to instantiate blending methods.

BlendMethod

Abstract base class for different blending methods.

MaskBlend

Blend two materials using a provided mask.

HeightBlend

Blend two materials based on their height maps.

PropertyBlend

Blend two materials based on a specified property map.

GradientBlend

Blend two materials using a linear gradient mask.

Functional API

pypbr.blending.functional

This module provides functional interfaces for blending PBR materials using various methodologies.

Functions:

blend_materials: Blend two materials together using the specified method.

blend_with_mask: Blend two materials using a provided mask.

blend_on_height: Blend two materials based on their height maps.

blend_on_properties: Blend two materials based on a specified property map.

blend_with_gradient: Blend two materials using a linear gradient mask.

pypbr.blending.functional.blend_materials(material1: MaterialBase, material2: MaterialBase, method: str = 'mask', **kwargs) MaterialBase[source]

Blend two materials together using the specified method.

Parameters:
  • material1 (MaterialBase) – The first material.

  • material2 (MaterialBase) – The second material.

  • method (str) – The blending method to use. Options are ‘mask’, ‘height’, ‘properties’, ‘gradient’.

  • **kwargs – Additional arguments specific to the blending method.

Returns:

A new material resulting from blending material1 and material2.

Return type:

MaterialBase

Raises:

ValueError – If an unknown blending method is specified or required parameters are missing.

pypbr.blending.functional.blend_on_height(material1: MaterialBase, material2: MaterialBase, blend_width: float = 0.1, shift: float = 0.0) MaterialBase[source]

Blend two materials based on their height maps with an optional vertical shift.

Parameters:
  • material1 (MaterialBase) – The first material.

  • material2 (MaterialBase) – The second material.

  • blend_width (float, optional) – Controls the sharpness of the blending transition. Smaller values result in sharper transitions. Defaults to 0.1.

  • shift (float, optional) – Shifts the blending transition vertically. Positive values raise the blending height, while negative values lower it. Defaults to 0.0.

Returns:

A new material resulting from blending material1 and material2 based on height.

Return type:

MaterialBase

Raises:

ValueError – If either material lacks a height map.

pypbr.blending.functional.blend_on_properties(material1: MaterialBase, material2: MaterialBase, property_name: str = 'metallic', blend_width: float = 0.1) MaterialBase[source]

Blend two materials based on a specified property map.

Parameters:
  • material1 (MaterialBase) – The first material.

  • material2 (MaterialBase) – The second material.

  • property_name (str) – The name of the property map to use for blending (e.g., ‘metallic’, ‘roughness’).

  • blend_width (float) – Controls the sharpness of the blending transition.

Returns:

A new material resulting from blending material1 and material2.

Return type:

MaterialBase

Raises:

ValueError – If either material lacks the specified property map.

pypbr.blending.functional.blend_with_gradient(material1: MaterialBase, material2: MaterialBase, direction: str = 'horizontal') MaterialBase[source]

Blend two materials using a linear gradient mask.

Parameters:
  • material1 (MaterialBase) – The first material.

  • material2 (MaterialBase) – The second material.

  • direction (str) – The direction of the gradient (‘horizontal’ or ‘vertical’).

Returns:

A new material resulting from blending material1 and material2.

Return type:

MaterialBase

Raises:

ValueError – If an invalid direction is specified or material size cannot be determined.

pypbr.blending.functional.blend_with_mask(material1: MaterialBase, material2: MaterialBase, mask: FloatTensor) MaterialBase[source]

Blend two materials using the provided mask.

Parameters:
  • material1 (MaterialBase) – The first material.

  • material2 (MaterialBase) – The second material.

  • mask (torch.FloatTensor) – The blending mask tensor, with values in [0, 1], shape [1, H, W] or [H, W].

Returns:

A new material resulting from blending material1 and material2.

Return type:

MaterialBase