Get average color from a Render Target 2D

So, I’m on my way to recreating something similar to the PowerWash Simulator. I already have the painting/erasing from surfaces part done. What I have to do now is read the average color from the mask render target. I have a render target that uses white or black for masking the material of the surface. I tried some things like directly reading the pixels from it using “Read render target pixel,” but it’s a really heavy operation and affects a lot of the performance. I also tried rendering the RT into another RT that is 1x1 pixel, but this only gets the pixel from the corner, and even reading only 1 pixel per second is a heavy task for the GPU and CPU. I also tried using CPP and the Auto Generate MipMaps from the RT, but using that option caused the mask to disappear in the distance and didn’t quite work with CPP.

If someone has the solution for this, I would appreciate it a lot, thanks!

running into the same issue, did you find a good solution?

Checking with my peers, we think your logic is close, changing the order on how the render target is done might be the fix.

As you mentioned, Read Render Target Pixel is quite heavy, but that’s regardless of it scanning 1 pixel or 10k, so it won’t matter how much is in front of it. Instead, test by adding an intermediate step:

  • Leave your RT mask as it is, with MipMaps disabled

  • Add another RT in the middle, same size as the mask, and make it a Float, with Auto Generate Mips set to On

  • From there, test using Draw Material to Render Target between your Mask and the middle RT

  • Since the middle RT has auto mips, UE will make smaller and smaller copies of the image, until it’s a single, average pixel

  • Add one final RT, size 1x1, and draw into it with a material that samples from the middle RT, with Mip Value Mode set to MipLevel

  • Read that final 1x1 RT a few times per second, and that should do the trick