Hi,
Noticed that under macOS and Metal api when calling texture2d ReadPixels() I have to use source rect coords with origin bottom-left (like OpenGL). Using Unity 5.6. Is this expected?
- SystemInfo.graphicsUVStartsAtTop is “true” for Metal (same as directx)
- googling shows that Metal has top-left coords origin (same as directx)
But with ReadPixels() source rect coods (not the destination) Metal behaves like OpenGL (bottom-left).
Aso did a test:
- filled a render texture top halp white, bottom half black
- read the topmost pixel into a texture2d and compared it to white
Let 's call it ReadPixelsYStartsAtTop test.
Did Debug.Log() of ReadPixelsYStartsAtTop and SystemInfo.graphicsUVStartsAtTop on different plaforms/api:

Only with Metal the results are different.
Hi monstercho,
I can confirm with Unity 2018.2.2f1 / iOS Metal SystemInfo.graphicsUVStartsAtTop returns TRUE, yet pixels are read from the bottom.
1 Like
does anybody know the solution?? whitch funtion can we use to detect the orition,so we can correctly set ReadPixels’s source rect.
This is pulled from a related terrain function, written by Unity, so most likely works for this:
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal || !SystemInfo.graphicsUVStartsAtTop)
{
alphamapTexture.ReadPixels(new Rect((float) sourceRect.x, (float) sourceRect.y, (float) sourceRect.width, (float) sourceRect.height), dest.x, dest.y);
}
else
{
alphamapTexture.ReadPixels(new Rect((float) sourceRect.x, (float) (sourceTex.height - sourceRect.yMax), (float) sourceRect.width, (float) sourceRect.height), dest.x, dest.y);
}
alphamapTexture.Apply();
1 Like