# Unreal Engine 4 Paint Filter Tutorial

**URL:** <https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134>\
**Category:** 🎓 Courses & Articles\
**Created:** [May 1, 2018, 7:01pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134 "2018-05-01T19:01:06Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![tommytran](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tommytran/32/81089_2.png) [@tommytran](https://forums.kodeco.com/u/tommytran)\
**Post date:** [May 1, 2018, 7:01pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/1 "2018-05-01T19:01:06Z")

</div>

In this Unreal Engine 4 tutorial, you will learn how to make your game look like a painting by implementing Kuwahara filtering.

* * *
 This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/100-unreal-engine-4-paint-filter-tutorial](https://www.raywenderlich.com/100-unreal-engine-4-paint-filter-tutorial)

---

<div class="post-metadata">

**Author:** ![scarlatto](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@scarlatto](https://forums.kodeco.com/u/scarlatto)\
**Post date:** [May 2, 2018, 4:41am UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/2 "2018-05-02T04:41:16Z")

</div>

Awesome! Thanks for sharing!

---

<div class="post-metadata">

**Author:** ![s0meguy](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/s0meguy/32/81494_2.png) [@s0meguy](https://forums.kodeco.com/u/s0meguy)\
**Post date:** [November 1, 2018, 12:30pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/3 "2018-11-01T12:30:38Z")

</div>

Thanks, really cool tutorial! Just as a heads up, putting custom shader files in ProjectFolder/Shaders doesn’t seem to work anymore with 4.21!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [November 1, 2018, 1:23pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/4 "2018-11-01T13:23:37Z")

</div>

@tommytran Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![makemake](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@makemake](https://forums.kodeco.com/u/makemake)\
**Post date:** [November 8, 2018, 7:41pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/5 "2018-11-08T19:41:11Z")

</div>

Hi! Thank you very much for these tutorials :D. I was wondering where can I learn the code used in Unreal Engine 4 materials custom node. I am looking for a full guide, if someone exsists. I was trying to recreate a blackhole effect, like the one in the interstellar movie. Something like this: [Shader - Shadertoy BETA](https://www.shadertoy.com/view/ldjSDc)  
but I failed miserably.  
Thank you again!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [November 13, 2018, 9:22pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/6 "2018-11-13T21:22:18Z")

</div>

@tommytran Do you have any feedback about this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![tommytran](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tommytran/32/81089_2.png) [@tommytran](https://forums.kodeco.com/u/tommytran)\
**Post date:** [November 15, 2018, 12:03am UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/7 "2018-11-15T00:03:19Z")

</div>

Thanks for the heads up! 4.21 has that as a “bug fix”:

> **Bug Fix:** Replaced automatic virtual shader directory mapping with manual approach in StartupModule(). It should reduce the amount of directory exists queries at Editor startup.

It looks like you need to manually map the directory using [AddShaderSourceDirectoryMapping](https://api.unrealengine.com/INT/API/Runtime/ShaderCore/AddShaderSourceDirectoryMapping/index.html).

---

<div class="post-metadata">

**Author:** ![tommytran](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tommytran/32/81089_2.png) [@tommytran](https://forums.kodeco.com/u/tommytran)\
**Post date:** [November 15, 2018, 12:05am UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/8 "2018-11-15T00:05:36Z")

</div>

Hi makemake,

The custom node uses HLSL so that’d be a good place to start. You can also check our [Custom Shaders](https://www.raywenderlich.com/190254/unreal-engine-4-custom-shaders-tutorial) tutorial for information on how the HLSL is generated.

---

<div class="post-metadata">

**Author:** ![s0meguy](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/s0meguy/32/81494_2.png) [@s0meguy](https://forums.kodeco.com/u/s0meguy)\
**Post date:** [November 15, 2018, 10:11am UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/9 "2018-11-15T10:11:14Z")

</div>

Thanks for the tip!

I managed to get it working again.  
Incase other people come here looking for a fix, here is how I got it working.

In your game project’s C++ solution(replace “Projectname” with your projects name) add/modify the following files:

- **Projectname.Build.cs:** (Add “ShaderCore” to your dependency modules)

PublicDependencyModuleNames.AddRange(new string[] { “Core”, “CoreUObject”, “Engine”, “InputCore”, “HeadMountedDisplay”, “RenderCore”, “Niagara”_, “ShaderCore”_ });

- **Projectname.h** (Derive of FDefaultGameModuleImpl to override StartupModule())

#pragma once

#include “CoreMinimal.h”

_class FModifiedDefaultModuleImpl  
: public FDefaultGameModuleImpl  
{  
virtual void StartupModule() override;  
};_

- **Projectname.cpp** ( replace FDefaultGameModuleImpl with your derrived class, implement the function StartupModule() and call AddShaderSourceDirectoryMapping() to include your projects /Shader/ directory)

#include “Projectname.h”  
#include “Modules/ModuleManager.h”  
_#include “ShaderCore.h”_

IMPLEMENT\_PRIMARY\_GAME\_MODULE(_FModifiedDefaultModuleImpl_, Projectname, “Projectname” );

_void FModifiedDefaultModuleImpl::StartupModule()  
{  
FDefaultGameModuleImpl::StartupModule();  
AddShaderSourceDirectoryMapping(TEXT(“/Project”), FPaths::Combine(FPaths::ProjectDir(), TEXT(“Shaders”)));  
}_

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [November 15, 2018, 10:48am UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/10 "2018-11-15T10:48:25Z")

</div>

@s0meguy Thank you for sharing the solution - much appreciated!

---

<div class="post-metadata">

**Author:** ![nicedwar](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/nicedwar/32/79275_2.png) [@nicedwar](https://forums.kodeco.com/u/nicedwar)\
**Post date:** [December 18, 2018, 1:37pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/11 "2018-12-18T13:37:31Z")

</div>

I followed this to add C++ support for the project:  
[https://puppet-master.net/docs/unreal-engine-4/programming/how-to-add-c-support-for-a-unreal-project/](https://puppet-master.net/docs/unreal-engine-4/programming/how-to-add-c-support-for-a-unreal-project/)  
and followed s0meguy’s steps for aAddShaderSourceDirectoryMapping(), but it didn’t seem to work. I just jumped back to 4.20 for now.

The filter adds some significant flickering/jitter, especially around the thin parts of of leaves when pulling the camera back a bit.  
Research suggested that going into the material, in this case **PP\_Kuwahara → Post Processing Material → Blendable Location** , and setting **Before Tonemapping** can help for certain post processing effects, but didn’t do much for me in this case.  
Turning off **Temporal Anti-Aliasing** , now accessible only in the project settings, does fix the jitter, but the overall scene doesn’t look as good when moving around.  
This post links to a PowerPoint from Epic about the development of TemporalAA, which suggests using sharpening, blurring, or noise to compensate.

> **[Post Processing jitter](https://forums.unrealengine.com/t/post-processing-jitter/319343)**
>
> When the Engine Scaleability Setting of Anti Aliasing is set to High or higher using a post process material will result in jitter: That is the Scene Color pass. The only scene texture pass that doesn’t seem to jitter seems to be the final pass:...

Adding a **Gaussian Depth of Field** to the PostProcessVolume with just a bit of far blur looks best to me. Lots of DoF settings available, helpful for retaining edges/details.

Thanks very much for putting this together! Just wanted to dump my info here for others.

---

<div class="post-metadata">

**Author:** ![phl4m](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/phl4m/32/81494_2.png) [@phl4m](https://forums.kodeco.com/u/phl4m)\
**Post date:** [April 9, 2019, 1:16pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/12 "2019-04-09T13:16:00Z")

</div>

Great tutorial, thank you!  
Looks like the variance is miscalculated, though. You have to get the mean value first, then get the sum of the squared differences (pixelvalue - meanvalue), then divide this sum by the number of samples.

```
for (int x = Range.x; x <= Range.y; x++)
    {
        for (int y = Range.z; y <= Range.w; y++)
        {
            float2 Offset = mul(float2(x, y) * TexelSize, RotationMatrix);
            float3 PixelColor = SceneTextureLookup(UV + Offset, 14, false).rgb;
            Mean += PixelColor;
            Samples++;
        }
    }
    Mean /= Samples;
    
    for (int x = Range.x; x <= Range.y; x++)
    {
        for (int y = Range.z; y <= Range.w; y++)
        {
            float2 Offset = mul(float2(x, y) * TexelSize, RotationMatrix);
            float3 PixelColor = SceneTextureLookup(UV + Offset, 14, false).rgb;
            Variance += (PixelColor - Mean) * (PixelColor - Mean);
        }
    }
    Variance = Variance / Samples;

```

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 30, 2019, 3:49am UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/13 "2019-04-30T03:49:28Z")

</div>

@phl4m Thank you for sharing this - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![proxit](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/proxit/32/81494_2.png) [@proxit](https://forums.kodeco.com/u/proxit)\
**Post date:** [June 11, 2019, 8:08pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/14 "2019-06-11T20:08:32Z")

</div>

Hi, Thanks for sharing, so much useful content 😀

What if I’d like to add a full vertex and pixel shader? I’ve seen some plugins as examples in C++ but unfortunately I can’t figure It out how to make them work and how to link the shaders 😪  
Something like that:

> void MainVertexShader(  
> float4 InPosition : ATTRIBUTE0,  
> float2 InUV : ATTRIBUTE1,  
> out float2 OutUV : TEXCOORD0,  
> out float4 OutPosition : SV\_POSITION  
> )  
> {  
> OutPosition = InPosition;  
> OutUV = InUV;  
> }
> 
> Texture2D TextureParameter;
> 
> void MainPixelShader(  
> in float2 uv : TEXCOORD0,  
> out float4 OutColor : SV\_Target0  
> )  
> {

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 9, 2019, 2:47pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/15 "2019-07-09T14:47:58Z")

</div>

@tommytran Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [August 22, 2019, 6:41pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/16 "2019-08-22T18:41:02Z")

</div>

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [August 22, 2019, 6:41pm UTC](https://forums.kodeco.com/t/unreal-engine-4-paint-filter-tutorial/42134/17 "2019-08-22T18:41:05Z")

</div>

Closed on August 22, 2019, 6:41pm UTC


