Skip to content

NormalMapEffect

Chuck Walbourn edited this page Dec 8, 2017 · 35 revisions

This effect extends BasicEffect to support normal-mapping and an optional specular map. It supports texture mapping, vertex coloring, directional per-pixel lighting, and fog.

See also Effects

Header

#include <Effects.h>

Initialization

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

std::unique_ptr<NormalMapEffect> effect;

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

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

effect = std::make_unique<NormalMapEffect>(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 one additional optional parameter that controls use of a specular map. If set to true, then SetSpecularTexture must be used, otherwise it is ignored.

NormalMapEffect(ID3D12Device* device, int effectFlags,
    const EffectPipelineStateDescription& pipelineDescription,
    bool specularMap = true);

Interfaces

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

Input layout

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

Properties

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

  • SetEmissiveColor: Sets the emissive color of the effect. Defaults to black (0,0,0).

  • SetSpecularColor: Sets the specular color of the effect. Defaults to white (1,1,1).

  • SetSpecularPower: Sets the specular power of the effect. Defaults to 16. Settings power to 0 can cause strange rendering artifacts.

  • DisableSpecular: Disables the specular lighting for the effect. Sets the color to black (0,0,0) and power to 1.

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

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

  • SetTexture: Associates a diffuse/albedo texture and sampler descriptor with the effect.

  • SetNormalTexture: Associates a normal map texture for the effect. Uses the same sampler as SetTexture.

  • SetSpecularTexture: Associates a specular texture with the effectUses the same sampler as SetTexture.

Remarks

The EffectFlags::Texture, EffectFlags::Lighting and EffectsFlags::PerPixelLighting are always enabled for this effect, so use or absence of these flag is ignored for this effect.

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

This effect always performs texturing, so if 'untextured' diffuse rendering is desired you must provide a 1x1 texture with white (1,1,1,1).

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