Accessing GBuffer from C++

For a university project I am working on implementing an RGBD camera as a plugin for Unreal.

Right now the plugin works by using three SceneCaptureComponent2Ds in order to capture a fully rendered image of the scene, depth data and an object mask. I had some issues with SceneCaptureComponents (e.g. the captured image being darker than ingame), so my instructor suggested “skipping the middle man” getting the data directly from the GBuffer.

I found GetGBufferData in DeferredShadingCommon.ush, though I don’t whether it’s possible (and if yes, how) to access that function from within regular C++ code.

I also am aware of the option View Mode → Buffer Visualization Mode menu in the editor and tried to investigate how that is implemented, hoping to find some code to have a look at, but so far I haven’t found anything.

1 Like

Hello!!!

This is another way than not to use SceneCapu:This is Base On Unreal4.18

Source Code by BaiPaoXiaoDao

    	ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER(
    		DZRenderSutioBP_InterceptSceneBaseColor,
    		UTexture2D*, vTextureAsset, TextureAsset,
    		{
    			/*if (!IsInRenderingThread())
    			return;*/
    			FRHICommandListImmediate& RHICmdList = GRHICommandList.GetImmediateCommandList();
    			//计数加一避免Render完成后直接清空了GBuffer,但会慢一帧,你猜
    			FSceneRenderTargets::Get(RHICmdList).AdjustGBufferRefCount(RHICmdList, 1);
    			static const FString ScrollingMessage(TEXT("Hello World: "));
    			GEngine->AddOnScreenDebugMessage(-1, 0.2f, FColor::Red, ScrollingMessage);
    			FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get(RHICmdList);
    			if (SceneContext.GBufferA)
    			{
    				FTexture2DRHIRef vTextTarget = SceneContext.GetGBufferATexture();
    				FString vSiceStr = FString::Printf(TEXT("FSceneRenderTargets GBufferA Size = %d*%d"), vTextTarget->GetSizeX(), vTextTarget->GetSizeY());
    
    				GEngine->AddOnScreenDebugMessage(-1, 0.2f, FColor::Red, vSiceStr);
    			}
    			//移除
    			FSceneRenderTargets::Get(RHICmdList).AdjustGBufferRefCount(RHICmdList, -1);
    		}
    	);

我应该将这段代码添加到哪里?

可以添加到扩展于UPrimitiveComponent的组件,收集绘制命令的地方

我可以通过这种方法获取深度的数据吗?因为我就是希望模仿这种方法得到深度数据。

具体是在那个函数里面我还是不清楚

4.25的ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER宏命令好像被弃用了

你好,请问你有这段代码原博客的链接吗?