Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

bug of unity 4.1.2 f2? built in shader and separate shader work different on android

Discussion in 'Editor & General Support' started by linguohua, Apr 16, 2013.

  1. linguohua

    linguohua

    Joined:
    Apr 13, 2013
    Posts:
    11
    Hi everyone, i have a big trouble with unity 4.1.2f1:
    My phone is android 4.1, and the gpu is vivante GC400.
    I create a simple project: two simple scenes, the first scene just have a GUI.Button which load the second scene when be clicked; the second scene has an unity sphere with a specular shader, and a GUI.Button which return to the first scene when be clicked.
    $first scene.png

    $second scene.png

    The problem is:When I switch between the first and the second scene(press first scene's button and press second scene's button)many times,if I use the built in shader(select it from the drop list of unity editor), it works well; but if I copy coresponding shader code from the unity built-in shader folder(builtin_shaders-4.1.2,download from unity) into a seperate shader file, then give it to the sphere, it does not work well, sometimes the sphere looks to be strange.
    $project.png

    $sphere looks strange 2.png

    $sphere looks strange 3.png

    But, when i test this project at unity 4.0.1f2, it works well in both scenarios.

    It's this a bug of 4.1.2f1?
    Any suggestions?

    Thanks!
     
    Last edited: Apr 16, 2013
  2. linguohua

    linguohua

    Joined:
    Apr 13, 2013
    Posts:
    11
    Any help, please.
    Thanks very very much.
     
  3. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    Hi, have you submitted a bug report on this? Do you have a case number?
     
  4. linguohua

    linguohua

    Joined:
    Apr 13, 2013
    Posts:
    11
    Hi,No, i have no case number.
    How can i have a case number?
    thanks.
     
  5. linguohua

    linguohua

    Joined:
    Apr 13, 2013
    Posts:
    11
    Hi, JuliusM, how to get a case number?
     
  6. linguohua

    linguohua

    Joined:
    Apr 13, 2013
    Posts:
    11
    I finally found a way to avoid this problem: I do not destroy the sphere when scene unload, so when i switch between the two scenes, the sphere not need to destroy and recreate, it always be there. and the shader not go wrong.
     
  7. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    Ok, i'll post resolution here for other people to see. The problem lies in vivante gpu drivers. In 4.1 we've added shader caching - after compiling once, if the gpu supports binary shaders (GL_OES_get_program_binary) we get the binary and save it to cache - so next time you try to load it (even on subsequent runs) you wont need to compile it - meaning way faster loading times. It turns out that vivante gpu have some bug in there ;-). For next unity release we will just blacklist this gpu from caching shaders, but for now the better workaround would be to add
    before loading new level.
    This will clear shader cache effectively forcing to recompile shaders (sure, if you keep shader object alive then no need to recompile, so keeping sphere/its material around will help too ;-))
    Hope this makes sense 8)
     
  8. linguohua

    linguohua

    Joined:
    Apr 13, 2013
    Posts:
    11
    Hi Alexey, your resolution work great, thank you very much.
    You are so handsome, you are so smart!
     
  9. scritchy

    scritchy

    Joined:
    Dec 30, 2010
    Posts:
    94
    is there any way for me to detect this GPU, or is there a list of them i can look for, or do i just have to suck it up and make it slower on all devices?

    Is the fix for this in 4.1.5, the recently released version or do we still need to do this?
     
  10. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    no, it will be out with 4.2
     
  11. scritchy

    scritchy

    Joined:
    Dec 30, 2010
    Posts:
    94
    So, while this does seem to fix the exploding mesh issue, on some devices (ie HTC Incredible), we are experiencing a slew of texture issues. Sometimes random things render black, or as a tester puts it "corrupt" or "glitched". This also occurs with less frequency on the brand new HTC One, but still sometimes things appear black.

    I don't know if it's related to this shader cache thing or not.
     
  12. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    hm, it's complicated issue. For now (4.2) we are disabling cache in these cases:
    - if running on pre-HoneyComb OS (we had too much of bugs in there)
    - if running on Immersion GPU (as of now all phones we tested on were buggy)
    as for HTC One - if disabling shader cache helps - please submit bug report about it (if it doesnt help - still bug report with repro project - i dont like the idea of graphical artefacts ;-))
     
  13. scritchy

    scritchy

    Joined:
    Dec 30, 2010
    Posts:
    94
    Disabling shader cache doesn't help (the black texture issue). i just confirmed building game in 4.0.1 makes all the black texture stuff stop happening on the HTC Incredible. will verify for HTC one in a bit. I have a submitted project that previously had "exploding meshes" which was fixed w/ the shader cache thing, i haven't confirmed the black texture stuff happens in there yet, will do that when i can, but it might take a day or two. that is bug 544782, which is marked as closed.

    - addendum - confirmed it made the blackness stop on the HTC One as well

     
    Last edited: Jun 24, 2013
  14. scritchy

    scritchy

    Joined:
    Dec 30, 2010
    Posts:
    94
    Question about ClearShaderCache()...
    if I call ClearShaderCache, and then call Application.LoadLevelAsync("something"); won't the shader cache just get re-filled by rendering the current level again while the async load is happening? If so this solution isn't going to work for those of us using this, will it?
     
  15. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    Just to add that We're also having problems with the shaders on Android Galaxy Nexus (4.2.2), Nexus 4 (4.2.2), Same project on Unity 4.1.2 works perfect but on 4.1.5 fails, it even crash on the Galaxy Nexus. ClearShaderCache() doesn't helps
     
  16. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    why do you hijack this thread then? 8)
    bug report with repro project
     
  17. bigramx

    bigramx

    Joined:
    Jun 28, 2013
    Posts:
    1
    Looks like the same problem in my game on Galaxy S i9000 (S1) with PowerVR SGX540 and with Android 2.3.6 Gingerbread. Some textures looks like broken in some conditions when i start the APK second time after shaders recompiling. ClearShaderCache() work's good to me and solve the problem.
     
  18. scritchy

    scritchy

    Joined:
    Dec 30, 2010
    Posts:
    94
    i just submitted a new project that reproduces the black texture issue i noted on this thread on both our HTC devices. this is now Case
    549562

    thanks

     
  19. Ogien

    Ogien

    Joined:
    Nov 21, 2012
    Posts:
    165
    Did anyone find a resolution to the black texture issue. I just had this start happening to me in 4.2.1 and I can't find a solution.
     
  20. Tim-Wiese

    Tim-Wiese

    Joined:
    Jul 7, 2012
    Posts:
    75
    I was having similar issues with building to iOS, I tried the Handheld.ClearShaderCache(), but it did nothing. I found a workaround, after instantiation I reapply whatever shader the model is using. Not ideal at all but it fixed my issue, I also have to submit a bug report with a test scene about this as I see no mention of it happening on iOS.

    A sample of the code.
    Code (csharp):
    1. if(obj.renderer != null)
    2.         {
    3.             for(int i = 0; i < obj.renderer.sharedMaterials.Length; i++)
    4.             {
    5.                 if(obj.renderer.sharedMaterials[i].shader.name == "DiffuseStaticOutline")
    6.                     obj.renderer.sharedMaterials[i].shader = Shader.Find("DiffuseStaticOutline");
    7.             }
    8.         }
     
  21. Ghikya

    Ghikya

    Joined:
    Jan 18, 2014
    Posts:
    4
    There is still a problem with caching shaders on Unity 5.3.3p1 on Android Galaxy S(I9000), the shaders looks ok, but there is about 10 FPS drop when launching app for second time after install, Handheld.ClearShaderCache() fix the problem.