# PyPBR
**PyPBR** is a Python library for creating, manipulating, and rendering Physically Based Rendering (PBR) materials, with a focus on providing a modular, flexible approach to material creation and blending.
PyPBR supports multiple PBR workflows, such as basecolor-metallic and diffuse-specular, and includes functionality for BRDF evaluation and blending operations.
PyPBR is build on PyTorch to leverage GPU acceleration and for easy integration with existing AI codebases.
## Features
- **Material Classes**: Support for different PBR workflows, including basecolor-metallic and diffuse-specular workflows.
- **Texture Manipulation**: Resize, rotate, crop, flip, and tile texture maps to create customized materials.
- **BRDF Models**: Implementations of Bidirectional Reflectance Distribution Functions (BRDF), including the Cook-Torrance model.
- **Material Blending**: Both functional and class-based approaches for blending materials, including methods based on masks, height maps, property maps, and gradients.
- **Input/Output**: Load and save materials from/to folders, supporting common file formats for easy integration into existing workflows.
## Installation
You can install **PyPBR** via pip:
```sh
pip install pypbr
```
## Getting Started
### Creating a PBR Material
To create a PBR material, use one of the provided classes from the `pypbr.material` module:
```python
from pypbr.material import BasecolorMetallicMaterial
from PIL import Image
# Load albedo and metallic maps
albedo_image = Image.open("path/to/albedo.png")
normal_image = Image.open("path/to/normal.png")
roughness_image = Image.open("path/to/roughness.png")
metallic_image = Image.open("path/to/metallic.png")
# Create a basecolor-metallic material
material = BasecolorMetallicMaterial(
albedo=albedo_image,
normal=normal_image,
roughness=metallic_image,
metallic=metallic_image
)
# Convert the material to a different workflow
diffuse_specular_material = material.to_diffuse_specular_material()
```
### Manipulating Texture Maps
PyPBR allows you to transform texture maps, such as resizing, rotating, and cropping:
```python
# Resize texture maps
material.resize((512, 512))
# Rotate the texture maps by 45 degrees
material.rotate(45, expand=True)
# Convert the albedo map to linear color space
material.to_linear()
```
### Evaluating BRDF
Use the `CookTorranceBRDF` class to evaluate light reflection on a material:
```python
from pypbr.models import CookTorranceBRDF
import torch
# Initialize the BRDF model
brdf = CookTorranceBRDF(light_type="point")
# Define the material and directions
view_dir = torch.tensor([0.0, 0.0, 1.0])
light_dir = torch.tensor([0.1, 0.1, 1.0])
light_intensity = torch.tensor([1.0, 1.0, 1.0])
# Evaluate the BRDF to get the reflected color
color = brdf(material, view_dir, light_dir, light_intensity)
```
### Blending Materials
You can blend two materials using different blending methods, either functionally or using class-based approaches:
```python
from pypbr.blending.functional import blend_materials
import torch
# Create two materials
material1 = load_material_from_folder("path/to/material1", preferred_workflow="metallic")
material2 = load_material_from_folder("path/to/material2", preferred_workflow="metallic")
# Blend the materials using a mask
mask = torch.rand(1, 256, 256)
blended_material = blend_materials(material1, material2, method='mask', mask=mask)
```
Or use class-based blending methods:
```python
from pypbr.blending.blending import MaskBlend
# Use a MaskBlend instance to blend two materials
mask_blend = MaskBlend(mask)
blended_material = mask_blend(material1, material2)
```
## Modules Overview
- **`pypbr.material`**: Core classes for creating and manipulating PBR materials.
- **`pypbr.models`**: Implementations of different BRDF models for rendering.
- **`pypbr.utils`**: Utility functions for color space conversions and normal map computations.
- **`pypbr.io`**: Functions for loading and saving materials.
- **`pypbr.blending.functional`**: Functional interfaces for blending materials.
- **`pypbr.blending.blending`**: Class-based blending interfaces for PBR materials.
## Contributing
Contributions are welcome! If you have ideas for new features or enhancements, feel free to open an issue or a pull request.
1. Fork the repository.
2. Create your feature branch (`git checkout -b feature/AmazingFeature`).
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`).
4. Push to the branch (`git push origin feature/AmazingFeature`).
5. Open a pull request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Contact
For any questions or suggestions, feel free to reach out or open an issue in the GitHub repository.
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/35/d6/55f3e0774f1ba68e283ef02f900f7350b3aac0ee50aac6dd95dc130fb3be/pypbr-0.1.0b1.tar.gz",
"platform": null,
"description": "# PyPBR\n\n**PyPBR** is a Python library for creating, manipulating, and rendering Physically Based Rendering (PBR) materials, with a focus on providing a modular, flexible approach to material creation and blending. \n\nPyPBR supports multiple PBR workflows, such as basecolor-metallic and diffuse-specular, and includes functionality for BRDF evaluation and blending operations.\n\nPyPBR is build on PyTorch to leverage GPU acceleration and for easy integration with existing AI codebases. \n\n## Features\n\n- **Material Classes**: Support for different PBR workflows, including basecolor-metallic and diffuse-specular workflows.\n- **Texture Manipulation**: Resize, rotate, crop, flip, and tile texture maps to create customized materials.\n- **BRDF Models**: Implementations of Bidirectional Reflectance Distribution Functions (BRDF), including the Cook-Torrance model.\n- **Material Blending**: Both functional and class-based approaches for blending materials, including methods based on masks, height maps, property maps, and gradients.\n- **Input/Output**: Load and save materials from/to folders, supporting common file formats for easy integration into existing workflows.\n\n## Installation\n\nYou can install **PyPBR** via pip:\n\n```sh\npip install pypbr\n```\n\n## Getting Started\n\n### Creating a PBR Material\n\nTo create a PBR material, use one of the provided classes from the `pypbr.material` module:\n\n```python\nfrom pypbr.material import BasecolorMetallicMaterial\nfrom PIL import Image\n\n# Load albedo and metallic maps\nalbedo_image = Image.open(\"path/to/albedo.png\")\nnormal_image = Image.open(\"path/to/normal.png\")\nroughness_image = Image.open(\"path/to/roughness.png\")\nmetallic_image = Image.open(\"path/to/metallic.png\")\n\n# Create a basecolor-metallic material\nmaterial = BasecolorMetallicMaterial(\n albedo=albedo_image, \n normal=normal_image,\n roughness=metallic_image,\n metallic=metallic_image\n)\n\n# Convert the material to a different workflow\ndiffuse_specular_material = material.to_diffuse_specular_material()\n```\n\n### Manipulating Texture Maps\n\nPyPBR allows you to transform texture maps, such as resizing, rotating, and cropping:\n\n```python\n# Resize texture maps\nmaterial.resize((512, 512))\n\n# Rotate the texture maps by 45 degrees\nmaterial.rotate(45, expand=True)\n\n# Convert the albedo map to linear color space\nmaterial.to_linear()\n```\n\n### Evaluating BRDF\n\nUse the `CookTorranceBRDF` class to evaluate light reflection on a material:\n\n```python\nfrom pypbr.models import CookTorranceBRDF\nimport torch\n\n# Initialize the BRDF model\nbrdf = CookTorranceBRDF(light_type=\"point\")\n\n# Define the material and directions\nview_dir = torch.tensor([0.0, 0.0, 1.0])\nlight_dir = torch.tensor([0.1, 0.1, 1.0])\nlight_intensity = torch.tensor([1.0, 1.0, 1.0])\n\n# Evaluate the BRDF to get the reflected color\ncolor = brdf(material, view_dir, light_dir, light_intensity)\n```\n\n### Blending Materials\n\nYou can blend two materials using different blending methods, either functionally or using class-based approaches:\n\n```python\nfrom pypbr.blending.functional import blend_materials\nimport torch\n\n# Create two materials\nmaterial1 = load_material_from_folder(\"path/to/material1\", preferred_workflow=\"metallic\")\nmaterial2 = load_material_from_folder(\"path/to/material2\", preferred_workflow=\"metallic\")\n\n# Blend the materials using a mask\nmask = torch.rand(1, 256, 256)\nblended_material = blend_materials(material1, material2, method='mask', mask=mask)\n```\n\nOr use class-based blending methods:\n\n```python\nfrom pypbr.blending.blending import MaskBlend\n\n# Use a MaskBlend instance to blend two materials\nmask_blend = MaskBlend(mask)\nblended_material = mask_blend(material1, material2)\n```\n\n## Modules Overview\n\n- **`pypbr.material`**: Core classes for creating and manipulating PBR materials.\n- **`pypbr.models`**: Implementations of different BRDF models for rendering.\n- **`pypbr.utils`**: Utility functions for color space conversions and normal map computations.\n- **`pypbr.io`**: Functions for loading and saving materials.\n- **`pypbr.blending.functional`**: Functional interfaces for blending materials.\n- **`pypbr.blending.blending`**: Class-based blending interfaces for PBR materials.\n\n## Contributing\n\nContributions are welcome! If you have ideas for new features or enhancements, feel free to open an issue or a pull request.\n\n1. Fork the repository.\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`).\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`).\n4. Push to the branch (`git push origin feature/AmazingFeature`).\n5. Open a pull request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Contact\n\nFor any questions or suggestions, feel free to reach out or open an issue in the GitHub repository.\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.0b1",
"project_urls": {
"Homepage": "https://gvecchio.com/PyPBR/",
"Repository": "https://github.com/giuvecchio/PyPBR"
},
"split_keywords": [
"pbr",
" materials",
" pytorch",
" graphics"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8418b87b50fb353d3edfd8d5507b5b46880e3bb9a8ddc6e5eea5c101de882284",
"md5": "d9ea36fe8aab4f0c68826d5ce0a65d0e",
"sha256": "29e6068c6e41f9b6ee59e98f623636acbf79366e9ebaaef337ffe4482c0c6089"
},
"downloads": -1,
"filename": "pypbr-0.1.0b1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d9ea36fe8aab4f0c68826d5ce0a65d0e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 1706575,
"upload_time": "2024-10-14T10:08:01",
"upload_time_iso_8601": "2024-10-14T10:08:01.825125Z",
"url": "https://files.pythonhosted.org/packages/84/18/b87b50fb353d3edfd8d5507b5b46880e3bb9a8ddc6e5eea5c101de882284/pypbr-0.1.0b1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "35d655f3e0774f1ba68e283ef02f900f7350b3aac0ee50aac6dd95dc130fb3be",
"md5": "8d014c1cee153b12fd52bdc817291f22",
"sha256": "8020d87c8c504233b669bf13f2802b10d0dd45fc73f18d2a3b9d7b365520984f"
},
"downloads": -1,
"filename": "pypbr-0.1.0b1.tar.gz",
"has_sig": false,
"md5_digest": "8d014c1cee153b12fd52bdc817291f22",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 14843746,
"upload_time": "2024-10-14T10:08:04",
"upload_time_iso_8601": "2024-10-14T10:08:04.103543Z",
"url": "https://files.pythonhosted.org/packages/35/d6/55f3e0774f1ba68e283ef02f900f7350b3aac0ee50aac6dd95dc130fb3be/pypbr-0.1.0b1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-14 10:08:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "giuvecchio",
"github_project": "PyPBR",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "torch",
"specs": [
[
">=",
"1.7.0"
]
]
},
{
"name": "torchvision",
"specs": [
[
">=",
"0.8.0"
]
]
},
{
"name": "numpy",
"specs": [
[
">=",
"1.18.0"
]
]
},
{
"name": "Pillow",
"specs": [
[
">=",
"8.0.0"
]
]
}
],
"lcname": "pypbr"
}