Undeclared variables in shader when using BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT

I’m trying to add a new shader parameter struct. In a cpp file, I have

BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT(FSomeParams, )
	SHADER_PARAMETER...
END_GLOBAL_SHADER_PARAMETER_STRUCT()

IMPLEMENT_GLOBAL_SHADER_PARAMETER_STRUCT(FSomeParams, "SomeParams");

In a new global shader class

BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
	SHADER_PARAMETER_STRUCT_REF(FSomeParams, SomeParams)
END_SHADER_PARAMETER_STRUCT

Then in the .usf

float temp = SomeParams.Param0;

But I’m getting a shader compile error saying SomeParams is undefined. I’ve looked at existing examples of use of BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT, and I don’t see any definitions in shaders, so I assume it’s generated by the compiler, but it’s not working for me. Am I missing something here?

Thanks in advance!

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