PBRShader
In this tutorial you will get familiar with PBRShader, which is the most common shader used in SkyRenderer.
In following lines you will get familiar with basic usage, parameter changes, GI, reflections, energy
preservation and many, many more.
Agenda:
- Physically Based Rendering Theory
- PBRShader basic usage
- PBRShader control parameters
Scene setup
Let's use custom scene composer to set up the scene.
from skyrenderer.cases.utils import MaterialsSceneComposer
scene_composer = MaterialsSceneComposer(antialiasing_level=2048)
scene_composer.setup_scene(width=1600, height=1000)
2025-02-04 10:45:01,394 | skyrenderer.scene.renderer_context | INFO: Root paths:
- root path: /dli/skyenvironment/skyrenderer/skyrenderer
- assets path: /dli/mount/assets
- config path: /dli/skyenvironment/skyrenderer/skyrenderer/config
- gpu sources path: /dli/skyenvironment/skyrenderer/skyrenderer/optix_sources/sources
- cache path: /dli/mount/cache
- ptx cache path: compiled_ptx/ptx
- ocio path: ocio_configs/aces_1.2/config.ocio
Physically Based Rendering
Bidirectional Scattering Distribution Function (BSDF in short), names a model which describes complex
surface-light interactions. BSDF consists of Bidirectional Reflectance Distribution Function (BRDF) and
Bidirectional Transmittance Distribution Function (BTDF) functions.
Physically based rendering's principle is to approximate real material's BSDF function to achieve photorealistic
results and reduce computational complexity. What is more, hyperparameters used in that model are defined
in a more intuitive and handful way. In order to reduce computational complexity additional pre-made maps
(e.g. normal map, specular map, etc.) are used.
In SkyRenderer the default Shader is PBRShader that focuses mainly on BRDF function.
BRDF is described by specular and diffuse component. Based on materials' properties different components
prevail. For fully metallic materials BRDF function consists mainly of specular factor, for non-metallic one
a diffuse factor plays main role. PBRShader implemented in SkyRenderer utilizes also a microfacet BRDF model,
that considers a surface as not smooth on micro-level, providing even more photorealistic results.
PBRShader basic usage
Let's create a Material Definition using PBRShader and assign this material to the shaderball.
To assign the material we will use RendererContext's set_material_definition() method.
In order to check, how different parameters affects PBRShader appearance, see SHADER_PBRShaderParameters tutorial.
from skyrenderer.scene.scene_layout.layout_elements_definitions import MaterialDefinition
from skyrenderer.basic_types.procedure.shader.basic_shaders import PBRShader
pbr_shader = PBRShader(scene_composer.renderer_context)
material_definition = MaterialDefinition(shader=pbr_shader)
scene_composer.renderer_context.set_material_definition(
node_name="shaderball_GEO", material_definition=material_definition
)
scene_composer.visualize()
2025-02-04 10:45:02,059 | skyrenderer.utils.time_measurement | INFO: Setup time: 621 ms
2025-02-04 10:45:04,978 | skyrenderer.utils.time_measurement | INFO: Context update time: 2.92 seconds
2025-02-04 10:45:29,942 | skyrenderer.utils.time_measurement | INFO: Key points calculation time: 0 ms
2025-02-04 10:45:29,942 | skyrenderer.utils.time_measurement | INFO: Render time: 24.96 seconds
Summary
In this section you have learnt:
- Physically Based Rendering principle is to approximate real material's BSDF function.
- PBRShader is defined in the same way as any other procedure.