pypbr


Namepypbr JSON
Version 0.1.0a4.dev0 PyPI version JSON
download
home_pageNone
SummaryA Python library for easy and fast manipulation of PBR materials with PyTorch integration.
upload_time2024-10-07 13:07:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6
licenseMIT License
keywords pbr materials pytorch graphics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyPBR

<!-- ![PyPBR Logo](https://github.com/giuvecchio/PyPBR/raw/main/assets/logo.png) -->

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:

```bash
pip install pypbr
```

Ensure that you have PyTorch installed. If not, follow the [official installation guide](https://pytorch.org/get-started/locally/) to set it up.

## Quick Start

### Loading and Manipulating Materials

```python
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

```python
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
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pypbr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "PBR, materials, PyTorch, graphics",
    "author": null,
    "author_email": "Giuseppe Vecchio <giuseppevecchio@hotmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f0/c4/3232585feedb68eb4ea21b25811f875d3c6abb524268baab94a6da6ff64c/pypbr-0.1.0a4.dev0.tar.gz",
    "platform": null,
    "description": "# PyPBR\n\n<!-- ![PyPBR Logo](https://github.com/giuvecchio/PyPBR/raw/main/assets/logo.png) -->\n\nPyPBR 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.\n\n## Features\n\n- **Multiple PBR Workflows:**\n  - **Basecolor-Metallic** and **Diffuse-Specular** workflows supported.\n  - Seamless conversion between workflows with dedicated methods.\n\n- **Dynamic Material Handling:**\n  - Automated selection of appropriate material classes (`BasecolorMetallicMaterial` or `DiffuseSpecularMaterial`) based on available texture maps using the Factory pattern.\n\n- **High-Precision Map Support:**\n  - Support for high bit-depth maps such as 16-bit height maps without loss of precision.\n\n- **Color Space Management:**\n  - Proper handling of sRGB and linear color spaces for albedo, diffuse, and specular maps.\n  - Flags to specify color space properties for each map.\n\n- **PyTorch Integration:**\n  - Utilizes PyTorch tensors for all material maps, enabling GPU acceleration and efficient computations.\n\n- **Material Manipulation Tools:**\n  - Functions to resize, tile, invert normals, and perform other common material manipulations.\n\n- **Advanced BRDF Models:**\n  - Implementation of the **Cook-Torrance** BRDF model that supports multiple workflows and ensures consistent rendering results.\n\n- **Flexible Input/Output:**\n  - Easy loading and saving of PBR materials from and to folders using standardized naming conventions.\n  - Support for various image formats including PNG, JPEG, TIFF, BMP, and EXR.\n\n## Installation\n\nPyPBR can be installed via pip:\n\n```bash\npip install pypbr\n```\n\nEnsure that you have PyTorch installed. If not, follow the [official installation guide](https://pytorch.org/get-started/locally/) to set it up.\n\n## Quick Start\n\n### Loading and Manipulating Materials\n\n```python\nfrom pypbr.io import load_material_from_folder, save_material_to_folder\n\n# Load a material from a folder with automatic workflow detection\nmaterial = load_material_from_folder('path/to/material/folder', preferred_workflow='metallic')\n\n# Convert the material to the diffuse-specular workflow\ndiffuse_specular_material = material.to_diffuse_specular_material()\n\n# Manipulate the material\ndiffuse_specular_material.resize((512, 512))\ndiffuse_specular_material.invert_normal()\n\n# Save the modified material to a new folder\nsave_material_to_folder(diffuse_specular_material, 'path/to/save/material', format='png')\n```\n\n### Rendering with Cook-Torrance BRDF\n\n```python\nimport torch\nfrom pypbr.io import load_material_from_folder\nfrom pypbr.models import CookTorranceBRDF\n\n# Load a material (can be BasecolorMetallicMaterial or DiffuseSpecularMaterial)\nmaterial = load_material_from_folder('path/to/material/folder')\n\n# Initialize the BRDF model\nbrdf = CookTorranceBRDF(light_type='directional')\n\n# Define view and light directions\nview_dir = torch.tensor([0.0, 0.0, 1.0])  # Viewer looking straight at the surface\nlight_dir = torch.tensor([0.0, 0.0, 1.0])  # Light coming from the same direction\n\n# Define light intensity\nlight_intensity = torch.tensor([1.0, 1.0, 1.0])  # White light\n\n# Compute the reflected color\ncolor = brdf(\n    material=material,\n    view_dir=view_dir,\n    light_dir_or_position=light_dir,\n    light_intensity=light_intensity\n)\n\n# color is a tensor with shape (3, H, W) representing the RGB values\n```\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A Python library for easy and fast manipulation of PBR materials with PyTorch integration.",
    "version": "0.1.0a4.dev0",
    "project_urls": {
        "Homepage": "https://github.com/giuvecchio/pypbr"
    },
    "split_keywords": [
        "pbr",
        " materials",
        " pytorch",
        " graphics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b35e0052a91dfd6afb57ae08080ac0172f212eff1844ce9eddec864f78c7081",
                "md5": "54c6e7a50e95fca67ddc37c595d405a6",
                "sha256": "df87a79e0ac66a49162516a7ad48a1881732af843ddf0768efb55f16c1c6aad2"
            },
            "downloads": -1,
            "filename": "pypbr-0.1.0a4.dev0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "54c6e7a50e95fca67ddc37c595d405a6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 18877,
            "upload_time": "2024-10-07T13:07:16",
            "upload_time_iso_8601": "2024-10-07T13:07:16.239821Z",
            "url": "https://files.pythonhosted.org/packages/2b/35/e0052a91dfd6afb57ae08080ac0172f212eff1844ce9eddec864f78c7081/pypbr-0.1.0a4.dev0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f0c43232585feedb68eb4ea21b25811f875d3c6abb524268baab94a6da6ff64c",
                "md5": "039a380b76972d3c6b1a68306c6e9136",
                "sha256": "51779738d46b9192a68272f2936e91630eac109b3d38d4fa36c5acf6abe6a53e"
            },
            "downloads": -1,
            "filename": "pypbr-0.1.0a4.dev0.tar.gz",
            "has_sig": false,
            "md5_digest": "039a380b76972d3c6b1a68306c6e9136",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 49165306,
            "upload_time": "2024-10-07T13:07:18",
            "upload_time_iso_8601": "2024-10-07T13:07:18.066579Z",
            "url": "https://files.pythonhosted.org/packages/f0/c4/3232585feedb68eb4ea21b25811f875d3c6abb524268baab94a6da6ff64c/pypbr-0.1.0a4.dev0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-07 13:07:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "giuvecchio",
    "github_project": "pypbr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pypbr"
}
        
Elapsed time: 0.36980s