Next, the Pixel Shader is declared using the following code:ĭECLARE_EXPORTED_SHADER_TYPE(FMyTestPS, Global, /*MYMODULE_API*/) įMyTestPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) Use `ELoadingPhase::PostConfigInit` on your module to cause it to load earlier.`Īfter a game or editor has launched, a dynamic module is not allowed to add its own shader type.
> `Shader type was loaded after engine init. Whichever module you add your FGlobalShader to must be loaded before the engine starts, or you will get an assert, such as:
It also causes the shader to be added to the compilation list, as long as its ShouldCache() method returns true. usf file ( f), the shader entry point ( MainVS), and the frequency/shader stage ( SF_Vertex). This macro maps the type ( FMyTestVS) to the. IMPLEMENT_SHADER_TYPE(, FMyTestVS, TEXT("MyTest"), TEXT("MainVS"), SF_Vertex) A Shader Type can be registered to Unreal Engine's list of types using the following code: For example, you may not want to compile a compute shader on a non-compute shader capable RHI.Ī Shader Type is a template or class that is specified by shader code, which maps to a physical C++ class. The ShouldCache() function is needed to determine if this shader should be compiled under certain circumstances. There are two constructors: the default constructor, and the serialization constructor.
For example, any C++ code that doesn't live in the Renderer Module. The third parameter is a type for external linkage for the code module where the shader module will live, if required. Usage of DECLARE_EXPORTED_SHADER_TYPE() macro generates exports required for serialization of the shader type. As such, it will end up in the Global Shader Map, meaning it doesn't need a material to find it. There are a few requirements when doing this: Static bool ShouldCache(EShaderPlatform Platform) DECLARE_EXPORTED_SHADER_TYPE(FMyTestVS, Global, /*MYMODULE_API*/) įMyTestVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)