-
Notifications
You must be signed in to change notification settings - Fork 411
EffectFactory
This is a helper object primarily used by the Model loader implementations to provide sharing of material Effects. This can be used standalone as well, and allows access to any existing ‘materials’ definitions already created.
It uses a simple case-sensitive string-based (wide-character) map for finding effect instances that have already been created by the factory, which avoid duplication of resources in complex models and scenes.
#include <Effects.h>
The EffectFactory constructor requires a Direct3D 12 device, assuming you don't have any textures used in your effects.
std::unique_ptr<EffectFactory> fxFactory;
fxFactory = std::make_unique<EffectFactory>( device );
To use textures in your effects, you need to provide your resource heaps typically from EffectTextureFactory:
states = std::make_unique<CommonStates>(device);
fxFactory = std::make_unique<EffectFactory>( device,
modelResources->Heap(), states->Heap() );
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr
or std::shared_ptr
UNDER CONSTRUCTION
std::shared_ptr<IEffect> __cdecl CreateEffect(
const EffectInfo& info,
const EffectPipelineStateDescription& opaquePipelineState,
const EffectPipelineStateDescription& alphaPipelineState,
const D3D12_INPUT_LAYOUT_DESC& inputLayout,
textureDescriptorOffset = 0,
int samplerDescriptorOffset = 0);
The EffectFactory is a concrete implementation of the IEffectFactory interface, and provides a default implementation and caching policy. This allows the developer to create their own custom version of the Effect Factory by deriving from IEffectFactory, which can be used with Model loaders. This could be used for alternative caching policies, substituting special Effects triggered material name, etc.
You can control the sharing cache with two methods that are implemented for EffectFactory.
This method sets the sharing mode which defaults to true. By setting it to false, CreateEffect will always return a new instance rather than returning a cached instance.
fxFactory->SetSharing( false );
This method clears the sharing cache, which might not release all the instances if they are referenced by other objects.
fxFactory->ReleaseCache();
Because of the DirectX 12 Pipeline State Object (PSO) model, all effect options must be determined at the time the effect is created.
-
EnablePerPixelLighting is used to determine if
EffectFlags::PerPixelLighting
will be used. This defaults to true. -
EnableNormalMapEffect is used to determine of NormalMapEffect is used for models containing tangents and normal-map textures. This defaults to true. If set to false, it will use BasicEffect instead for these materials.
-
EnableFogging is used to determine if
EffectFlags::Fog
will be used. This defaults to false.
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