Skip to content

PBREffect

Chuck Walbourn edited this page May 9, 2019 · 40 revisions

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, PBREffectFactory

Header

#include <Effects.h>

Initialization

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

Interfaces

PBREffect supports IEffect, IEffectMatrices, and IEffectLights.

Fog settings are not supported by this effect.

Input layout

This effect requires SV_Position, NORMAL, and TEXCOORD0. It does not support per-vertex color.

Properties

  • 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 albeto, roughness, and metalness information.

  • SetAlbedoTexture: Sets the albeto texture. This uses the sampler in slot 0. Can be set to nullptr to remove a reference.

  • 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 function call. 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 as DXGI_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.

Remarks

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.

Feature Level Notes

This effect uses Shader Model 4.0 so requires Direct3D hardware feature level 10.0 or greater.

Direct3D feature levels

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 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

Art Pipeline for glTF

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One

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 12

DirectXMesh

DirectXTex

DirectXMath

Win2D

Tools

Test Suite

Model Viewer

Content Exporter

DxCapsViewer

Clone this wiki locally