Black textures on some devices/android versions

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

  1. trooper

    trooper

    Member

    Joined:
    Aug 21, 2009
    Messages:
    594
    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

    Member

    Joined:
    Aug 21, 2009
    Messages:
    594
    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

    Member

    Joined:
    Jan 9, 2011
    Messages:
    9
    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

    Member

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

    Ogien

    Member

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

    kurylo3d

    Member

    Joined:
    Nov 7, 2009
    Messages:
    940
    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

    Member

    Joined:
    Nov 21, 2012
    Messages:
    42
    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

    Member

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

    kurylo3d

    Member

    Joined:
    Nov 7, 2009
    Messages:
    940
  10. Ogien

    Ogien

    Member

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

    skytrack

    New Member

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

    skytrack

    New Member

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

    Xaron

    Member

    Joined:
    Nov 15, 2012
    Messages:
    155
    Could you say how?

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

    meat5000

    Member

    Joined:
    Mar 5, 2013
    Messages:
    30
    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

    New Member

    Joined:
    Apr 19, 2013
    Messages:
    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

    Member

    Joined:
    Sep 20, 2010
    Messages:
    215
    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

    New Member

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

    Tomo Games

    Member

    Joined:
    Sep 20, 2010
    Messages:
    215
    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

    Member

    Joined:
    Aug 27, 2013
    Messages:
    9
    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

    Member

    Joined:
    Apr 12, 2011
    Messages:
    108
    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

    Member

    Joined:
    Dec 22, 2011
    Messages:
    400
    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

    Member

    Joined:
    Aug 10, 2006
    Messages:
    543
    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

    Member

    Joined:
    Jan 20, 2009
    Messages:
    158
    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!
     
  24. ZFarago

    ZFarago

    Member

    Joined:
    Aug 13, 2012
    Messages:
    46
    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.