Search Unity

  1. Dismiss Notice
  2. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  3. Dismiss Notice

RenderTexture coordinate system origin is bottom-left on iPad, but top-left on iPhone 5S

Discussion in 'iOS and tvOS' started by eduardocoelho, Dec 19, 2015.

  1. eduardocoelho

    eduardocoelho

    Joined:
    Dec 18, 2013
    Posts:
    10
    I'm using RenderTexture to take screenshots in my Unity game.

    I have successfully managed to draw the Camera contents to the target RenderTexture and grab part of the RenderTexture's contents (i.e.: A Region Of Interest) using the code below:

    Code (csharp):
    1.  
    2. RenderTexture currentActiveRT =RenderTexture.active;
    3.  
    4. var renderTex =newRenderTexture((int)renderTexSize.x,(int)renderTexSize.y,24,RenderTextureFormat.ARGB32);
    5.  
    6. CameraScreenshot.targetTexture = renderTex;CameraScreenshot.gameObject.SetActive(true);CameraScreenshot.Render();
    7.  
    8. RenderTexture.active = renderTex;
    9.  
    10. // 4. Create the final output Texture, which will have the the ROI drawn in the final size.var tex =newTexture2D((int)screenshotSize.x,(int)screenshotSize.y,TextureFormat.RGB24,false);
    11. tex.ReadPixels(fROI,0,0,true);
    12.  
    13. // 5. Restore context and release resources.
    14. RenderTexture.active = currentActiveRT;
    15.  
    Everything works as expected on both the Unity Editor and the iPad device, however, on my iPhone 5S device the final output gets wrong because a different region of the RenderTexture is used. After some debugging I realised that on both Editor and iPad the origin of the RenderTexturecoordinate system is bottom-left (upwards) but on the iPhone it is top-left (downwards).

    Does anyone know how can I fix that?

    Original S.O. thread: http://stackoverflow.com/questions/...tem-origin-is-bottom-left-on-ipad-but-top-lef
     
  2. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,437
    You are wrong in your reasoning - it is because of metal vs opegl es difference.
    well you can always check if you are running on metal or gles. Though i agree we should look into handling it better
     
  3. eduardocoelho

    eduardocoelho

    Joined:
    Dec 18, 2013
    Posts:
    10
    Thanks for the reply, I added the following code as a workaround.

    Code (csharp):
    1.  
    2. if(SystemInfo.graphicsDeviceVersion.StartsWith("Metal")){
    3.     var metalY=(1f-nROI.y-nROI.height);
    4.     nROI=newRect(nROI.x,metalY,nROI.width,nROI.height);
    5. }
    6.  
    Although it's a weird solution it's working now.
     
  4. eduardocoelho

    eduardocoelho

    Joined:
    Dec 18, 2013
    Posts:
    10
    Looks like the screenshot was corrupted (see attached image). Any idea why could it happen?
    I'm invoking the screenshot procedure as a coroutine:
     

    Attached Files:

  5. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,437
    that looks weird indeed. Please create small repro project (as in - just cube or smth and scripts you need to do your magic) and bug report it (drop case number here so i dont miss it)
     
unityunity