|
| 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() |
0 commit comments