Search Unity

Unity 4.5 RenderTexture black on iOS (worked fine in Unity v4.4.3)

Discussion in 'iOS and tvOS' started by Velvety, May 29, 2014.

  1. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    In our game we are rendering out a sprite atlas texture with RenderTexture by doing multiple passes. We loop through all our sprites and render them one at a time to the same texture with the camera's clearflags set to Nothing (so that previous data rendered does not get overwritten). This works fine in editor. It also worked fine with Unity v4.4.3 on iOS.

    But with Unity 4.5 this breaks on iOS. Now everything turns black EXCEPT for the last pass. Whatever we render into the RenderTexture on the last pass looks fine, everything else is just black.

    Clearly something has changed with how RenderTexture is working on iOS in Unity 4.5.

    Does anyone at Unity know what has changed or how to fix this? We've spent about 8 hours today trying various things and we can't figure out any way to get this working on iOS. It used to work fine.

    Thanks,
     
  2. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Maybe provide a sample for others to test this also.
    If not then a Bug report is needed to Unity3D asap.
     
  3. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Our setup right now is actually loading data from a server via JSON, parsing that and loading the correct asset bundle and then using a series of coroutines to create the sprite atlas from RenderTexture. So it is not a simple thing to pull out for an example. However, we will try to recreate it in a simple version we can post here and as a Unity bug (because it does seem like a Unity 4.5 bug). Stay tuned, that will be coming.
     
  4. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    We have made a small project to reproduce the bug and submitted it to Unity as a bug here: http://fogbugz.unity3d.com/default.asp?610557_ivq5v0r6ct1p2rh9

    In the meantime if anyone has any suggestions or possible work arounds please share. Our game is scheduled to be released in 2 weeks and this is a major blocker, thanks!
     
  5. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    Just to put info to more people eyes: we slightly overdid TBDR-related optimizations to skip restore gpu-mem->tile. The gist of it - if you render to RT out of draw cycle, e.g Update (or in draw cylce if you start rendering to RT immediately) - RT will be forcibly cleared. We have a fix internally it will be released soonish (i heard the news ;-) that we will be doing more frequent "patch" releases to fix issues like that faster
     
  6. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Thanks for all your help Alexey.

    If anyone needs a quick fix for this, our solution was to yield return new WaitForEndOfFrame() before each render texture pass.
     
  7. DerWoDaSo

    DerWoDaSo

    Joined:
    May 25, 2009
    Posts:
    131
    Thanks a lot Velvety! The quick fix did help...
     
  8. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Unity 4.5.1 contain the fix?
     
  9. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    >>Unity 4.5.1 contain the fix?
    it should
     
  10. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
  11. martin-sustek

    martin-sustek

    Joined:
    Jul 16, 2014
    Posts:
    14
    Hi, I have similar problem but in a little more complicated situation.

    I want to render an object seen by a camera into PNG file with transparency. Because I was unable to render a texture with transparency (it had either wrong colors or alpha channel), I have 2 cameras and render 2 textures, one in RGB (this has good colors) and another one in RGBA (this has good alpha information). Then I combine these to textures pixel by pixel in memory (I read pixels form alpha texture and in case of non-transparent color I rewrite their RGB channels by values from color texture) and save the RGBA result into a file.

    This whole mechanism worked well until 4.5. But in 4.5. (even in 4.5.2) it draws my object on black background instead of transparent. This happens only on iOS (Android build and editor works well in every version). I have tried both WaitForEndOfFrame and OnGUI.

    So, what is the correct way to render from camera into texture (Camera.Render(), Texture2D.ReadPixels()), edit this texture programmatically (Texture2D.GetPixel() and Texture2D.SetPixel()) and save it to the file (Texture2D.EncodeToPNG()) in 4.5?

    UPDATE: It looks like problem is not in editing textures, but even RGBA texture has no transparency (it has just black background). So maybe on iOS camera is not capable to capture transparency into texture.
     
    Last edited: Jul 16, 2014