Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyPBR

PyPBR is a versatile Python library designed for easy and efficient manipulation of Physically Based Rendering (PBR) materials with seamless PyTorch integration. It simplifies loading, converting, manipulating, and saving PBR materials, and offers robust tools for working with advanced Bidirectional Reflectance Distribution Function (BRDF) models like Cook-Torrance.

Features

  • Multiple PBR Workflows:

    • Basecolor-Metallic and Diffuse-Specular workflows supported.
    • Seamless conversion between workflows with dedicated methods.
  • Dynamic Material Handling:

    • Automated selection of appropriate material classes (BasecolorMetallicMaterial or DiffuseSpecularMaterial) based on available texture maps using the Factory pattern.
  • High-Precision Map Support:

    • Support for high bit-depth maps such as 16-bit height maps without loss of precision.
  • Color Space Management:

    • Proper handling of sRGB and linear color spaces for albedo, diffuse, and specular maps.
    • Flags to specify color space properties for each map.
  • PyTorch Integration:

    • Utilizes PyTorch tensors for all material maps, enabling GPU acceleration and efficient computations.
  • Material Manipulation Tools:

    • Functions to resize, tile, invert normals, and perform other common material manipulations.
  • Advanced BRDF Models:

    • Implementation of the Cook-Torrance BRDF model that supports multiple workflows and ensures consistent rendering results.
  • Flexible Input/Output:

    • Easy loading and saving of PBR materials from and to folders using standardized naming conventions.
    • Support for various image formats including PNG, JPEG, TIFF, BMP, and EXR.

Installation

PyPBR can be installed via pip:

pip install pypbr

Ensure that you have PyTorch installed. If not, follow the official installation guide to set it up.

Quick Start

Loading and Manipulating Materials

from pypbr.io import load_material_from_folder, save_material_to_folder

# Load a material from a folder with automatic workflow detection
material = load_material_from_folder('path/to/material/folder', preferred_workflow='metallic')

# Convert the material to the diffuse-specular workflow
diffuse_specular_material = material.to_diffuse_specular_material()

# Manipulate the material
diffuse_specular_material.resize((512, 512))
diffuse_specular_material.invert_normal()

# Save the modified material to a new folder
save_material_to_folder(diffuse_specular_material, 'path/to/save/material', format='png')

Rendering with Cook-Torrance BRDF

import torch
from pypbr.io import load_material_from_folder
from pypbr.models import CookTorranceBRDF

# Load a material (can be BasecolorMetallicMaterial or DiffuseSpecularMaterial)
material = load_material_from_folder('path/to/material/folder')

# Initialize the BRDF model
brdf = CookTorranceBRDF(light_type='directional')

# Define view and light directions
view_dir = torch.tensor([0.0, 0.0, 1.0])  # Viewer looking straight at the surface
light_dir = torch.tensor([0.0, 0.0, 1.0])  # Light coming from the same direction

# Define light intensity
light_intensity = torch.tensor([1.0, 1.0, 1.0])  # White light

# Compute the reflected color
color = brdf(
    material=material,
    view_dir=view_dir,
    light_dir_or_position=light_dir,
    light_intensity=light_intensity
)

# color is a tensor with shape (3, H, W) representing the RGB values

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypbr-0.1.0a4.tar.gz (49.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypbr-0.1.0a4-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file pypbr-0.1.0a4.tar.gz.

File metadata

  • Download URL: pypbr-0.1.0a4.tar.gz
  • Upload date:
  • Size: 49.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pypbr-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 36e06bc56712773ccd24832d7b57aac5d9b7a6f1e04973189e1441cf01566d49
MD5 d0e59f6686032fa34e5d2998d418d0f8
BLAKE2b-256 1e1feab86d2891343dd5d18244b42eb878c2f467a6e0295e4cf380d3e130154b

See more details on using hashes here.

File details

Details for the file pypbr-0.1.0a4-py3-none-any.whl.

File metadata

  • Download URL: pypbr-0.1.0a4-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pypbr-0.1.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 4405e9db582f40805381b7a622e1f6d1eefe0254eb76fe050185212e43a891fb
MD5 bf227b663d74953171518c4a88c0bb94
BLAKE2b-256 12419cf6bf0f34476b0194bf3e35059173f3482ff64dc30b804244cd4d3319f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page