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. Dismiss Notice

Shader Fails on Intel HD Graphics Cards

Discussion in 'Shaders' started by Doddler, Jun 12, 2014.

  1. Doddler

    Doddler

    Joined:
    Jul 12, 2011
    Posts:
    265
    So I'm having a bit of an odd issue... It's hard to test myself since I don't have access to a computer with this video adapter, but a number of people trying to run my game on Intel HD Graphics 4000 and similar cards are reporting that this shader always shows solid black for them. The weirdest thing is that Shader.isSupported returns true, the cards report supporting shader 3.0, and the fallback is never invoked.

    Here's the shader code:

    Code (csharp):
    1. Shader "Custom/Unlit Transparent Colored"
    2. {
    3.     Properties
    4.     {
    5.         _Color ("Blending Color", Color) = (0.5,0.5,0.5,1)
    6.         _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
    7.         _BlendTex ("Blend (RGB), Alpha (A)", 2D) = "grey" {}
    8.         _SecondBlend ("Use Second Blend", Range (0, 1)) = 0
    9.         _Desaturate ("Use Desaturation", Range (0, 1)) = 0
    10.         _SepiaMode ("Use Really Colors", Range (0, 1)) = 0
    11.     }
    12.  
    13.     SubShader
    14.     {
    15.         LOD 200
    16.  
    17.         Tags
    18.         {
    19.             "Queue" = "Transparent"
    20.             "IgnoreProjector" = "True"
    21.             "RenderType" = "Transparent"
    22.         }
    23.  
    24.         Pass {
    25.  
    26.             Blend SrcAlpha OneMinusSrcAlpha
    27.  
    28.             ZTest Always Cull Off ZWrite Off
    29.             Fog { Mode off }      
    30.  
    31.             CGPROGRAM
    32.  
    33.             #pragma fragmentoption ARB_precision_hint_fastest
    34.             #pragma vertex vert
    35.             #pragma fragment frag
    36.             #pragma target 2.0
    37.  
    38.  
    39.             // vertex input: position, UV
    40.             struct appdata {
    41.                 float4 vertex : POSITION;
    42.                 float4 texcoord : TEXCOORD0;
    43.             };
    44.  
    45.             struct v2f {
    46.                 float4 pos : POSITION;
    47.                 float2 uv : TEXCOORD0;
    48.             };
    49.  
    50.             sampler2D _MainTex;
    51.             sampler2D _BlendTex;
    52.  
    53.             fixed4 _Color;
    54.             //fixed4 _Color2;
    55.             half _Desaturate;
    56.             half _SecondBlend;
    57.             half _SepiaMode;
    58.  
    59.             v2f vert( appdata v ) {
    60.                 v2f o;
    61.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    62.                 o.uv = v.texcoord.xy;
    63.                 return o;
    64.             }
    65.            
    66.             fixed4 frag(v2f i) : COLOR {
    67.                 fixed4 color = tex2D (_MainTex, i.uv);
    68.                
    69.                 fixed alpha = color.a;
    70.                 fixed power = (color.r + color.g + color.b) / 3;
    71.  
    72.                 color = color * lerp(_Color * 2, 1, power);
    73.                
    74.                 if(_SecondBlend > 0.5)
    75.                 {
    76.                     fixed4 color2 = tex2D (_BlendTex, i.uv);
    77.  
    78.                     color = (color * (1 - color2.a)) + (color * color2 * color2.a); // * lerp(color2, float4(1,1,1,1), color2.a);
    79.                 }
    80.  
    81.                 if(_Desaturate < 0.5)
    82.                 {
    83.                     fixed des = (color.r + color.g + color.b) / 3;
    84.                     color.r = des;
    85.                     color.g = des;
    86.                     color.b = des;
    87.                 }
    88.  
    89.                 if(_SepiaMode > 0.5)
    90.                 {
    91.                     color = color * float4(0.76, 0.59, 0.37, 1);
    92.                 }
    93.  
    94.                 color.a = alpha;
    95.  
    96.                 return color;
    97.             }
    98.  
    99.             ENDCG
    100.         }
    101.     }
    102.  
    103.     Fallback "Unlit/Transparent"
    104. }
    105.  
     
  2. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    Could it be the target 2.0 doing it?
    Maybe they only have 3.0 but not 2.0? (is such a thing possible?)

    also you have ifs
     
  3. Doddler

    Doddler

    Joined:
    Jul 12, 2011
    Posts:
    265
    I don't think such a thing is possible. Also on the ifs, I use them to enable/disable certain features. Is there an issue with that approach?
     
  4. avadlamani

    avadlamani

    Joined:
    Sep 29, 2013
    Posts:
    104
    I don't know, but on some older cards if statements do tend to cause issues. But usually there performance based not black screen based
     
  5. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Try 3.0. also check that DX11 (if you're using it, that is) isn't screwing with the shader syntax, as DX11 often does this dopey syntax rubbish that causes 3.0 shaders to show up black.
     
  6. Doddler

    Doddler

    Joined:
    Jul 12, 2011
    Posts:
    265
    Based on ZephyrSys's suggestion, I removed the if statements and replaced them with #pragma multi_compile keywords, which appears to have fixed the issue. It's concerning that the shader would silently fail rather than fallback, but I guess some cards won't do if's (or that many if's).

    Thanks for the help everyone.
     
  7. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    You're welcome.