-
Notifications
You must be signed in to change notification settings - Fork 411
SkinnedEffect
DirectXTK | Effects |
---|
This is a native Direct3D 12 implementation of the built-in SkinnedEffect from XNA Game Studio 4 (Microsoft.Xna.Framework.Graphics.SkinnedEffect
) which supports skinned animation with up to 72 bones and 1, 2, or 4 bone influences per vertex. It supports texture mapping, directional vertex lighting, directional per-pixel lighting, and fog.
See also Effects
Related tutorial:** Using skinned models
classDiagram
class EffectFlags{
<<enumeration>>
Fog
PerPixelLighting
BiasedVertexNormals
}
class IEffect{
<<Interface>>
+Apply()
}
class IEffectMatrices{
<<Interface>>
+SetWorld()
+SetView()
+SetProjection()
+SetMatrices()
}
class IEffectLights{
<<Interface>>
+SetAmbientLightColor()
+SetLightEnabled()
+SetLightDirection()
+SetLightDiffuseColor()
+SetLightSpecularColor()
+EnableDefaultLighting()
}
class IEffectFog{
<<Interface>>
+SetFogStart()
+SetFogEnd()
+SetFogColor()
}
class IEffectSkinning{
<<Interface>>
+SetBoneTransforms()
+ResetBoneTransforms()
}
class SkinnedEffect{
+SetDiffuseColor()
+SetEmissiveColor()
+SetSpecularColor()
+SetSpecularPower()
+DisableSpecular()
+SetAlpha()
+SetColorAndAlpha()
+SetTexture()
}
SkinnedEffect .. EffectFlags
SkinnedEffect --|> IEffect
SkinnedEffect --|> IEffectMatrices
SkinnedEffect --|> IEffectLights
SkinnedEffect --|> IEffectFog
SkinnedEffect --|> IEffectSkinning
#include <Effects.h>
Construction requires a Direct3D 12 device, optional effect flags, and state description:
std::unique_ptr<SkinnedEffect> effect;
RenderTargetState rtState(m_deviceResources->GetBackBufferFormat(),
m_deviceResources->GetDepthBufferFormat());
EffectPipelineStateDescription pd(
&InputLayout,
CommonStates::Opaque,
CommonStates::DepthDefault,
CommonStates::CullCounterClockwise,
rtState);
effect = std::make_unique<SkinnedEffect>(device, Effects::None, pd);
The constructor takes one additional optional parameter to optimize the shader (see below):
SkinnedEffect(ID3D12Device* device, int effectFlags,
const EffectPipelineStateDescription& pipelineDescription, int weightsPerVertex = 4);
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr
or std::shared_ptr
SkinnedEffect supports IEffect, IEffectMatrices, IEffectLights, IEffectFog, and IEffectSkinning. EffectFlags::Fog
is required to enable fogging.
This effect requires NORMAL
, TEXCOORD0
, BLENDINDICES
and BLENDWEIGHT
.
-
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). 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. Can optionally include an alpha channel as well.
The BLENDINDICES
and BLENDWEIGHT
elements can hold up to 4 individual bone influences per vertex. Since each influence adds more computation to the shader, you can optimize this effect by setting the supported number of influences to 1, 2, or 4 in the constructor and any additional influences will be ignored. This value defaults to 4.
The effect always performs either vertex (EffectFlags::Lighting
) or per-pixel lighting (EffectFlags::PerPixelLighting
). It does not support per-vertex color (EffectFlags::VertexColor
).
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
.
This effect always performs texturing, so if 'untextured' rendering is desired you must provide texture coordinates, and a 1x1 texture with white (1,1,1,1).
Both EffectFlags::Lighting
and EffectFlags::Texture
are always enabled for this effect, so use or absence of these flags is ignored for this effect.
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.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Xbox One
- Xbox Series X|S
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20