Search Unity

Shader invisible in Mac Player, works in Editor

Discussion in 'Shaders' started by BonneCW, Jan 19, 2019.

  1. BonneCW

    BonneCW

    Joined:
    Jan 22, 2017
    Posts:
    123
    Hey there,

    I have a problem with my UI shaders. I use the Sprite Default shader as base for them and add my functionality in the frag function. That way I e.g. developed a highlight shader brightening an image button when hovering it. It works like a charm on Windows (Editor and Player) and on Mac in the Editor. But when exporting on Mac when hovering the button, it's just invisible. I build the Windows Player on Windows and the Mac Player on Mac.

    Here is my shader:

    Code (CSharp):
    1. Shader "EW/UI/HighlightShader"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6.         _Color ("Tint", Color) = (1,1,1,1)
    7.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    8.         [HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
    9.         [HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
    10.         [PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
    11.         [PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
    12.     }
    13.  
    14.     SubShader
    15.     {
    16.         Tags
    17.         {
    18.             "Queue"="Transparent"
    19.             "IgnoreProjector"="True"
    20.             "RenderType"="Transparent"
    21.             "PreviewType"="Plane"
    22.             "CanUseSpriteAtlas"="True"
    23.         }
    24.  
    25.         Cull Off
    26.         Lighting Off
    27.         ZWrite Off
    28.         Blend One OneMinusSrcAlpha
    29.  
    30.         Pass
    31.         {
    32.         CGPROGRAM
    33.             #pragma vertex SpriteVert
    34.             #pragma fragment frag
    35.             #pragma target 2.0
    36.             #pragma multi_compile_instancing
    37.             #pragma multi_compile _ PIXELSNAP_ON
    38.             #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
    39.             #include "UnitySprites.cginc"
    40.                                                    
    41.              float4 frag(v2f IN) : SV_Target
    42.              {
    43.                  fixed4 c = SampleSpriteTexture(IN.texcoord) * IN.color;
    44.                  c.rgb *= c.a;
    45.                  c.r *= 1.75;
    46.                  c.g *= 1.75;
    47.                  c.b *= 1.75;
    48.                    
    49.                  return c;
    50.              }
    51.         ENDCG
    52.         }
    53.     }
    54.     Fallback "Sprites/Default"
    55. }
    56.  
    I have no idea whether it's a bug or if I'm missing some point. I'm still not used to writing shaders, but such simple stuff should behave the same on Mac and Windows imo.

    I'm using Unity 2017.4.18 right now and my procedure for enabling this shader is to switch the material of the image when hovering the button and reverting to default when leaving the button.
     
  2. BonneCW

    BonneCW

    Joined:
    Jan 22, 2017
    Posts:
    123
    Has really nobody any experience with that? :(
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Because there's nothing obviously wrong with the shader. My only thought would be that your mac build is stripping the shader when for some reason the windows build is not.