Hi there.
I’m calling ReadPixels on a rendertexture in my code. Now, in the editor, I get maybe (average) 2-3ms impact from this. Not entirely cheap, but the rest of the game’s code takes this into account.
Now, problem occurs when I call the function in a standalone build. That 2-3ms balloons into a 15-30(!)ms spike!
This is just for reading an 8x8 pixel square!
Interestingly, neither game resolution nor the size of that square have any effect on the command.
This is, of course, really affecting things ![]()
I’ve tried nearly every approach to the ReadPixels that I can think of or find! Yielding stuff, calling in frame, calling on postrender, setting rendertexture to active outside of camera’s target textured, setting the camera to render constantly, setting camera to render on demand, pulling from screen instead of rendertexture, pixels32…
It’s quite an endless list ![]()
I’ve submitted this as a bug report, but I’m posting here just in case anyone has any ideas or experience with this. It’s an issue that I’ve repeated on 3x different systems - though one of those computers gave me a alternating spikes - one call would be 2ms, the next 20.
In game, the function is called every ~9 frames. I stripped everything down and isolated things to run outside the game code. This is what I’ve been running to test:
using UnityEngine;
using System.Collections;
public class _pixelstest : MonoBehaviour {
public bool grab;
public Renderer display;
public RenderTexture textureofrender;
public Texture2D tex;
void Awake() {
tex = new Texture2D(8,8);
}
void Update() {
if(Input.GetKeyDown ("space")) {
grab = true;
}
}
void OnPostRender() {
if(grab){
RenderTexture.active = textureofrender;
tex.ReadPixels(new Rect(0, 0, 8, 8), 0, 0);
tex.Apply();
textureofrender.DiscardContents();
//Debug.LogError ("It Just ReadPixels");
grab = false;
}
}
}