Download

How to access the z-buffer by altering the UE4 source code?

I want to access the pixel data of every frame, and now I have gotten the color buffer (via Viewport->ReadPixels).
But it seems difficult to read the depth buffer. I googled the solution, and some one said that I have to edit the UE4 source code.
Here is what I want to do:

  1. Read the Z-buffer which includes the distance from the player’s camera to every single pixel.
  2. Locate the source code that implemented the Z-buffer algorithm, so that I can know what Actor a pixel is rendering (e.g. a pawn, or a static mesh chest).

Is there any way to do this?
Thanks.

Did you read pixel in your custom viewport class’s Draw function. Or does it work anywhere. I get a crash while trying to call the ReadPixel of viewport.

Yes, I call a custom function in void UXXXViewportClient::Draw(FViewport * Viewport, FCanvas * SceneCanvas).