# Using C++ shaders from within a plugin

**URL:** <https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470>\
**Category:** Rendering\
**Tags:** rhi, unreal-engine, Plugins, Shaders, question\
**Created:** [July 28, 2014, 10:30am UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470 "2014-07-28T10:30:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZorbaTHut\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ZorbaTHut\_1](https://forums.unrealengine.com/u/ZorbaTHut_1)\
**Post date:** [July 28, 2014, 10:30am UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/1 "2014-07-28T10:30:42Z")

</div>

Right now, the official recommended way to use a specific shader from C++ is via the IMPLEMENT\_SHADER\_TYPE macro. This macro (once all is said and done) looks for a specific filename within the Engine/Shaders directory.

This is a very awkward place for plugins, since it requires that any user of the plugin install the plugin and then install all used shaders. It also means that multiple projects with different plugins cannot transparently use the same UE4 installation.

Ideally, it should be possible to put shaders inside the plugin itself so they can be read via IMPLEMENT\_SHADER\_TYPE. There’s presumably a way to include content, but shaders themselves don’t seem to work this way - the code appears to always append the root engine directory, and there’s no way to retrieve a plugin directory or otherwise refer to the contents of a plugin.

Is there something important I’m missing, or is this a feature that would need to be implemented?

---

<div class="post-metadata">

**Author:** ![Ehamloptiran\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ehamloptiran\_1](https://forums.unrealengine.com/u/Ehamloptiran_1)\
**Post date:** [July 28, 2014, 10:45am UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/2 "2014-07-28T10:45:44Z")

</div>

This is a feature that would need to be developed, I know I read somewhere that they were in fact investigating a way to accomplish this, so in future we may have “Engine/Shaders” for engine shaders, then “[PLUGIN]/Shaders” for specific plugin shaders.

---

<div class="post-metadata">

**Author:** ![denis.ischenko](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@denis.ischenko](https://forums.unrealengine.com/u/denis.ischenko)\
**Post date:** [August 29, 2016, 8:43pm UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/3 "2016-08-29T20:43:03Z")

</div>

Hi guys! Any update on that?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_88d57b37](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_88d57b37](https://forums.unrealengine.com/u/anonymous_user_88d57b37)\
**Post date:** [August 22, 2017, 11:09pm UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/4 "2017-08-22T23:09:32Z")

</div>

> New: Global Shader Support For Plugins
> 
> You can now add new global shaders  
> inside of Plugins and Projects! Taking  
> advantage of changes made to the  
> shader compiler and shader directory  
> file structure, Plugins and Projects  
> can provide their own Shaders. You can  
> look at the LensDistortion plugin for  
> a simple example  
> (Engine/Plugins/Compositing/LensDistortion).
> 
> Notes:
> 
> Plugin and Project modules that have  
> global shaders require use of the  
> PostConfigInit loading phase. Shader  
> support in Plugins and Projects is  
> still experimental. Plugins and  
> Projects can include other plugins’  
> USH files in the Public directory  
> freely. It is the responsibility of  
> the Plugin author to handle  
> inter-plugin dependencies correctly.  
> USF files should only be located in  
> the Private directory. All calls to  
> IMPLEMENT\_SHADER\_TYPE, should now  
> include the full path of the USF  
> shader file (e.g.  
> “/Engine/Private/Foo.usf” or  
> “/Plugin/FooBar/Private/MyComputeShader.usf”).  
> C++ Generated files should be mapped  
> within the /Engine/Generated/ virtual  
> directory. Shaders/ directory requires  
> at least a Private/ or Public/  
> directory. The Generated/ directory  
> should not exist.

4.17 release notes

---

<div class="post-metadata">

**Author:** ![darkgaze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkgaze](https://forums.unrealengine.com/u/darkgaze)\
**Post date:** [February 15, 2018, 4:42pm UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/5 "2018-02-15T16:42:00Z")

</div>

More on that: An official blog post with not many information, hard to make it compile, a little.

> **[How to Add Global Shaders to UE4](https://www.unrealengine.com/en-US/tech-blog/how-to-add-global-shaders-to-ue4)**
>
> Epic Games Senior Engine Programmer Rolando Caloca Olivares walks through the simple process of creating your own custom global shaders, enabling you to have greater control over the look and feel of your project.

---

<div class="post-metadata">

**Author:** ![darkgaze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkgaze](https://forums.unrealengine.com/u/darkgaze)\
**Post date:** [February 15, 2018, 4:49pm UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/6 "2018-02-15T16:49:42Z")

</div>

In fact, I have a comment to add here:  
"“/Plugin/FooBar/Private/MyComputeShader.usf” ← is not working for me. I checked typos, but It’s not able to find it… I’ll update the answer when I find out what’s going on

---

<div class="post-metadata">

**Author:** ![Darkxiv](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Darkxiv](https://forums.unrealengine.com/u/Darkxiv)\
**Post date:** [July 3, 2019, 11:21pm UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/7 "2019-07-03T23:21:25Z")

</div>

You should also add something like this to your FFooModule::StartupModule() for your Foo plugin:

{

```
FString PluginShaderDir = FPaths::Combine(IPluginManager::Get().FindPlugin(TEXT("Foo"))->GetBaseDir(), TEXT("Shaders"));
AddShaderSourceDirectoryMapping(TEXT("/Plugin/Foo"), PluginShaderDir);

```

}

---

<div class="post-metadata">

**Author:** ![NickJ-CL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NickJ-CL](https://forums.unrealengine.com/u/NickJ-CL)\
**Post date:** [September 27, 2019, 4:36pm UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/8 "2019-09-27T16:36:41Z")

</div>

Thanks, that comment saved me a lot of debugging.  
It’s a shame it’s not written in the [ShaderInPlugin documentation](https://docs.unrealengine.com/en-US/Programming/Rendering/ShaderInPlugin/Overview/index.html).

---

<div class="post-metadata">

**Author:** ![g\_test](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@g\_test](https://forums.unrealengine.com/u/g_test)\
**Post date:** [September 25, 2023, 3:06pm UTC](https://forums.unrealengine.com/t/using-c-shaders-from-within-a-plugin/289470/9 "2023-09-25T15:06:17Z")

</div>

Hello all, when adding compute shaders in plugin, I encountered some error"LogModuleManager Unable to load dll There may be an operating system error or the module may not be properly set up.  
I tried to narrow down the issue, and found it’s related with c++ shader class and IMPLEMENT\_GLOBAL\_SHADER pair. Defining only first pair of shader looks good

EDIT: fixed for myself, cause of bool type in shader parameter struct
