Skip to content

Commit c90c98c

Browse files
committed
Merge branch 'feature/blending' into develop
2 parents 9bf43e6 + 4ded256 commit c90c98c

14 files changed

Lines changed: 617 additions & 8 deletions

File tree

examples/data/rocks/basecolor.png

36 MB
Loading

examples/data/rocks/diffuse.png

36 MB
Loading

examples/data/rocks/height.png

23.7 MB
Loading

examples/data/rocks/metallic.png

16 KB
Loading

examples/data/rocks/normal.png

38.9 MB
Loading

examples/data/rocks/opacity.png

22 KB
Loading

examples/data/rocks/roughness.png

11.3 MB
Loading

examples/data/rocks/specular.png

1.35 MB
Loading

examples/example_blend.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import torch
2+
from torchvision.transforms.functional import to_pil_image
3+
4+
from pypbr import CookTorranceBRDF
5+
from pypbr.io import load_material_from_folder
6+
import pypbr.blending as B
7+
import pypbr.blending.functional as BF
8+
9+
# Load material
10+
material1 = load_material_from_folder("./data/tiles", preferred_workflow="metallic")
11+
material2 = load_material_from_folder("./data/rocks", preferred_workflow="metallic")
12+
13+
# Blend the materials
14+
blender = B.HeightBlend(blend_width=0.1, shift=-0.5)
15+
16+
material, mask = blender(material1, material2)
17+
18+
H, W = 512, 512
19+
material.resize((H, W)).tile(2)
20+
21+
# Create an instance of the BRDF with the material
22+
brdf = CookTorranceBRDF(light_type="point")
23+
24+
# Define the view direction, light direction, and light intensity
25+
view_dir = torch.tensor([0.0, 0.0, 1.0]) # Viewing straight on
26+
light_dir = torch.tensor([0.1, 0.1, 1.0]) # Light coming from slightly top right
27+
light_intensity = torch.tensor([1.0, 1.0, 1.0]) # White light
28+
light_size = 1.0
29+
30+
# Evaluate the BRDF to get the reflected color
31+
reflected_color = brdf(material, view_dir, light_dir, light_intensity, light_size)
32+
33+
# Convert to PIL Image and display
34+
image = to_pil_image(reflected_color)
35+
image.show()

pypbr/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
It includes both functional APIs and transformation classes that can be composed.
66
77
Modules:
8+
blending: Classes for blending materials using various methodologies.
89
io: Input/output functions for saving and loading materials.
910
material: Classes representing PBR materials.
1011
models: Classes representing BRDF models.
@@ -24,12 +25,15 @@
2425
srgb_to_linear,
2526
"""
2627

27-
from . import io, utils
28+
from . import blending, io, utils
2829
from ._version import version as __version__
2930
from .material import BasecolorMetallicMaterial, DiffuseSpecularMaterial, MaterialBase
3031
from .models import BRDFModel, CookTorranceBRDF
3132

3233
__all__ = [
34+
"blending",
35+
"io",
36+
"utils",
3337
"MaterialBase",
3438
"BasecolorMetallicMaterial",
3539
"DiffuseSpecularMaterial",

0 commit comments

Comments
 (0)