Skip to content

DebugEffect

Chuck Walbourn edited this page Aug 15, 2022 · 9 revisions
DirectXTK Effects

This effect provides a way to visualize normals, tangents, and binormals/bitangents for debugging purposes. This effect also supports GPU instancing.

See also Effects

Related tutorials: Using advanced shaders, Multistream rendering and instancing

classDiagram
class Mode{
    <<enumeration>>
    Mode_Default
    Mode_Normals
    Mode_Tangents
    Mode_BiTangents
}
class EffectFlags{
    <<enumeration>>
    VertexColor
    BiasedVertexNormals
    Instancing
}
class IEffect{
    <<Interface>>
    +Apply()
}
class IEffectMatrices{
    <<Interface>>
    +SetWorld()
    +SetView()
    +SetProjection()
    +SetMatrices()
}
class DebugEffect{
    +SetHemisphericalAmbientColor()
    +SetAlpha()
}
DebugEffect .. Mode
DebugEffect .. EffectFlags
DebugEffect --|> IEffect
DebugEffect --|> IEffectMatrices
Loading

Header

#include <Effects.h>

Initialization

Construction requires a Direct3D 12 device, optional effect flags, and state description:

std::unique_ptr<Debugffect> effect;

RenderTargetState rtState(m_deviceResources->GetBackBufferFormat(),
    m_deviceResources->GetDepthBufferFormat());

EffectPipelineStateDescription pd(
    &InputLayout,
    CommonStates::Opaque,
    CommonStates::DepthDefault,
    CommonStates::CullCounterClockwise,
    rtState);

effect = std::make_unique<DebugEffect>(device, EffectFlags::None, pd);

For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr or std::shared_ptr

The constructor takes an additional defaulted parameter which controls the specific debug shader to use:

Mode_Default Hemispherical ambient lighting
Mode_Normals RGB normals
Mode_Tangents RGB tangents
Mode_BiTangents RGB bi-tangents (a.k.a. binormals)
DebugEffect(ID3D12Device* device, int effectFlags,
    const EffectPipelineStateDescription& pipelineDescription,
    Mode debugMode = Mode_Default);

Interfaces

PBREffect supports IEffect and IEffectMatrices.

Input layout

This effect requires SV_Position, NORMAL, and TEXCOORD0. If per-vertex colors are enabled (EffectFlags::VertexColor), it also requires COLOR.

If instancing is enabled (EffectFlags::Instancing), this effect also requires these vertex elements:

"InstMatrix",  0, DXGI_FORMAT_R32G32B32A32_FLOAT
"InstMatrix",  1, DXGI_FORMAT_R32G32B32A32_FLOAT
"InstMatrix",  2, DXGI_FORMAT_R32G32B32A32_FLOAT

Properties

  • SetAlpha: Sets the alpha (transparency) of the effect. Defaults to 1 (fully opaque).

  • SetHemisphericalAmbientColor: The default mode uses a simple hemispherical ambient lighting so you can see the object with some 3D clues regardless of overall scene lighting. It defaults to using White to Black. This property can set different upper/lower colors.

Remarks

The EffectFlags::BiasedVertexNormals is supported by this effect. This flag should be used if the vertex data contains normals encoded as biased data such as DXGI_FORMAT_R10G10B10A2_UNORM.

EffectFlags::Fog is not supported by this effect.

Further reading

Christian Schüler, "Normal Mapping without Precomputed Tangents", ShaderX 5, Chapter 2.6, pp. 131 – 140 and this blog post

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

DirectXMesh

DirectXTex

DirectXMath

Tools

Test Suite

Model Viewer

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally