Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Black textures on some devices/android versions

Discussion in 'Android' started by trooper, Aug 11, 2013.

  1. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    I've got an issue where some devices are having my shader show up as black. Does anyone know what the cause of a black texture is? I know pink means the shader isn't supported but black seems like the lighting isn't working.

    Example: http://imgur.com/JozhJH9
     
  2. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    The top picture shows what the shader should look like (and works on most devices) but there are some devices that don't.

    You can see the reflection part of the shader is working in the bottom image but the color of the texture is black. The bit of yellow at the back is actually a different material (needed to be transparent for the flames).

    Anyone come across this type of issue is custom shaders? It's got to be something I'm doing wrong in my shader:

    Code (csharp):
    1.  
    2. Shader "Simple/VertexLit Reflective"
    3. {
    4.  
    5.     Properties
    6.     {
    7.          
    8.         _Reflected ("Reflection", Color) = (0.15,0.15,0.15,1)
    9.         _MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
    10.         _BumpTex ("Normal", 2D) = "white" {}
    11.         _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }    
    12.         _WindDirection("Wind Direction",Vector) = (0,0,0,0)
    13.  
    14.     }
    15.  
    16.  
    17.    SubShader
    18.    {
    19.                
    20.           Pass
    21.           {    
    22.          
    23.           Tags {"LightMode"="Vertex" }
    24.    
    25.  
    26.             GLSLPROGRAM
    27.    
    28.             // Varyings        
    29.             varying mediump vec2 uv;
    30.             varying mediump vec2 uv2;
    31.             varying lowp vec3 lighting;
    32.             varying lowp vec3 reflectedDirection;
    33.             varying lowp float c;
    34.             varying mediump vec3 viewDirection;
    35.             varying mediump vec3 normal;
    36.             varying mediump vec3 lightDir;
    37.             uniform mediump vec3 unity_LightPosition[1];
    38.             uniform mediump vec3 unity_LightColor[1];
    39.      
    40.            
    41.             uniform mat4 _Object2World; // model matrix
    42.             uniform mat4 _World2Object; // inverse model matrix
    43.    
    44.             uniform lowp vec4 _WindDirection;
    45.  
    46.             uniform mediump vec4 _Reflected;
    47.    
    48.             #ifdef VERTEX
    49.              
    50.                uniform mediump vec4 _MainTex_ST;
    51.                uniform mediump vec4 _BumpTex_ST;
    52.                
    53.             uniform lowp vec3 _WorldSpaceLightPos0, _LightColor0, _WorldSpaceCameraPos;
    54.    
    55.             void main()
    56.             {            
    57.        
    58.        
    59.                 vec4 wind;
    60.        
    61.                 wind.xyz    = mat3(_WindDirection, _WindDirection, _WindDirection) * _WindDirection.xyz;
    62.                 wind.w        = 0.0;
    63.    
    64.                   uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
    65.                   uv2 = gl_MultiTexCoord1.xy * _BumpTex_ST.xy + _BumpTex_ST.zw;
    66.          
    67.                 viewDirection = vec3(_Object2World * gl_Vertex - vec4(_WorldSpaceCameraPos, 1.0));
    68.                
    69.                    normal = normalize(gl_NormalMatrix * gl_Normal);
    70.                
    71.                 lightDir = normalize(vec3(unity_LightPosition[0].xyz));
    72.                
    73.                 lighting = max(dot(normal, lightDir), 0.) * unity_LightColor[0] + gl_LightModel.ambient.rgb;
    74.                  
    75.                 c = (1.0-gl_Color.g) * 1.5;
    76.                
    77.                 reflectedDirection = reflect(viewDirection, normal);  
    78.                
    79.                 vec4 pos =  gl_Vertex;
    80.                
    81.                 pos.xyz +=  wind.xyz + (_WindDirection.xyz * (1.0-gl_Color.r)) ;
    82.                
    83.                 gl_Position = gl_ModelViewProjectionMatrix * pos;
    84.                
    85.             }
    86.      
    87.              #endif
    88.    
    89.              #ifdef FRAGMENT
    90.              
    91.      
    92.             uniform lowp sampler2D _MainTex;
    93.             uniform lowp sampler2D _BumpTex;  
    94.               uniform lowp samplerCube _Cube;  
    95.                
    96.             void main()
    97.             {
    98.    
    99.                 lowp vec4 u = texture2D(_MainTex, uv);
    100.                 lowp vec4 u2 = texture2D(_BumpTex, uv2);
    101.              
    102.                  u.rgb *= lighting;
    103.              
    104.                  gl_FragColor = (u - (u2.g * u) * c) + (textureCube(_Cube, reflectedDirection) * _Reflected);
    105.                  
    106.             }
    107.    
    108.              #endif
    109.      
    110.    
    111.              ENDGLSL
    112.           }
    113.        }
    114.        
    115.        Fallback "Mobile/VertexLit"
    116.    
    117. }
     

    Attached Files:

  3. phtphan

    phtphan

    Joined:
    Jan 9, 2011
    Posts:
    10
    I have the same problem on one of customer's Android device.

    $1185165_10151810934551508_567324716_n.jpg

    Will let you know if I could find out the cause
     
  4. phtphan

    phtphan

    Joined:
    Jan 9, 2011
    Posts:
    10
    I used specular reflective on the airplane skin.
     
  5. Ogien

    Ogien

    Joined:
    Nov 21, 2012
    Posts:
    165
    I have the same issue, anyone find a solution?
     
  6. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    remember mobile doesnt support over 2048x2048. I found that if you use a texture thats larger then that it will turn black.
     
  7. Ogien

    Ogien

    Joined:
    Nov 21, 2012
    Posts:
    165
    I do not have any textures that large, thanks though

    I really would like a solution to this, I am getting angry 1 star comments from users.
     
  8. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    might wanna go to unity support with this. Using custom shaders?
     
  9. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
  10. Ogien

    Ogien

    Joined:
    Nov 21, 2012
    Posts:
    165
    I am using the built in Mobile->Vertex Lit,
     
  11. skytrack

    skytrack

    Joined:
    Apr 19, 2013
    Posts:
    4
    Hello! Did u find the reason or solution ? We've experienced this as well sometimes.
     
  12. skytrack

    skytrack

    Joined:
    Apr 19, 2013
    Posts:
    4
    Looks like we've fixed it!
     
  13. Xaron

    Xaron

    Joined:
    Nov 15, 2012
    Posts:
    379
    Could you say how?

    Any chance your device has a MALI 400 GPU?
     
  14. meat5000

    meat5000

    Joined:
    Mar 5, 2013
    Posts:
    118
    With latest version of Unity I had to play with depth buffers (enable 32 bit, disable 24 bit) or my entire game was black. Android also has limited texture support.

    Also check the texture import settings, specifically for Transparency options.

    White could be completely transparent?
     
  15. skytrack

    skytrack

    Joined:
    Apr 19, 2013
    Posts:
    4
    No, it's still reproducible. We're experiencing this bug on iPad devices sometimes. I thought it was related to the Resources.UnloadUnusedAssets() method, but i was wrong.
    Have no idea what to do.
     
  16. Tomo-Games

    Tomo-Games

    Joined:
    Sep 20, 2010
    Posts:
    223
    Hey guys do all your problems go away if you hard set Quality Settings for AntiAliasing Multi Sampling to 0?
    QualitySettings.antiAliasing = 0;

    I was about to raise my own thread as my issue seems worse when using Static Batching with Anti Aliasing.

    Before we get into texture import settings using ETC and RGBA 16 and such. I wanted to point out that my game has been out with 3 updates to Google Play, Amazon / Kindle, and Nook with no texture rendering issues on Unity 3.5.x Pro.

    With the 4th update I had upgraded to Unity 4.2.1f4 Pro and now I have users reporting black bars on my UI (NGUI) and flickering graphics. The flickering is some of my meshes deforming all over the place. At first I couldn't reproduce the problem on my devices but now I've isolated the cause with the ramping up of my Quality Settings. Other build settings include: OpenGL ES 2.0 and Android 2.2 as a base.

    I have confirmed issues on Galaxy 1 - 4 S devices and on Nook Color by enabling AntiAliasing Mulitsampling 2x or higher.

    Can people tell me if they are seeing similar results by hard setting:
    QualitySettings.masterTextureLimit = 0; //Let's avoid Mip maps for now.
    QualitySettings.antiAliasing = 2; //or 4, 8...
     
  17. skytrack

    skytrack

    Joined:
    Apr 19, 2013
    Posts:
    4
    Yep, we have no AA at all and experiencing this issue.
     
  18. Tomo-Games

    Tomo-Games

    Joined:
    Sep 20, 2010
    Posts:
    223
    Yikes. Does it get worse when enabling multi sampling above 0? Many of my static models disappear. I lose my skybox. I get some flickering on screen too which is random.

    Anyone notice things change with changes to AA settings?
     
  19. Ilona

    Ilona

    Joined:
    Aug 27, 2013
    Posts:
    10
    We are also experiencing this problem. We've had it before, but found out there were still some texture atlases set at 4096, we set those to 2048 and that solved the problem. Now we've added some new graphics and the problem has emerged again. I've checked all atlases and nothing is bigger than 2048 this time. Setting antiAliasing makes the problem worse, but we also don't use antiAliasing to begin with so this can not be used to solve the problem.

    Any advice would be appreciated!
     
  20. DreamEnder

    DreamEnder

    Joined:
    Apr 12, 2011
    Posts:
    191
    I'm having a similar issue. My static batched models are black when I run on my iPhone 5. They show up fine if I set them to non static.
     
  21. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    I have the same issue in Traffic Racer after upgrading to Unity 4.2.x It both happens in iOS and Android. But not always. You can see it in a user video below.
    https://everyplay.com/videos/1098645
    If you look at 00:20 , you can see that it's related with lighting. The texture turns to normal with headlight flasher (when a spot light is enabled). I have tried mobile/diffuse and mobile/vertexlit shaders. The problem occurs on both.
     
    Last edited: Oct 23, 2013
  22. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,240
    I'm having this problem as well: some textures turn black when anti-aliasing is enabled. Did anyone figure out a fix?
     
  23. matrix211v1

    matrix211v1

    Joined:
    Jan 20, 2009
    Posts:
    193
    Simple fix.

    Change your Material to "Unlit/Transparent Cutout" if you are using Unity 4.3. Also make sure your Texture Atlas are set to either Texture at 2048x2048 and Truecolor or if you need Advanced settings, choose 2048 and Automatic Truecolor.

    This was using NGUI 2.6.1.

    Enjoy!
     
    enggreys likes this.
  24. ZFarago

    ZFarago

    Joined:
    Aug 13, 2012
    Posts:
    155
    I see this topic is quite old, I have experimented this "black-skinned-object" problem today. It was strange as the material preview and every non-skinned mesh looked fine. A time ago, sometimes we saw black objects in mobile, but it was quite rare. But today I switched the editor to OpenGL mode, and every single skinned meshes turned to black.

    So I went trough every editor / quality / importer settings options but nothing. The only chance left is to figure out this bug under shader side. I am using a custom shader but it is quite standard for our projects, and worked well before. After a short experimenting I find out if the objects doesn't have vertex colors, but shader want to use them, then in opengGL the "default" assigned color will be black, and not white. In the Editor in OGL, it is constant, so easy to find, but if you build to mobile, some devices renders it fine, and some renders it in black. This is only happens when using skinned mesh renderer.

    So if anybody have the same problem, maybe can chek if the used shader multiplicating the final color with the vertex colors as this could be the reason for black objects.
     
  25. KBAallstar

    KBAallstar

    Joined:
    Jun 29, 2015
    Posts:
    2
    I had issues with basic materials turning black on Android. Fixed it by reducing the "smoothness" of the material to 0.5 or less. I also chose compress in ETC1 format, but I think the main issue was smoothness above 0.5. I'm using Unity 5.1.
     
  26. Ratstash

    Ratstash

    Joined:
    Jan 17, 2015
    Posts:
    3
    Changing to unlit textures fixed it for me, but I realize that may not be an option for you. Our game worked perfectly on the S6 and had black textures on the Note 4. I think it may have to do with their current batching system because all objects that were unique (not batched) had no issues. Sorry I couldn't be more help, good luck!
     
  27. NeilUVFX

    NeilUVFX

    Joined:
    May 20, 2015
    Posts:
    1
    Happy to confirm that this solution worked for me - all materials that had this issue were set at 0.5 smoothness (default?), setting them to 0.4 and all textures appeared fine - Tested on a Nexus 7.
     
  28. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    Just came to report that I had the same problem - black textures on everything (except NGUI textures for some reason). I disabled AA and that solved the problem for me.

    [Galaxy Note 4, Android 5.0.1 device]
     
  29. grimmy

    grimmy

    Joined:
    Feb 2, 2009
    Posts:
    409
    I'm trying a few of these solutions. How on earth do you change the 'smoothness' of a material? I can't find any settings. Is that shader specific? If so, what Shader were you using?
     
  30. OnAndOn

    OnAndOn

    Joined:
    Feb 14, 2015
    Posts:
    11
    Just in case someone comes across this...
    Smoothness is property of Standard shader in Unity 5+.
     
  31. araz01

    araz01

    Joined:
    Aug 2, 2016
    Posts:
    53
    HI! i FIXED this, it happening a day ago, and i found the solution, when building the game, set the texture compression : etc1 (default) but before that, make sure all your textures (or the ones that are black), click the texture, once selected, select android and override the setting, then select the format from whatever it is (usually compression) change it to true colour and apply. then build and run the black texture will be as intended. hope i was clear lol, just found this :p :D good luck guys!

    update: alot of people are struggling :(, we need to find a way to get this across. spread the word people.
     
    Hansaja2000 likes this.
  32. MoribitoMT

    MoribitoMT

    Joined:
    Jun 1, 2013
    Posts:
    301
    I am having this issue
    iPhone 5 no problem, but iPhone 6s has the problem
    Using Unity 2017.1.3 patch 2, any idea ?
     
  33. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Had this again 7 years later... Thinking it's Open GL 2.0 with Fixed Function shaders not working well, have to switch to a CG shader to get it going.
     
  34. LGW_DesertEagle_PWN

    LGW_DesertEagle_PWN

    Joined:
    Jul 25, 2019
    Posts:
    4
    Ran into this issue recently on a Pico Neo 2 Device. It was resolved by disabling multi-threaded rendering (using GLES3).
     
    OlliQueck likes this.
  35. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,059
    The problem is related to "Auto Graphics API" you should turn it on. It solves these kinds of weird problems.