UE4 Guide: How to Add Global Shaders
Events
Subscribe:  iCal  |  Google Calendar
Helsinki FI   17, Oct — 25, Oct
Minsk BY   17, Oct — 19, Oct
London GB   22, Oct — 23, Oct
Singapore SG   23, Oct — 25, Oct
Paris FR   24, Oct — 27, Oct
Latest comments
by Nils Arenz
3 hours ago

@Tristan: I studied computergrafics for 5 years. I'm making 3D art now since about half a year fulltime, but I had some experience before that. Its hard to focus on one thing, it took me half a year to understand most of the vegetation creation pipelines. For speeding up your workflow maybe spend a bit time with the megascans library. Making 3D vegetation starts from going outside for photoscanns to profiling your assets. Start with one thing and master this. @Maxime: The difference between my technique and Z-passing on distant objects is quiet the same. (- the higher vertex count) I would start using this at about 10-15m+. In this inner radius you are using (mostly high) cascaded shadows, the less the shader complexety in this areas, the less the shader instructions. When I started this project, the polycount was a bit to high. Now I found the best balance between a "lowpoly" mesh and the less possible overdraw. The conclusion of this technique is easily using a slightly higher vertex count on the mesh for reducing the quad overdraw and shader complexity. In matters visual quality a "high poly" plant will allways look better than a blade of grass on a plane.

by Anthony Thomas Gaines
6 hours ago

Is this not like gear VR or anything else

by Starkemis
7 hours ago

Thank you!

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

Leave a Reply

2 Comments on "UE4 Guide: How to Add Global Shaders"

avatar
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;
}
};

wpDiscuz