Custom shaders for mesh rendering?


Obligatory - UE4 newbie here - So pardon me if I do not know things.

I am looking at writing custom shaders to load (static) meshes in the scene (Basically load index buffer and vertex data in). Similar to gltf files.

As I am doing my research, I understand that there are Global Shaders (mostly 1 per scenes and used for things like post process etc) and Material Shaders (Which can have applied to various objects in the scenes) - So I guess I should be looking more in to writing Materials shaders. (vertex and pixel shaders here)

So I read the following tutorials/links I could find :

I have some questions :

  1. Should I be implementing it as a plugin or local module? I assume in UE4 plugins systems there is not much of a difference(?)
  2. To start off with I am looking to load a simple triangle or cube 3d model into the scene with my custom shaders - I found this blog post (Yet another blog...: Adding Global shaders to UE4 v2.0) but I havnt manged to get far ahead. Does any one know of any resource /sample/tutorial doing the same? It is a pretty basic use case so I guess there should be some tutorials but I havnt any yet.
  3. I found this GitHub - sp0lsh/UE4ShaderPluginDemo: A tutorial project that shows how to implement HLSL Pixel and Com - But I am still looking through it to understand and extent it to load a simple model . Any pointers would be appreciated.

Do I understand it correct (on a broader level) or I am missing something here?


Hey @amitahire thanks for sharing your thoughts.

As far as I understood you, there are two parts to your questions:

  1. Loading and handling custom mesh data.
  2. Developing, including and using custom shader code.

Considerations on 1.:
I would recommend taking a look at the loading code for GLTF. You can find it implemented as an engine plugin under Engine/Plugins/Editor/GLTFImporter. There you see how Epic has structured its abstraction layer for loading 3d model data so it can be used with Unreal Engine. This part of the documentation might also be relevent for you Mesh Drawing Pipeline | Unreal Engine Documentation

Considerations on 2.:
We found that in most situations, putting our shaders in specific plugins has a lot of benefits, given that the plugin has an isolated set of features. Local modules come in handy, if you have strong dependencies to other parts of your local appliaction, yet want to have logical seperation, with the added benefit of faster turn-around/compile times (due to the fact that changes in the module only triggers a recompile of the module itself most of the time). We started a series of blog posts describing our setup.

Hope this helps you navigate your problem.

Hey amitahire! I’m a bit new to UE4 rendering as well.

I do think you have the approach a bit wrong - shaders are primarily used for operations on the GPU after you have already loaded your data. If you’re loading a mesh from a file that should be done all on the CPU side. In that case, the GLTFImporter plugin mentioned by blurryroots definitely seems like a good place to start.

If you’re still interested in using global shaders for another purpose, I’d take a look at GitHub - Temaran/UE4ShaderPluginDemo: A tutorial project that shows how to implement HLSL Pixel an . I’ve personally found it very helpful, and this version of the repository has been updated to work with some of the changes added in UE 4.22+.