Get GBuffer Information

I would like to get the Information stored in the GBuffer. I saw some approaches using custom HLSL nodes, e.g.:

MaterialFloat2 UV = MaterialFloat2(ScreenAlignedPosition(Parameters.ScreenPosition).xy);

FGBufferData GBData = GetGBufferData(UV, false);
return GBData.Metallic;

But I get the errors:

[SM5] /Engine/Generated/Material.ush(1271,14-19): error X3000: unrecognized identifier ‘GBData’

[SM5] /Engine/Generated/Material.ush(1271,1-12): error X3000: unrecognized identifier ‘FGBufferData’

Has anyone an idea?

1 Like

GetGBufferData() is defined in DeferredShadingCommon.ush.

For materials, it is only included, if material has access to scene textures, and thus, it will only work in post process or translucent materials.

Hello There!
I know that this is an old thread but…

In UE5.3, I defined a custom material node to fetch the underlying BaseColor from a Transluency Material:

FGBufferData GBData = GetGBufferData(UV, false);
return GBData.BaseColor;

when I connect the node, UE5.3 crash hard:

[2024-07-12T07:56:35.031Z]LogOutputDevice: Error: Ensure condition failed: ShaderTableHash == 0 || UniformBufferHash == ShaderTableHash [File:D:\build\++UE5\Sync\Engine\Source\Runtime\D3D12RHI\Private\D3D12Commands.cpp] [Line: 77] 
[2024-07-12T07:56:35.031Z]LogOutputDevice: Error: Invalid uniform buffer FOpaqueBasePassUniformParameters bound on PixelShader at index 2.
[2024-07-12T07:56:35.031Z]LogStats:             FDebug::EnsureFailed -  0.000 s
Fatal error: [File:D:\build\++UE5\Sync\Engine\Source\Runtime\RHICore\Public\RHICoreShader.h] [Line: 147] 
Uniform buffer bound to slot 2 is not what the shader expected:
	Bound                : Uniform Buffer[FOpaqueBasePassUniformParameters] with Hash[0x09880f28]
	Expected             : Uniform Buffer[SceneTexturesStruct] with Hash[0x09700e08]
	Shader Name          : <unknown>
	Layout CB Size       : 2432
	Layout Num Resources : 49
	Resource Types       : 9 8 5 8 16 16 16 16 9 8 5 8 16 16 16 16 9 8 5 8 5 8 5 8 5 8 5 8 9 8 5 8 9 8 13 13 9 9 9 9 9 9 9 8 8 8 5 8 16

Also tested:

FScreenSpaceData ScreenSpaceData = GetScreenSpaceData(UV, false);
return ScreenSpaceData.GBuffer.BaseColor;

with exact same results…

Of course, I have no idea what does this mean :slight_smile:
Any idea someone?

Browsing the Forum, I realise that I may have access to the SceneTexture Node in Transluent material…

And of course, it works and provide access to all GBuffer I need…