- 
                Notifications
    
You must be signed in to change notification settings  - Fork 465
 
BasicEffect
This is a native Direct3D 12 implementation of the built-in BasicEffect from XNA Game Studio 4 which supports texture mapping, vertex coloring, directional lighting, and fog.
See also Effects
#include <Effects.h>
Construction requires a Direct3D 12 device, optional effect flags, and state description:
std::unique_ptr<BasicEffect> effect;
RenderTargetState rtState(m_deviceResources->GetBackBufferFormat(),
    m_deviceResources->GetDepthBufferFormat());
EffectPipelineStateDescription pd(
    &VertexPositionNormalTexture::InputLayout,
    &CommonStates::Opaque,
    &CommonStates::DepthDefault,
    &CommonStates::CullCounterClockwise,
    &rtState);
effect = std::make_unique<BasicEffect>(device, EffectFlags::Lighting, 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
BasicEffect supports IEffect, IEffectMatrices, IEffectLights, and IEffectFog
This effect requires SV_Position, NORMAL if lighting is enabled (EffectFlags::Lighting or EffectFlags::PerPixelLighting), COLOR if per-vertex colors are enabled (EffectFlags::VertexColor), and  TEXCOORD0 if texturing is enabled (EffectFlags::Texture).
- 
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 texture shader resource view with the effect. Can be set to nullptr to remove a reference.
 
BasicEffect optimizations in XNA Game Studio 4.0
BasicEffect: a misnomer?
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 [email protected] 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 - v20
 - MinGW 12.2, 13.2
 - CMake 3.21