-
Notifications
You must be signed in to change notification settings - Fork 511
PBREffect
DirectXTK | Effects |
---|
PBREffect 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. This effect also supports GPU instancing.
SkinnedPBREffect extends PBREffect
to support vertex skinning. The skinned effect does not support velocity buffer generation or GPU instancing.
See also PBREffectFactory
Related tutorials: Physically-based rendering, Multistream rendering and instancing
classDiagram
class IEffect{
<<Interface>>
+Apply()
+GetVertexShaderBytecode()
}
class IEffectMatrices{
<<Interface>>
+SetWorld()
+SetView()
+SetProjection()
+SetMatrices()
}
class IEffectLights{
<<Interface>>
+SetLightEnabled()
+SetLightDirection()
+SetLightDiffuseColor()
+EnableDefaultLighting()
}
class PBREffect{
+SetAlpha()
+SetConstantAlbedo()
+SetConstantMetallic()
+SetConstantRoughness()
+SetAlbedoTexture()
+SetNormalTexture()
+SetRMATexture()
+SetEmissiveTexture()
+SetSurfaceTextures()
+SetIBLTextures()
+SetBiasedVertexNormals()
+SetInstancingEnabled()
+SetVelocityGeneration()
+SetRenderTargetSizeInPixels()
}
PBREffect--|> IEffect
PBREffect--|> IEffectMatrices
PBREffect--|> IEffectLights
class IEffectSkinning{
<<Interface>>
+SetWeightsPerVertex()
+SetBoneTransforms()
+ResetBoneTransforms()
}
class SkinnedPBREffect
PBREffect <|-- SkinnedPBREffect
SkinnedPBREffect --|> IEffectSkinning
#include <Effects.h>
Construction requires a Direct3D 11 device.
std::unique_ptr<PBREffect> effect;
effect = std::make_unique<PBREffect>(device);
std::unique_ptr<SkinnedPBREffect> effect;
effect = std::make_unique<SkinnedPBREffect>(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.
SkinnedPBREffect also supports IEffectSkinning.
Fog settings are not supported by these effects.
These effects require SV_Position
, NORMAL
, and TEXCOORD0
. It does not support per-vertex color.
If instancing is enabled, PBREffect
also requires these vertex elements:
"InstMatrix", 0, DXGI_FORMAT_R32G32B32A32_FLOAT
"InstMatrix", 1, DXGI_FORMAT_R32G32B32A32_FLOAT
"InstMatrix", 2, DXGI_FORMAT_R32G32B32A32_FLOAT
If skinning is used, the vertex layout requires BLENDINDICES
and BLENDWEIGHT
.
-
SetAlpha: Sets the alpha (transparency) of the effect. Defaults to 1 (fully opaque). This value is also used for binning opaque vs. transparent geometry.
-
SetConstantAlbedo, SetConstantMetallic, and SetConstantRoughness: Used to set the constant value when not using texturing for the albedo, roughness, and metalness information.
-
SetAlbedoTexture: Sets the albedo texture. This uses the sampler in slot 0. Can be set to nullptr to remove a reference. Can optionally include an alpha channel as well.
-
SetNormalTexture: Sets the normal texture. This uses the sampler in slot 0. Can be set to nullptr to remove a reference.
See NormalMapEffect for more details about the normal map texture.
- SetRMATexture: Sets the roughness/metalness/ambient-occlusion (RMA) texture. 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.
-
SetEmissiveTexture: Associates an emissive texture with the effect. This uses the sampler in slot 0. Can be set to nullptr to remove a reference.
-
SetSurfaceTextures: Associates a albedo texture, normal texture, and roughness/metalness/ambient-occlusion (RMA) texture with the effect in one method. This uses the sampler in slot 0. Can be set to nullptr to remove a reference.
-
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, IBLBaker, and Lys.
-
SetBiasedVertexNormals: Enables support for compressed vertex normals which require
*2 - 1
biasing at runtime such asDXGI_FORMAT_R10G10B10A2_UNORM
. -
SetInstancingEnabled: Enables support for per-vertex instancing by adding a per-vertex
XMFLOAT3X4
transform matrix. -
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.
PBREffect
does not support both instancing and velocity generation at the same time.
- SetRenderTargetSizeInPixels: Used to set the pixel size of the render target when generating velocity buffers.
These effects 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.
These effects 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.
Albedo (base color) map | Normal map | Emissive map |
Metalness (blue) | Roughness (green) | Ambient Occlusion (red) | Roughness/Metalness/Ambient-Occlusion map |
These effects use Shader Model 4.0 so requires Direct3D hardware feature level 10.0 or greater.
Note this means you can also count on
DXGI_FORMAT_BC5_UNORM
texture compression hardware support for your normal maps.
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
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 2017 2020
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
J.M.P. van Waveren and Ignacio Castaño, "Real-Time Normal Map DXT Compression", id Software, February 2008 PDF (note: BC5 is "tangent-space 3Dc")
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
- Windows 7 Service Pack 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