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

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,

Maybe provide a sample for others to test this also.
If not then a Bug report is needed to Unity3D asap.

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.

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!

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 :wink: that we will be doing more frequent “patch” releases to fix issues like that faster

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.

Thanks a lot Velvety! The quick fix did help…

Unity 4.5.1 contain the fix?

Unity 4.5.1 contain the fix?
it should

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.