Wrong Material Values in Custom FMaterialShader

I’m trying to create a custom FMaterialShader so I can access material values in a custom full screen shader outside of the post-process steps.

I’ve got it working for the most part however I’m not getting correct/any values when I go to access the material properties.

This is what I have for the pixel shader, including bits that are used for testing. Right now I’m just trying to get the correct BaseColor result but that’ is wrong no matter what channels I use for it

void OutlinePS(
	in float4 SvPosition : SV_POSITION,
	out float4 OutColor : SV_Target0)
{
	ResolvedView = ResolveView();

	const float2 UVPos = SvPositionToViewportUV(SvPosition);
	
	FMaterialPixelParameters MaterialParameters = MakeInitializedMaterialPixelParameters();
	FPixelMaterialInputs PixelMaterialInputs;
	
	// This is the call to the material graph
	CalcMaterialParameters(MaterialParameters, PixelMaterialInputs, SvPosition, true);

	float3 Colour = GetMaterialBaseColor(PixelMaterialInputs);
	float Alpha = GetMaterialOpacity(PixelMaterialInputs);
	float3 Emissive = GetMaterialEmissive(PixelMaterialInputs);

	Colour = PixelMaterialInputs.BaseColor;

	float4 ScreenPosition = SvPositionToResolvedScreenPosition(SvPosition);
	float3 TranslatedWorldPosition = SvPositionToResolvedTranslatedWorld(SvPosition);
	
	OutColor = float4(UVPos.xy, Colour.xy);
	// OutColor = ScreenPosition;
	// OutColor = float4(TranslatedWorldPosition, 1);
}

When I open it up in RenderDoc, I can see the input as I would expect, so it looks like it’s definitely sampling it but the result is the issue. I don’t know if it matters but RenderDoc is picking up the input texture as B8G8R8A8_TYPLESS

This is the input material that I’m using for testing

The texture is just a UV image on the R and G channels.

Anyone have any ideas?

Alright found the issue, got it from looking at the code used in this repo: heyx3/ExtendedGraphicsProgramming at bc613297401a08fa373d7322255aa93c9e4a17be

Also good read for this information from the same person: Advanced Graphics Programming in Unreal, part 5 | by William Mishra-Manning | Jun, 2025 | Medium

Anyway, so the issue is here

FMaterialPixelParameters MaterialParameters = MakeInitializedMaterialPixelParameters();
FPixelMaterialInputs PixelMaterialInputs;
	
// This is the call to the material graph
CalcMaterialParameters(MaterialParameters, PixelMaterialInputs, SvPosition, true);

You need to set the UV coordinates, which get set with the interpolator shenenigans but I did it this way

FMaterialPixelParameters MaterialParameters = MakeInitializedMaterialPixelParameters();
MaterialParameters.TexCoords[0] = SvPositionToViewportUV(SvPosition);
	
FPixelMaterialInputs PixelMaterialInputs;
	
// This is the call to the material graph
CalcMaterialParameters(MaterialParameters, PixelMaterialInputs, SvPosition, true);
1 Like