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.0a2.tar.gz (53.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.0a2-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pypbr-0.1.0a2.tar.gz
  • Upload date:
  • Size: 53.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.0a2.tar.gz
Algorithm Hash digest
SHA256 af362010f4d409fbbbf3f38ced3b39a4a759261cd4bce2dc33d74ed41f243101
MD5 42a1039350b4fc3b5e5280e33291ced3
BLAKE2b-256 7886255743403be6c14e193330e83cf67cd298db4f6226a3e4786c713c9d01e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pypbr-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 15.0 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.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 3cb675c6d61735106e65f1b854d70ce3c1cb18e72b86982e3e8aaf2d1be0bdb8
MD5 f1f81cb3b100e8acc6d582d55372fc42
BLAKE2b-256 ab5bd5a85d20861892c3caa8dc939bc2d3eee51850b95fd6be8e52c6397150e6

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