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 Effects, PBREffectFactory
Related tutorials: Physically-based rendering, Multistream rendering and instancing
classDiagram
class EffectFlags{
<<enumeration>>
Texture
BiasedVertexNormals
Instancing
Emissive
Velocity
}
class IEffect{
<<Interface>>
+Apply()
}
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()
+SetRenderTargetSizeInPixels()
}
PBREffect .. EffectFlags
PBREffect --|> IEffect
PBREffect --|> IEffectMatrices
PBREffect --|> IEffectLights
class IEffectSkinning{
<<Interface>>
+SetBoneTransforms()
+ResetBoneTransforms()
}
class SkinnedPBREffect
PBREffect <|-- SkinnedPBREffect
SkinnedPBREffect --|> IEffectSkinning
Header
#include <Effects.h>
Initialization
Construction requires a Direct3D 12 device, optional effect flags, and state description:
std::unique_ptr<PBREffect> effect;
RenderTargetState rtState(m_deviceResources->GetBackBufferFormat(),
m_deviceResources->GetDepthBufferFormat());
EffectPipelineStateDescription pd(
&InputLayout,
CommonStates::Opaque,
CommonStates::DepthDefault,
CommonStates::CullCounterClockwise,
rtState);
effect = std::make_unique<PBREffect>(device, EffectFlags::None, pd);
std::unique_ptr<SkinnedPBREffect> effect;
effect = std::make_unique<SkinnedPBREffect>(device, EffectFlags::None, pd);
In addition to the usual effect flags, this effect also supports EffectFlags::Emissive
and EffectFlags::Velocity
.
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr
or std::shared_ptr
Older versions of the library used
, bool emissive = false, bool generateVelocity = false)
as the final parameters to the ctor. These are replaced withEffectFlags
now.
Interfaces
PBREffect supports IEffect, IEffectMatrices, and IEffectLights.
SkinnedPBREffect also supports IEffectSkinning.
Fog settings are not supported by these effects.
Input layout
These effects require SV_Position
, NORMAL
, and TEXCOORD0
.
If instancing is enabled (EffectFlags::Instancing
), 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
.
Properties
-
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 along with a sampler descriptor with the effect. Can optionally include an alpha channel as well.
-
SetNormalTexture: Sets the normal texture. Uses the same sampler as the albedo texture.
See NormalMapEffect for more details about the normal map texture.
- SetRMATexture: Sets the roughness/metalness/ambient-occlusion (RMA) texture. Uses the same sampler as the albedo texture.
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. Uses the same sampler as the albedo texture. This requires having enabled
EffectFlags::Emissive
in the constructor, otherwise it is ignored. -
SetSurfaceTextures: Associates a albedo texture, normal texture, and roughness/metalness/ambient-occlusion (RMA) texture along with a sampler descriptor with the effect in one method.
-
SetIBLTextures: Associates a radiance and irradiance texture along with a sampler descriptor with the effect. The number of miplevels in the radiance texture is also required as this is used to compute roughness.
The radiance and irradiance map are special cubemaps. They are generated by tools like AMD Cubemapgen, cmft/cmftStudio, IBLBaker, and Lys.
- SetRenderTargetSizeInPixels: Used to set the pixel size of the render target when generating velocity buffers. If
EffectFlags::Velocity
is set, then both a Render Target 0 and Render Target 1 must be bound for rendering, and SetRenderTargetSizeInPixels should be set for the target pixel size.
Remarks
If EffectFlags::Texture
is not provided, then the effect uses the constant albedo, metallic, and roughness values. Note that use of velocity buffers require texture input.
The EffectFlags::Lighting
and EffectsFlags::PerPixelLighting
are always enabled for these effects, so use or absence of these flag is ignored.
The EffectFlags::BiasedVertexNormals
is supported by these effects. This flag should be used if the vertex data contains normals encoded as biased data such as DXGI_FORMAT_R10G10B10A2_UNORM
.
EffectFlags::Fog
and EffectFlags::VertexColor
are not supported by these effects.
PBREffect
does not support both EffectFlags::Instancing
and EffectFlags::Velocity
at the same time. SkinnedPBREffect
doesn't support either of these effect flags.
Albedo (base color) map | Normal map | Emissive map |
Metalness (blue) | Roughness (green) | Ambient Occlusion (red) | Roughness/Metalness/Ambient-Occlusion map |
Further reading
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")
For Use
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Xbox One
- Xbox Series X|S
Architecture
- x86
- x64
- ARM64
For Development
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20
Related Projects
DirectX Tool Kit for DirectX 11
Tools
See also
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 opencode@microsoft.com with any additional questions or comments.