Skip to content

DualTextureEffect

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

This is a native Direct3D 12 implementation of the built-in DualTextureEffect from XNA Game Studio 4 (Microsoft.Xna.Framework.Graphics.DualTextureEffect) which supports two layer multi-texturing (for light maps or detail textures), vertex color, and fogging.

See also Effects

Dual texture map

classDiagram
class EffectFlags{
    <<enumeration>>
    Fog
    VertexColor
}
class IEffect{
    <<Interface>>
    +Apply()
}
class IEffectMatrices{
    <<Interface>>
    +SetWorld()
    +SetView()
    +SetProjection()
    +SetMatrices()
}
class IEffectFog{
    <<Interface>>
    +SetFogStart()
    +SetFogEnd()
    +SetFogColor()
}
class DualTextureEffect{
    +SetDiffuseColor()
    +SetAlpha()
    +SetColorAndAlpha()
    +SetTexture()
    +SetTexture2()
}
DualTextureEffect .. EffectFlags
DualTextureEffect --|> IEffect
DualTextureEffect --|> IEffectMatrices
DualTextureEffect --|> IEffectFog
Loading

Header

#include <Effects.h>

Initialization

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

std::unique_ptr<DualTextureEffect> effect;

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

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

effect = std::make_unique<DualTextureEffect>(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

Interfaces

DualTextureEffect supports IEffect, IEffectMatrices, and IEffectFog. EffectFlags::Fog is required to enable fogging.

Input layout

This effect requires SV_Position, TEXCOORD0, and TEXCOORD1. It requires COLOR if per-vertex colors are enabled (EffectFlags::VertexColor).

Properties

  • SetDiffuseColor: Sets the diffuse color of the effect. Defaults to white (1,1,1). Alpha channel (.w component) is ignored.

  • SetAlpha: Sets the alpha (transparency) of the effect. Defaults to 1 (fully opaque). This value is also used for binning opaque vs. transparent geometry.

  • SetColorAndAlpha: Sets the diffuse color of the effect and the alpha (transparency).

  • SetTexture: Associates a texture and sampler descriptor with the effect for the 'base' texture. Can optionally include an alpha channel as well.

  • SetTexture2: Associates a texture and sampler descriptor with the effect for the 'second' texture.

Remarks

Does not support lighting (EffectFlags::Lighting or EffectsFlags::PerPixelLighting) as it is assumed to be 'baked' into one of the two textures. The EffectFlags::BiasedVertexNormals flag is ignored by this effect.

The EffectFlags::Texture flag is always enabled for this effect, so use or absence of this flag is ignored for this effect.

Diffuse map Light map

Further reading

DualTextureEffect

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Xbox One
  • Xbox Series X|S

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