This is a native Direct3D 11 implementation of the five built-in effects from XNA Game Studio, providing identical functionality and API:
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr or std::shared_ptr
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476892.aspx
http://blogs.msdn.com/b/shawnhar/archive/2010/04/30/built-in-effects-permutations-and-performance.aspx
http://blogs.msdn.com/b/shawnhar/archive/2010/04/25/basiceffect-optimizations-in-xna-game-studio-4-0.aspx
http://blogs.msdn.com/b/shawnhar/archive/2008/08/22/basiceffect-a-misnomer.aspx
http://blogs.msdn.com/b/shawnhar/archive/2010/08/04/dualtextureeffect.aspx
http://blogs.msdn.com/b/shawnhar/archive/2010/08/09/environmentmapeffect.aspx
- BasicEffect supports texture mapping, vertex coloring, directional lighting, and fog
- AlphaTestEffect supports per-pixel alpha testing
- DualTextureEffect supports two layer multitexturing (for lightmaps or detail textures)
- EnvironmentMapEffect supports cubic environment mapping
- SkinnedEffect supports skinned animation
Initialization
The BasicEffect constructor requires a Direct3D 11 device.
std::unique_ptr<BasicEffect> effect(new BasicEffect(device));
Set effect parameters
effect->SetWorld(world);
effect->SetView(view);
effect->SetProjection(projection);
effect->SetTexture(cat);
effect->SetTextureEnabled(true);
effect->EnableDefaultLighting();
Draw using the effect
effect->Apply(deviceContext); deviceContext->IASetInputLayout(...); deviceContext->IASetVertexBuffers(...); deviceContext->IASetIndexBuffer(...); deviceContext->IASetPrimitiveTopology(...); deviceContext->DrawIndexed(...);
Input Layout
To create an input layout matching the effect vertex shader input signature:*// First, configure effect parameters the way you will be using it. Turning// lighting, texture map, or vertex color on/off alters which vertex shader// is used, so GetVertexShaderBytecode will return a different blob after// you alter these parameters. If you create an input layout using a// BasicEffect that had lighting disabled, but then later enable lighting,// that input layout will no longer match as it will not include the// now-necessary normal vector.voidconst* shaderByteCode; size_t byteCodeLength; effect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength); device->CreateInputLayout(VertexPositionNormalTexture::InputElements, VertexPositionNormalTexture::InputElementCount, shaderByteCode, byteCodeLength, pInputLayout);
Threading model
Creation is fully asynchronous, so you can instantiate multiple effect instances at the same time on different threads. Each instance only supports drawing from one thread at a time, but you can simultaneously draw on multiple threads if you create a separate effect instance per Direct3D 11 deferred context.http://msdn.microsoft.com/en-us/library/windows/desktop/ff476892.aspx
Further reading
http://blogs.msdn.com/b/shawnhar/archive/2010/04/28/new-built-in-effects-in-xna-game-studio-4-0.aspxhttp://blogs.msdn.com/b/shawnhar/archive/2010/04/30/built-in-effects-permutations-and-performance.aspx
http://blogs.msdn.com/b/shawnhar/archive/2010/04/25/basiceffect-optimizations-in-xna-game-studio-4-0.aspx
http://blogs.msdn.com/b/shawnhar/archive/2008/08/22/basiceffect-a-misnomer.aspx
http://blogs.msdn.com/b/shawnhar/archive/2010/08/04/dualtextureeffect.aspx
http://blogs.msdn.com/b/shawnhar/archive/2010/08/09/environmentmapeffect.aspx