How to speed up readPixelsAsync?

Hello,

I want to read pixels in each frame and the original API readPixels is very slow. I find some similar questions like this and this. But these two questions seem have no good approach to read pixels from texture quickly.

Here is my playground: https://playground.babylonjs.com/#ZS6ZGL#10 . It takes about 10~20 ms to read 4x4 pixels. I wonder if there is any approach to speed up read pixels in nowadays.

Thanks!

Unfortunately we are using barebone webgl here and I have no other idea on how to boost that process. Data need to go from GPU memory to CPU memory and it is a long trip

Other question maybe: can you avoid that read? maybe do what you need with a shader?

Thanks, here is another strange thing. In this playground: https://playground.babylonjs.com/#ZS6ZGL#22 readPixels function seems cost fewer millisecond compare with the old PG. The only different in this PG is a video Texture is used. Why does this happen?

It is unfortunately all Angle and WebGL magic we do not have any control on at the Engine level :frowning: but yes it is pretty strange indeed.

1 Like