top of page
Writer's pictureDavid Flores

Learning Unreal: Custom Shaders

Today's Learning Unreal post is the third part of a mini-sub series about creating shaders in Unreal. You can find the previous part on toon outlines here.


The topic of today's post is how to use custom shaders, which allow you to write HLSL code to create more complex materials than possible with the node-based system. As always, if you want to follow along with the same tutorial that I'm using, you can find it here.


As with the previous posts, I'll first start by providing an unaltered image of the scene so we can compare it later.

Unaltered viking image.
All set and ready to go, one last time.

The key step in creating a custom shader in Unreal is to add a Custom node in the node-based system, which allows you to input your own HLSL code into the shader. I created two different shaders using a Custom node while following this tutorial, the first of which was a Desaturation shader.

Viking with desaturation shader.
Hello darkness, my old friend...

This was a rather simple process, requiring only a single line of HLSL to be inputted into a custom shader. There's really not much more to say than that. It really was that simple.

 

The second custom shader I created was a Gaussian Blur shader, which required a bit more work than the previous example above.

Viking with a Guassian Blur shader.
Try not to focus too hard on this one.

The main trick behind creating this shader is using external shader files and importing them into Unreal's material system. These external files should go into Shaders folder that you create in the project folder*. With an external shader file, it becomes a simple task to implement the complex algorithm for Gaussian Blur, and a neat little trick you can do with a second Custom node let's you create global functions that you can use anywhere in your shader.


Though creating custom shaders with the Custom node is a powerful skill that will let you create better shaders, there are a few disadvantages. Most notably:

  • Custom nodes cannot access many parts of the rendering pipline

  • HLSL code is not guaranteed to work across different versions of Unreal

  • Code in Custom nodes cannot be constant folded for optimization purposes

*In recent versions of Unreal, it no longer checks the Shaders folder when checking for external shader files, which can cause errors. This forum post provides a work around for this issue, but it's a bit of a hassle, especially if you aren't familiar with C++.

 

Unfortunately, it's time to say goodbye to our viking friend for now.


199 views0 comments

Recent Posts

See All

Comments


bottom of page