-
Notifications
You must be signed in to change notification settings - Fork 512
PBREffect
This effect implements a Disney-style (Roughness/Metalness workflow) Physically-Based Renderer (PBR) effect using Image-Based Lighting (IBL) in combination with up to three directional lights.
See also Effects
#include <Effects.h>
Construction requires a Direct3D 11 device.
std::unique_ptr<PBREffect> effect;
effect = std::make_unique<PBREffect>(device);
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr
or std::shared_ptr
PBREffect supports IEffect, IEffectMatrices, and IEffectLights.
Fog settings are not supported by this effect.
This effect requires SV_Position
, NORMAL
, and TEXCOORD0
. It does not support per-vertex color.
-
SetAlpha: Sets the alpha (transparency) of the effect. Defaults to 1 (fully opaque).
-
SetConstantAlbedo, SetConstantMetallic, and SetConstantRoughness: Used to set the constant value when not using texturing for the roughness/metalness/ambient-occlusion information.
-
SetSurfaceTextures: Associates a albedo texture, normal texture, and roughness/metalness/ambient-occlusion (RMA) texture with the effect. This uses the sampler in slot 0. Can be set to nullptr to remove a reference.
The RMA texture uses the glTF2 standard order: The metalness is in the B channel, roughness in the G channel, and ambient occlusion in the R channel. If there's no ambient occlusion, then the R channel should be set to all 1.
- SetIBLTextures: Associates a radiance and irradiance texture with the effect. The number of miplevels in the radiance texture is also required as this is used to compute roughness. This uses the sampler in slot 1. Can be set to nullptr to remove a reference.
The radiance and irradiance map are special cubemaps. They are generated by tools like AMD Cubemapgen, cmft/cmftStudio, and Lys.
-
SetEmissiveTexture: Associates an emissive texture with the effect. This uses the sampler in slot 0. Can be set to nullptr to remove a reference.
-
SetBiasedVertexNormals: Enables support for compressed vertex normals which require
*2 - 1
biasing at runtime such asDXGI_FORMAT_R10G10B10A2_UNORM
. -
SetVelocityGeneration: Enables the generation of a velocity buffer. If set to true, then both a Render Target 0 and Render Target 1 must be bound for rendering.
-
SetRenderTargetSizeInPixels: Used to set the pixel size of the render target when generating velocity buffers.
This effect always performs per-pixel lighting. Calls to SetLightingEnabled(false);
will generate a C++ exception, and calls to SetPerPixelLighting are ignored.
The lighting modeling for PBR does not make use of an ambient or specular term as these are more directly modeled by the image-based lighting model. Calls to SetAmbientLightColor and SetLightSpecularColor are ignored.
This effect requires a texture sampler in both slots 0 and 1. GeometricPrimitive and SpriteBatch only set a texture sampler in slot 0 by default, Model sets a sampler in slots 0 and 1.
This effect uses Shader Model 4.0 so requires Direct3D hardware feature level 10.0 or greater. For this reason, the Windows Phone 8.1 projects do not include the source for the PBR effect implementation as Windows Phone 8.1 hardware only supports Feature level 9.3.
Basic Theory of Physically-Based Rendering
Burley et al. "Physically-Based Shading at Disney", SIGGRAPH 2012 Course: Practical Physically Based Shading in Film and Game Production. Slides Notes
Karis. "Real Shading in Unreal Engine 4", SIGGRAPH 2013 Course: Physically Based Shading in Theory and Practice. Slides Notes
SIGGRAPH Course: 2012 2013 2014 2015 2016
Pharr, Jakob, and Humphreys, Physically Based Rendering: From Theory to Implementation, Morgan Kaufmann, website code
The Comprehensive PBR Guide, Allegorithmic website
Christian Schüler, "Normal Mapping without Precomputed Tangents", ShaderX 5, Chapter 2.6, pp. 131 – 140 and this blog post
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Xbox One
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20