Skip to content

EffectFactory

Chuck Walbourn edited this page Jul 17, 2016 · 32 revisions

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.

Header

#include <Effects.h>

Initialization

The EffectFactory constructor requires a Direct3D 12 device, and will create any required resource heaps automatically.

std::unique_ptr<EffectFactory> fxFactory;
fxFactory = std::make_unique<EffectFactory>( device );

If you already have created the required heaps, you can provide your own:

states = std::make_unique<CommonStates>(device);

resourceDescriptors = std::make_unique<DescriptorHeap>(device,
    D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
    D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
    Descriptors::Count);

fxFactory = std::make_unique<EffectFactory>( device,
    resourceDescriptors->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

Creating effects

UNDER CONSTRUCTION

Interfaces

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.

Sharing

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();

Effects options

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.

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