I have a custom mesh I’m generating in C++ using a UMeshComponent subclass. It’s following more or less the format described at A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums. I would like to be able to create a custom shader for my mesh so that I can, for example, decode some vertex properties (texture weights basically) and pass them to a custom fragment shader (to do some blending).
It looks like this sort of thing is possible based on the documentation at Shader Development | Unreal Engine Documentation but there’s not enough information there for me to sit down and start writing anything so I have a couple of questions:
Has anyone else had any experience with this or can point me to a simple place to start learning about it?
How much control do you have, compared to say, writing standard HLSL or GLSL shaders?
How would a custom shader like this be able to integrate into the Editor’s Material Editor? For example, would I be able to parametrise any textures used in the shaders and set/edit them in the editor?
In fact, potentially all I need is a custom vertex shader in C++, the fragment shading could be done using the Editor’s blueprint-style material editing. Is it possible to create a custom vertex shader, the outputs (interpolated accordingly) of which can be read and used in the Material Editor?
Ok, so I’ve made some progress but I still have plenty of questions.
The first problem I was having was that I was using Visual Studio’s Find in Solution function to grep for strings but apparently it doesn’t search the .usf files (I’m new to UE so I had no idea what .usf files were for until now) so I wasn’t finding any matches for FVertexFactoryInput etc. Now that I’ve started reading through some of these shader files, the “Shader Development” documentation makes a lot more sense. I only have previous experience with GLSL but I can see more-or-less how the .usf files work.
It seems that Vertex Factories are basically the interface between a specific mesh type and a specific shader type (I’m still a little unsure exactly how ‘shaders’ relate to ‘materials’). So if I have a custom mesh type (defined as a component) I can create a scene proxy (which represents the mesh data in the rendering thread). That scene proxy will have a VertexFactory associated with it. It is in that vertex factory where the data in the vertex buffer is given context (by setting the components of the ‘Data’ member to contain the correct offsets and strides) similar to how glVertexAttribPointer() does it in OpenGL.
Up until this point, I have followed the “Procedural Mesh Generation” tutorial which has covered the topics above. However, now I want to edit and adapt it. Currently I stick four colours into the ColorComponent of the vertex factory and magically I can access that in the material editor in UnrealEd. Let’s say that I wanted 8 colour components instead of the four here. I can see how I would adapt the vertex factory and buffers to push this into the shader system (maybe I would add a second Colour2Component or switch from FColor to an 8 element array or similar) but how can I access this information in the material editor? Can I create a new material editor node and if so, how?
I know there’s a lot of question in there but if anyone has any ideas about any of them, I would appreciate any help.
Hi Matt, sounds like you are on the right track, take a look at my Fluid Surface Actor plugin in my signature. It uses a custom mesh with a custom vertex factory, and is completely compatible with the material editor, this may give you some clues on how to proceed forward. I also will be releasing the source code to my Metaballs rendering some point soon, which again uses another custom vertex factory, that also integrates the geometry shader (Which originally vertex factories do not use).
milliams -I too am trying to do custom shader work so can you give an update of what to do? Have you used NVIDIA Nsight Visual Studio Edition?
Ehamloptiran -the FluidSurface Plugin does not work any other examples available?