Undeclared variables in shader when using BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT

When creating a BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT you need to use the uniform macro SHADER_PARAMETER_RDG_UNIFORM_BUFFER, on your FParameters you are using SHADER_PARAMETER_STRUCT_REF which is incorrect,

Here is the code to create the uniform struct:

TRDGUniformBufferRef<FUltratest> PassUniformBuffer = nullptr;
		{
			auto* RainbowUniformShaderParams = GraphBuilder.AllocParameters<FUltratest>();
			RainbowUniformShaderParams->TestTexture = Batch[0]->GetRDGTextureUAVRef(GraphBuilder);
			PassUniformBuffer = GraphBuilder.CreateUniformBuffer(RainbowUniformShaderParams);
		}

When adding the pass to the graph builder you will be asked to include the parameters in one of their Lambdas anyway!

And finally one thing, it took me a while to figure out was the fact that you have to include #include “/Engine/Private/Common.ush” on your .usf, with that you should be able to access the struct.

1 Like