Added a second demo project building on top of the first one featuring an advanced shader from shadertoy - created by Inigo Quilez
Hi there!
First thanks for this post, really helpful!
I’ve encountered the following problem: I was coding around, some time after I’ve been working on my shaders and implementing your stuff, when I realized that
- My compile button was gone and
- Unreal didn’t like to hot-reload anymore.
I’ve investigated this a bit, reinstalled VS and did a lot of stuff until I came back onto this post. When I download your Shader Project and open it, the Compile button is also missing. When I create a fresh, new, Unreal Project (4.24), with the Twinstick example project and as a C++ project, I have a compile button!
This brings me to the assumption that those changes broke something how the engine works with my project and makes hot-reload not work anymore and the in-engine compile button vanish.
Have you encountered similiar problems, do you know what could be the reason for this?
Here the Answerhub-Link, where this problem is explained at full length:
https://answers.unrealengine.com/que…0358/view.html
Aaand I’ve already found the solution. I’ve compared the code with the one from the ShooterGame example, as you recommended, and changed the module’s parent class to FDefaultGameModuleImpl instead of IModuleInterface.
Do you know why that happend? Maybe your forum post has to be corrected…
Thanks, i’ll look into it and update the project.
Unable to reproduce your issue, which version of the engine are you using please?
edit: I’ll make inhering from FDefaultGameModuleImpl the default behavior, it’s necessary if you build a game on top of the project hosting the shader, it doesn’t seem necessary if the project is a plugin only hosting the shader in comparison.
Thanks for the feedback.
I was using the latest 4.24
Your welcome, glad I could help!
Thanks again for this awesome forum post, coding shaders externally is much more pleasant then directly in the material editor’s custom node
Care to elevate what this simple copy/paste is? I have the same problem you have, and couldn’t find a solution
I know it’s a late answer but to anyone who needs help here is what I’ve done to get the paint effect working.
I copied this :
float2 UV = GetDefaultSceneTextureUV(Parameters, 14);
float4 MeanAndVariance[4];
float4 Range;
float Angle = GetPixelAngle(UV);
float2x2 RotationMatrix = float2x2(cos(Angle), -sin(Angle), sin(Angle), cos(Angle));
Range = float4(-XRadius, 0, -YRadius, 0);
MeanAndVariance[0] = GetKernelMeanAndVariance(UV, Range, RotationMatrix);
Range = float4(0, XRadius, -YRadius, 0);
MeanAndVariance[1] = GetKernelMeanAndVariance(UV, Range, RotationMatrix);
Range = float4(-XRadius, 0, 0, YRadius);
MeanAndVariance[2] = GetKernelMeanAndVariance(UV, Range, RotationMatrix);
Range = float4(0, XRadius, 0, YRadius);
MeanAndVariance[3] = GetKernelMeanAndVariance(UV, Range, RotationMatrix);
// 1
float3 FinalColor = MeanAndVariance[0].rgb;
float MinimumVariance = MeanAndVariance[0].a;
// 2
for (int i = 1; i < 4; i++)
{
if (MeanAndVariance*.a < MinimumVariance)
{
FinalColor = MeanAndVariance*.rgb;
MinimumVariance = MeanAndVariance*.a;
}
}
return FinalColor;
into a “Custom” node.
Here is the final node :
Hello, it seams that it still throws an error that it is unable to find the global still
I have read all the comments but still can’t resolve my missing shader source. “/Project/trunkWind.ush”. I am totally new and expect this is because I haven’t done anything relating to C++.
I am trying to open this example project and it can’t find the shader within the /Shader folder.
any help is greatly appreciated. thanks
I fixed the error in 4.25,here is the URL: GitHub - franklzt/vegetation-shader: A procedural wind material for vegetation in UE4.
Met this error following “Unreal Engine 4 Paint Filter Tutorial” from here Unreal Engine 4 Paint Filter Tutorial | raywenderlich.com
The solution from @MaxImeDupart still works - Virtual Shader Source Path - Link custom Shaders - Shadertoy Demo download - #4 by MaximeDupart
(similar solution - UE4 – Loading shaders from within the project folder – Oded Maoz Erell's CG Log)
-
Make it a c++ project by at least adding a c++ class to your game from the engine (File - New C++ Class - None - Next. In UE5 it’s located in Tools instead of File).
-
If you have 4.21 Add “ShaderCore” to your project’s
PublicDependencyModuleNames
in.Build.cs
file inside Source folder. If you have 4.22+ - you need to add RenderCore instead. For example, replace
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
with
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RenderCore" });
- Modify your project’s main .cpp and .h files. For example, my project’s name is PaintFilter and I’ve modified from
// Fill out your copyright notice in the Description page of Project Settings.
#include "PaintFilter.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, PaintFilter, "PaintFilter" );
to
// Fill out your copyright notice in the Description page of Project Settings.
#include "PaintFilter.h"
#include "Modules/ModuleManager.h"
#include "Interfaces/IPluginManager.h"
#include "Logging/LogMacros.h"
#include "Misc/Paths.h"
#include "ShaderCore.h"
void FPaintFilterModule::StartupModule()
{
#if (ENGINE_MINOR_VERSION >= 21) || (ENGINE_MAJOR_VERSION >= 5)
FString ShaderDirectory = FPaths::Combine(FPaths::ProjectDir(), TEXT("Shaders"));
AddShaderSourceDirectoryMapping("/Project", ShaderDirectory);
#endif
}
void FPaintFilterModule::ShutdownModule()
{
}
IMPLEMENT_PRIMARY_GAME_MODULE( FPaintFilterModule, PaintFilter, "PaintFilter" );
PaintFilter.h from
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
to
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
class FPaintFilterModule
: public IModuleInterface
{
public:
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};
Basically what you do you setup additional module that will add project’s /shaders directory as shaders searching path.
-
Recompile your project - open “.sln” file from your project’s directory in visual studio, then “Build” → Rebuild <your_project_name>.
-
Open your project in unreal and it will work external shader pathes.
PS Too bad that Unreal still have that issue, I think UE need a default way to use external shaders from Project without need to setting it up each time manually. I’m going to report it to https://issues.unrealengine.com/, hopefully it will work out.