How to resolve HLSL programming [FSimpleShaderPS] Calculated Size: 280, Real Size: 304 error?

IMPLEMENT_SHADER_TYPE(, FSimpleShaderVS, TEXT("/YV12Shaders/Private/SimpleShader.USF"), TEXT("MainVS"), SF_Vertex)
IMPLEMENT_SHADER_TYPE(, FSimpleShaderPS, TEXT("/YV12Shaders/Private/SimpleShader.USF"), TEXT("MainPS"), SF_Pixel)
class FSimpleShaderPS : public FSimpleShader
{
	DECLARE_SHADER_TYPE(FSimpleShaderPS, Global);
public:
	FSimpleShaderPS() {}

	FSimpleShaderPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
		: FSimpleShader(Initializer)
	{
		YTextureVal.Bind(Initializer.ParameterMap, TEXT("YTextureObj"));
		UTextureVal.Bind(Initializer.ParameterMap, TEXT("UTextureObj"));
		VTextureVal.Bind(Initializer.ParameterMap, TEXT("VTextureObj"));
		YTextureSampler.Bind(Initializer.ParameterMap, TEXT("YTextureSampler"));
		UTextureSampler.Bind(Initializer.ParameterMap, TEXT("UTextureSampler"));
		VTextureSampler.Bind(Initializer.ParameterMap, TEXT("VTextureSampler"));
	}
public:
	FShaderResourceParameter YTextureVal;
	FShaderResourceParameter YTextureSampler;
	FShaderResourceParameter UTextureVal;
	FShaderResourceParameter UTextureSampler;
	FShaderResourceParameter VTextureVal;
	FShaderResourceParameter VTextureSampler;
};

#include "/Engine/Public/Platform.ush"

void MainVS(
	in  float3  InPosition : ATTRIBUTE0,
	in  float4  InUV : ATTRIBUTE1,
	out float4  OutPosition : SV_POSITION,
	out float2  OutUV : TEXCOORD0,
	)
{
	OutPosition = float4(InPosition,1);
	OutUV       = InUV;
}

Texture2D    YTextureObj;
Texture2D    UTextureObj;
Texture2D    VTextureObj;
SamplerState YTextureSampler;
SamplerState UTextureSampler;
SamplerState VTextureSampler;


void MainPS(
	in  float2 uv : TEXCOORD0,
	out float4 OutColor : SV_Target0)
{
	float3 yuv;                                                             
	float3 rgb;                                                             
	yuv.x = YTextureObj.Sample(YTextureSampler,uv).r;										
	yuv.y = UTextureObj.Sample(UTextureSampler,uv).r - 0.5;                               
	yuv.z = VTextureObj.Sample(VTextureSampler,uv).r - 0.5;                               
	                                                                      
	rgb = float3x3( 1,       1,         1,                                    
	          0,       -0.39465,  2.03211,		 						  
	          1.13983, -0.58060,  0) * yuv;								                           
	OutColor = vec4(rgb.x,rgb.y,rgb.z,1.0f);                          
}

Hi. I came across the same issue and here how I solved it.

If you go to this file in engine plugins: Compositing\LensDistortion\Source\LensDistortion\Private\LensDistortionRendering.cpp
You will notice that parameters are defined with LAYOUT_FIELD.

Adding solves the problem.
Nevertheless, this is the legacy/old method of working with shaders. A more recent example on how to create shader parameters can be found in this class:
class FLightmapPathTracingRGS : public FGlobalShader.

Cheers,
P

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.