Hello, I’m looking for a way to make my material output data to UAV. (Can’t find any block that can do it :()Or if it’s not possible, to create a compute shader. If creating compute shader, how can i compile it ? should i create a FMaterial from FComputeShader ?
As a result i want to be able to modify data for each vertex in runtime from GPU.
Any informations beyond the documentation in UE4 about custom shaders is greatly appreciated.
If I understand you correctly, you want to be able to evaluate a material graph for each vertex each frame. You didn’t say where it would get used (as vertex input to vertex shader or shader resource view to shader).
It’s possible to implement this with some C++, but it’s probably not going to be easy.
What you need is a new FMaterialShader type, eg
class FShadeVerticesCS : public FMaterialShader
{
DECLARE_SHADER_TYPE(FShadeVerticesCS ,Material);
public:
Lucky for you the material compiler already supports compiling the emissive input for a compute shader with CompiledMP_EmissiveColorCS. In the past the light function shader used to be compiled for compute shaders and it made use of this, it’s very similar to what you want to do.
Then there’s a whole bunch of other places that you would have to change.
Hi !
First of all thanks for a quick answer!
My problem boils down to this:
We have one shader(vertex or compute) which computes some data for each vertex and store this data somewhere(UAV - or somehow another way?). Computations done only when it is needed(not every frame), so i would like to call a function to compute that data. This shader doesn’t need to be visible in material editor - it can be hidden in my actor’s implementation. This code once written shouldn’t be modified.
Another shader uses this data(by vertex input or UAV - i think using UAV would be easier? ). This one is called every frame. This material also must be visible in material editor, for others, to modify it’s look. The only problem here is to get that data the first shader computed(I want to modify each vertex based on it - somehow in vertex shader).
Ok, so i got my usf file,
got my class FAwesomeMaterial: public FMaterialShader
and got
IMPLEMENT_SHADER_TYPE(, FAwesomeMaterial, TEXT(“AwesomeMaterial”), TEXT(“ComputeThis”), SF_Compute);
Everything good so far, but when i run it it throws me: Assertion failed: !bInitializedSerializationHistory
which when you look it up in source code tells you this:
// This will trigger if an IMPLEMENT_SHADER_TYPE was in a module not loaded before InitializeShaderTypes
// Shader types need to be implemented in modules that are loaded before that
check(!bInitializedSerializationHistory);
so my question is how can i make my module load before InitializeShaderTypes?! I’m guessing my whole game is one module? OR i have to make another module inside my game? If yes, then how?!
Thanks I’ll add that to the assert message for people who run into this in the future. And hopefully we can support shader types in non-startup modules in the future.
You need to enqueue a rendering command from the event, and call the RHI functions from within the rendering command. Look around for examples, lots in FScene implementation.