UE4 Guide: How to Add Global Shaders
Events
Subscribe:  iCal  |  Google Calendar
7, Mar — 1, Jun
Raleigh US   16, Apr — 19, Apr
SEATTLE US   19, Apr — 22, Apr
Kharkiv UA   20, Apr — 21, Apr
Los Angeles US   23, Apr — 25, Apr
Latest comments
by sanek94cool
2 hours ago

What Bikmambetov is going to do there? He can only share how to make stupid movies :)

This would be so much more interesting if they'd offer help with housing and integration with a crash course in Japanese. Having some knowledge of the Japanese language and culture should be a pre but in my honest opinion, not a must. That would make this job hunt a much more relevant subject of interest.

by Samsun Rock
7 hours ago

Thank to the recommend this article. my suggestion is also effective from Change User Account Name in windows 10 operating computer, you must to learn this tutorial.

UE4 Guide: How to Add Global Shaders
13 September, 2017
News

In Unreal Engine 4, global shaders are shaders that can be used from the C++ side to render post-processing effects, dispatch compute shaders, clear the screen, etc.  Sometimes you need more advanced functionality to achieve a desired look, and a custom shader pass might help you. Epic Games has shared a step-by-step guide by Rolando Caloca Olivares to doing that. Let’s check it out. 

Art by Michael Gerard

Unreal Shader Files and How To Use Them

UE4 reads .usf files (Unreal Shader Files) from the Engine/Shaders folder. Any new shaders need their source files placed here. As of 4.17, shaders can also be read from a plugin (Plugin/Shaders). You should enable r.ShaderDevelopmentMode=1 in your ConsoleVariables.ini file for ease of development. Check out the documentation for more information.

Start by adding a new .usf file in your Engine/Shaders folder and calling it MyTest.usf. Then add a simple pass-through Vertex Shader and a Pixel Shader that returns a custom color:

// MyTest.usf 

// Simple pass-through vertex shader

void MainVS(
	in float4 InPosition : ATTRIBUTE0,
	out float4 Output : SV_POSITION
)
{
	Output = InPosition;
}

// Simple solid color pixel shader
float4 MyColor;
float4 MainPS() : SV_Target0
{
	return MyColor;
}

 

Now, in order to get UE4 to pick up the shader and start compiling it, you need to declare a C++ class. Start with the Vertex Shader:

// This can go on a header or cpp file
class FMyTestVS : public FGlobalShader
{
DECLARE_EXPORTED_SHADER_TYPE(FMyTestVS, Global, /*MYMODULE_API*/);
FMyTestVS()
{
}
FMyTestVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer)
{
}
static bool ShouldCache(EShaderPlatform Platform)
{
return true;
}
};

Make sure to continue studying global shaders here

Source: Epic Games
Comments

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
AdminLee Recent comment authors
Admin
Admin

on it

Lee
Guest
Lee

Could you please… PLEASE reformat that c++ code:
// This can go on a header or cpp file
class FMyTestVS : public FGlobalShader
{
DECLARE_EXPORTED_SHADER_TYPE(FMyTestVS, Global, /*MYMODULE_API*/);
FMyTestVS()
{
}
FMyTestVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer)
{
}
static bool ShouldCache(EShaderPlatform Platform)
{
return true;
}
};