Count colored pixels of RenderTexture and get this data on CPU.
I need to calculate pixels of RenderTexture that are colored(alpha > 0). So I need to get pixels data inside C# script. My render texture is 16x16 pixels.
I have tried many things:
Texture2D.ReadPixels() - very slow.
Graphics.CopyTexture() - does not work with Texture2D.
AsyncGPUReadbackRequest - does not work on Android.
Texture2D.ReadPixels() but on a thread - works only on the main thread.
ComputeShader - does not work on low-end Android devices
Custom shader - can't read data directly from shader(GPU) so this also requires to read pixels from render texture.
So my guess that there is no way to get pixels to C# script fast. But maybe there is a way to just count colored pixels of the RenderTexture.
And again, the main problem is that reading pixels from RenderTexture to Texture is very slow. On Android it takes 10ms.
Your texture is barely 256 pixels, a simple ReadPixels should work fine on any device. Are you sure this is what is causing the performance issues? How many times are you doing it per frame?