Custom render mode, light pass accumulator buffer

Hi,

I have a custom render mode where I need to change how light is rendered. The important part is in DefferedLightingCommon.ush in AccumulateDynamicLighting method. I would like to store some of light data of the currently rendered light to be available for the next light. I enabled CustomData GBuffer and thought i could use it as an intermediate buffer, but if I do something like “GBuffer.CustomData.x = Shadow.SurfaceShadow;” it looks like the value is not written into the Gbuffer custom Data.

Does this mean g-buffer data can’t be modified after base pass or I’m doing something wrong?

FLightAccumulator AccumulateDynamicLighting(
                //.....
		/*check condition for previous GBuffer.CustomData.x val
		...
		*/		
		LightAccumulator_AddSplit(LightAccumulator, Lighting.Diffuse, Lighting.Specular, Lighting.Diffuse, MaskedLightColor * Shadow.SurfaceShadow, bNeedsSeparateSubsurfaceLightAccumulation);
		LightAccumulator_AddSplit(LightAccumulator, Lighting.Transmission, 0.0f, Lighting.Transmission, MaskedLightColor * Shadow.TransmissionShadow, bNeedsSeparateSubsurfaceLightAccumulation);

		GBuffer.CustomData.x = Shadow.SurfaceShadow;
		
		LightAccumulator.EstimatedCost += 0.4f;		// add the cost of the lighting computations (should sum up to 1 form one light)
	#endif

Thank you.

For anyone having the same problem, instead of trying to modify a gbuffer, I created two new textures, one as an input and one as output to a pixel shader. Once the shader writes out to output texture, I copy the content to the input texture and move on to the next pass.

Some relevant files and code:

//////////////////create in and out textures, LightRendering.cpp////////////////
const FRDGTextureDesc OutTextureDesc(FRDGTextureDesc::Create2D(SceneTextureExtent, PF_R32_FLOAT, FClearValueBinding::White, TexCreate_ShaderResource | TexCreate_UAV | TexCreate_RenderTargetable));
FRDGTextureRef OutTexture = GraphBuilder.CreateTexture(OutTextureDesc, TEXT("OutTexture"));
const FRDGTextureDesc InTextureDesc(FRDGTextureDesc::Create2D(SceneTextureExtent, PF_R32_FLOAT, FClearValueBinding::White, TexCreate_ShaderResource | TexCreate_UAV | TexCreate_RenderTargetable));
FRDGTextureRef InTexture = GraphBuilder.CreateTexture(InTextureDesc, TEXT("InTexture"));

//after adding light pass
AddCopyTexturePass(GraphBuilder, OutTexture, InTexture);
////////////////////////////////////////////////////////////////////////////////////////

///////////class FDeferredLightPS : public FGlobalShader/////////////
//add parameters to pixel shader
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, InTexture)
SHADER_PARAMETER_SAMPLER(SamplerState, InTextureSampler)

//FDeferredLightPS::FParameters GetDeferredLightPSParameters
//init params
Out.InTexture = InTexture;
Out.InTextureSampler = TStaticSamplerState<SF_Point, AM_Wrap, AM_Wrap, AM_Wrap>::GetRHI();
///bind out texture
Out.RenderTargets[1] = FRenderTargetBinding(OutTexture, ERenderTargetLoadAction::EClear);
////////////////////////////////////////////////////////////////////////////////////////

///////////DeferredLightPixelShaders.usf/////////////
//declare in texture
Texture2D       InTexture;
SamplerState    InTextureSampler;
//define out texture
void DeferredLightPixelMain(float4 SVPos : SV_POSITION,nointerpolation uint NodeCount  : DISPATCH_NODECOUNT,nointerpolation uint2 Resolution : DISPATCH_RESOLUTION, out float4 OutColor : SV_Target0, out float OutTexture : SV_Target1)
////////////////////////////////////////////////////////////////////////////////////////