Search Unity

RenderTexture not working on iOS and Android Unity 4.2.0f4

Discussion in 'Editor & General Support' started by The-IT664, Jul 26, 2013.

  1. pkettu

    pkettu

    Joined:
    Mar 9, 2015
    Posts:
    2
    I am. This helped a lot. Thank you!
     
  2. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    540
    I Have the same problem too. But i can't use 5.0.2 because critical feature has been fixed just in 5.1.f3 for me.
     
  3. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    I *just* got my RenderTexture to appear on an Android dev build, using Unity 5.1.1f1. I was running into problems earlier, hence stumbling upon this thread, but they had to do with XML loading and DeviceOrientation issues, so they were completely unrelated.
     
  4. SoftAnswers

    SoftAnswers

    Joined:
    Aug 10, 2015
    Posts:
    3
    Same Issue on 2d Texture and Im Using 5.1.3 version any fix for this?
    this is insane if tilll 5.1.3 and they didnt fix it!
     
    AbandonedCart likes this.
  5. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    so, long thread and i still dont get what "Same Issue" are we talking about. Can anybody give me case number with *small* repro attached?
     
  6. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
    We're having rendertexture problems on iOS using Unity v5.2.0p1 with shaders that use a GrabPass - we're not setting up our own rendertextures or cameras or targets or otherwise manually doing anything.

    When antialiasing is enabled in the quality settings, anything rendered to the screen before the shader using the GrabPass turns black (in our case, everything opaque as we're running shaders to distort/refract the background). Without antialiasing everything seems to run fine.

    (@Alexey, bug filed Case 729439.)

    Maybe related to http://issuetracker.unity3d.com/iss...ng-causes-black-screen-with-gles-error-0x0500 ?
     
    Last edited: Oct 15, 2015
  7. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    >>We're having rendertexture problems on iOS using Unity v5.2.0p1 with shaders that use a GrabPass - we're not setting up our own rendertextures or cameras or targets or otherwise manually doing anything.

    And this is where you are going wrong ;-). Honestly - while gab pass sounds cool and dandy i would prefer users to actually use RTs and write explicitly exactly what they want to do. But lets move on from from me ranting

    >>(@Alexey, bug filed Case 729439.)
    oh can i whine? it has JUST the shader - now i need to go create scene etc - not hard, sure, but that make me think maybe my time is better spent elsewhere etc - so if you want unity devs to love you - spend some time to create repro project as this will help us jump right into the issue.

    >>Maybe related to http://issuetracker.unity3d.com/iss...ng-causes-black-screen-with-gles-error-0x0500 ?
    yeah - on gles there was issue *in general* with AA handling + RT. Though i am honestly not sure that i did check grabpass + AA when doing this fix (so yeah - need to look into it).

    Now about metal: sadly AA+grabpass will not work in near future. If you need a bit more technical info (and read about metal a bit) read on. Essentially you cannot do ANYTHING with AA rt unless you resolve it. Now, resolve is "store" action on render encoder and everything would be good if not a tiny caveat: resolve is destructive - if you do resolve AA data is essentially gone. Now what grabpass + AA is doing is: render in AA, stop encoder (be if for read pixels or copy pixels or blit or whatever magic) [here source AA is killed], do magic, continue rendering [but OH NO, AA data was destroyed already]. Surprisingly we do have plans on how to approach it (apple engineers proposed some possible workarounds), but for now you are kinda stuck with destructible AA.
     
  8. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
    Fair enough... perhaps the shader docs could suggest this approach :) We're wanting to refract pretty much our entire opaque pass for some transparent effects - is rendering everything to a texture and then blitting that to screen and then applying transparent effects over it the way to go here?

    Yep, also fair enough :) I've done that before but haven't had time with this particular bug yet. Also, I did reply to the case email with more stuff but it never appeared in the bug tracker.

    Update: I've submitted an example project.

    Fingers crossed you can magically fix something...

    I don't know much about Metal at the low end, but this sounds pretty annoying for your rendering pipeline.

    Thanks a lot for replying.

    I made an example project showing the problem on iOS - it has been submitted as a bug report referencing the original case 729439. It's been assigned Case 736412.

    Edit: See below for QA/Alexey response and advice.
     
    Last edited: Nov 14, 2015
  9. Suguma

    Suguma

    Joined:
    May 29, 2015
    Posts:
    26
    Ok, I also filled a bug case too, for I also have the problem and do not use GrabPass.
    @Alexey (Case 740620)

    I'll explain again what is going on for me.
    I call for Camera.Render into a texture and that texture comes out either out of place (like with a weird offset) or even completely black (which is usually the case).
    It's as simple as that. This screenshot shows the bug very clearly.
     

    Attached Files:

  10. fcloss

    fcloss

    Joined:
    Dec 1, 2011
    Posts:
    192
    Hi @Alexey .

    I work with @Suguma and we are experiencing this problem for a while already and we were completely stuck to version 5.0.2 to keep working and updating our product (TacticalPad).

    Now, it is basically impossible to keep using this version, not possible anymore to find a suitable environment for OSX , XCode, Unity and iOs versions compatibility.

    @Suguma has created the project attached on the previous post with a cut version of TacticalPad where it uses the RenderTexture and is having the issue with the black resulting texture. I am almost begging you to have it tested on a high priority because it is affecting our product roadmap and causing serious impacts.

    We are Unity clients since its version 2, so we keep a lot of respect for you guys and really count on you to support us on this so delicate moment =)

    Thanks in advance
    Kind Regards,
    Fernando
     
  11. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    >>Ok, I also filled a bug case too, for I also have the problem and do not use GrabPass.
    >>@Alexey (Case 740620)
    well can i have small repro that actually illustrates the issue - there are so many things in there that i am bit reluctant to even look into it (i will get to it, sure, but when you need to balance gazillion of bugs/features/etc - "smaller" things kinda take priority). I'll poke qa to check and simplify repro (but you can be proactive, you know ;-))
     
  12. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
    hey Alexey,

    did you get around to checking on our submitted repo? Did it show the issue with grabpass + antialiasing on iOS at your end?
    (Original case 729439. Repo assigned Case 736412)

    Edit: See below for QA/Alexey response and advice.

    cheers,

    // greg
     
    Last edited: Nov 14, 2015
  13. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    >>Repo assigned Case 736412
    but thats about grabpass + AA? works for me (though i'm trying 5.3 sure) did you recheck it on patch releases?
     
  14. fcloss

    fcloss

    Joined:
    Dec 1, 2011
    Posts:
    192
    @Alexey Barkin we can get the repro project smaller, we tried to keep most of the core of the UI to illustrate it, but it is already pretty simple. You may have had a different impression when you saw the issue report, because of the number of lines or whatever, but it is pointed out there the line number of the moment RT is used and the step by step of the execution. If you could open it, you will probably change the first impression of complexity of the project.

    Regards,
    Fernando
     
    Last edited: Nov 6, 2015
  15. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
    Thanks a lot for taking a look at the repo, @Alexey. We've not tried the latest patch releases as a few previous patch releases for 5.1.x and 5.2.x kept breaking Unity UI. It would be great if the new patches or 5.3beta magically fixed the grabpass+AA problem so I'll check them out. The bug existed for us from around 5.1.x - 5.2.2f1 (the current stable build we're using) when we noticed it causing problems in iOS builds. It might have existed before but we weren't building for iOS as much previously.

    You mentioned earlier that using the grabpass wasn't really your preferred technique. We're basically wanting to distort the opaque scene (as shown in the repo) in some of the transparent shaders. Would your recommendation be to render the whole opaque background to a rendertexture, blit it before the transparent passes start, then render all of the transparent stuff and use the rendertexture in the distortion shaders that need it? I assume we'd need to manage the depth correctly too, rather than a plain quad being blitted (else the transparent stuff won't respect the scene depth).

    Edit: QA has looked at the problem and due to technical stuff with Metal and performance implications of workarounds the problem won't be fixed. @Alexey has also said that Metal + AA affects some of the pipeline and there are no plans to workaround the issues. Basically the advice is to not use grabpasses (in shaders) when using Metal with AA. We could try to use rendertextures, but instead we're using CommandBuffers to grab the current screen.

    cheers again,

    // greg
     
    Last edited: Nov 14, 2015
  16. fcloss

    fcloss

    Joined:
    Dec 1, 2011
    Posts:
    192
    @Alexey Could you give us a feedback or date or anything?

    Problem is getting bigger and bigger for us. Unity5.0.2 has the crazy rotation crash on splash with iOs 9 (the same HearthStone had: http://us.battle.net/hearthstone/en/forum/topic/19136294703) and we are getting terrible reviews on AppStore.

    The RT issue does not happen with a clean scene, but happens with our scene, but again, it can not be an error on our side, once we have it working for Unity 3, 4 and first release of 5. I don't think we could debug Unity on a necessary level to say to you 'this is the problem' because it is happening on a lower level of the framework.

    Please get this on a higher priority, at least run it once to see it with your own eyes.

    Tks
    Fernando
     
  17. fcloss

    fcloss

    Joined:
    Dec 1, 2011
    Posts:
    192
    @Alexey , any news on this?

    Guess you know about the issue in iOs 9 landscape orientation(issue 742579), causing crash on splash. The fix (or workaround) was just released on 5.2.2p4. Off course this issue is destroying our reputation on AppStore, as expected.

    This issue makes our problem even bigger, once we can't keep using 5.0.2 due to the crash. That's by far the worst situation we have ever got maintaining and updating our app.

    Have a nice week
    Fernando
     
  18. fcloss

    fcloss

    Joined:
    Dec 1, 2011
    Posts:
    192
    @Alexey have you had the chance to check the sample we sent?

    I would love to hear a yes. It would be a hell of a Christmas gift.

    Have a nice holiday.

    Fernando
     
  19. Suguma

    Suguma

    Joined:
    May 29, 2015
    Posts:
    26
    HOLY MOTHER!
    5.3.0 seems to have fixed the issue!
     
    fcloss likes this.
  20. subatomic

    subatomic

    Joined:
    Nov 13, 2014
    Posts:
    24
    5.3.0f4 and 5.3.1f1 both work on iOS/iPhone6+ for me, for both 1.) RenderTextures drawn by Camera (using the target slot in the Camera's inspector), and also by 2.) Graphics.Blit...

    If you find yourself having problems on iOS with Graphics.Blit not working, you _may_ have a missing shader (as I did), turn on script debugging and you might see a null Material message there in xcode.

    I was doing this in my script: mat = new Material( Shader.Find( "MyShaderName" ) ), and of course Unity doesn't know about this shader when packing the iOS bundle! I fixed this by adding a Shader slot to my script and dragging the shader onto it. Now the shader makes it onto the iPhone, and my super cool effects work.
     
  21. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    I just want to thank everyone for reporting their findings for the iOS builds. As I was only testing on Android, I wasn't running into this problem on 5.1.3, but as I am currently porting my games to iOS, I ran into the issue, so it looks like I'll be upgrading to 5.3.

    Hopefully I will not incur the poor Android performance, as some people are experiencing.
     
  22. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Er, maybe I spoke too soon. I am using 5.3.1f1 and RenderTexture is still not working for me on iOS (works great on Android/PC/Mac).
    This is the code I'm using to generate the RenderTexture. Any ideas? Maybe I need to use another technique to render to texture?

    Code (CSharp):
    1.     IEnumerator RenderScreenshot()
    2.     {
    3.         yield return new WaitForEndOfFrame();
    4.  
    5.         if (mInGameMenu == null)
    6.             yield break;
    7.  
    8.         // The main camera is not showing a texture
    9.         { // Render the main camera
    10.             Camera mainCam = Camera.main;
    11.  
    12.             mainCam.targetTexture = Game.Instance.Script.ScreenshotTexture;
    13.  
    14.             if (mainCam.targetTexture != null)
    15.                 mainCam.Render();
    16.  
    17.             mainCam.targetTexture = null;
    18.         }
    19.  
    20.         // The NGUI layer renders fine
    21.         {   // Render the NGUI layer, with the screenshot elements
    22.  
    23.             GameObject nguiCam = GameObject.Find("UI Root/Camera");
    24.             Camera uiCam = nguiCam.GetComponent<Camera>();
    25.             uiCam.targetTexture = Game.Instance.Script.ScreenshotTexture;
    26.  
    27.             if (uiCam.targetTexture != null)
    28.                 uiCam.Render();
    29.  
    30.             uiCam.targetTexture = null;
    31.  
    32.             uiCam.depth = 0;    // Restore the camera depth
    33.         }
    34.  
    35.         {   // Create the texture from the RenderTexture
    36.  
    37.             RenderTexture screenshot = Game.Instance.Script.ScreenshotTexture;
    38.             RenderTexture.active = screenshot;
    39.  
    40.             int width = screenshot.width;
    41.             int height = screenshot.height;
    42.  
    43.             Texture2D tex = new Texture2D(width, height);
    44.             tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
    45.             tex.Apply();
    46.             Persistence.Instance.Mobile.Screenshot = tex;   // Save the screenshot
    47.         }
    48.     }
    49.  
    50.     // Screenshot logic is in UI, because we use the UI to render the watermark.
    51.     private void TakeScreenshot()
    52.     {
    53.         // In case this is pertinent...
    54.         GameObject nguiCam = GameObject.Find("UI Root/Camera");
    55.         Camera cam = nguiCam.GetComponent<Camera>();
    56.         cam.depth = -99;    // Hide the camera behind the other cameras
    57.  
    58.         ...
    59.  
    60.         // Use a coroutine to render a screenshot, because we have to wait
    61.         // for the frame to finish rendering first.
    62.         StartCoroutine("RenderScreenshot");
    63.     }
    EDIT:
    Ha! As I typed this, I commented out the NGUI overlay render, and it turns out RenderTexture is working. So, for some reason, on iOS, the NGUI Render() is obliterating the main camera Render().
     
    Last edited: Feb 5, 2016
  23. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    i'm seeing RenderTexture problems on 5.3.3 / iOS 10. works well in Editor, and not at all on iOS 10 on an iPhone 6.
     
  24. AbandonedCart

    AbandonedCart

    Joined:
    Mar 4, 2014
    Posts:
    72
    Unity support could also be proactive. I have had this issue in the past, resolved it, and now face it again in 5.4.2
    It is disappointing to see the same issues keep resurfacing, especially when the direction Unity has taken is more of a "pay-for-update" than "your purchase matters" approach.
     
    Last edited: May 10, 2017
  25. jcowles

    jcowles

    Joined:
    May 25, 2016
    Posts:
    11
    I'm seeing this problem on Android in the 5.4.2f2 GVR13 (Daydream tech preview build).

    Any advice @Alexey?

    I have a small repro case, but it is built on the GVR/Daydream API.
     
  26. jcowles

    jcowles

    Joined:
    May 25, 2016
    Posts:
    11
    I take it back, this is working for me -- the issue was I was calling FindShader on shaders that were not explicitly referenced in the project, so once I added them to the always included shader list, everything worked as expected.
     
    idurvesh likes this.
  27. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    Unity 5.6.2f3
    Same issue, Textures on Mobile device are getting black and red. Using custom shaders but no texture is bigger than 2048px
     
  28. Sixbraker

    Sixbraker

    Joined:
    May 20, 2017
    Posts:
    8
    I had the same issue on my LGpad! Unity version 5.6.1!
    This worked baby! <3 <3 <3
    :rolleyes: