Search Unity

Glow/Spotlight shader not working on OSX/Android/iOS (OpenGL)

Discussion in 'Shaders' started by 1Time, Mar 4, 2015.

  1. 1Time

    1Time

    Joined:
    Jun 13, 2013
    Posts:
    2
    I'm working on a project where we use a shader that creates a spotlight/cameralight effect. This effect doesn't seem to work on OSX/Android/iOS and I can't seem to find the reason for that, but it's probably something with OpenGL because when I add

    "#pragma only_renderers openGL gles gles3"

    the materials become pink and the shader says that it either has errors or that it is not supported.

    I want this shader to work on all platforms, not only on Windows.
    Could someone please help me on this issue. Pictures and code are posted below.



    Code (CSharp):
    1. Shader "Custom/GlowLine" {
    2.   Properties {
    3.       _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
    4.       _MainTex ("Particle Texture", 2D) = "white" {}
    5.       _BrightnessFactor ("Brightness Factor", Float ) = 1.0
    6.       _BrightnessHardness( "Brightness Hardness", Float ) = 2.0
    7.       _LineHardness( "Line Hardness", Float ) = 2.0
    8.   }
    9.  
    10.   Category {
    11.       Tags { "Queue"="Overlay" "IgnoreProjector"="True" "RenderType"="Transparent" }
    12.       Blend SrcAlpha One
    13.       ZTest Always
    14.       AlphaTest Greater .01
    15.       ColorMask RGB
    16.       Cull Back Lighting Off ZWrite On Fog { Color (0,0,0,0) }
    17.       BindChannels {
    18.           Bind "Color", color
    19.           Bind "Vertex", vertex
    20.           Bind "TexCoord", texcoord
    21.       }
    22.      
    23.       // ---- Fragment program cards
    24.       SubShader {
    25.           Pass {
    26.          
    27.               CGPROGRAM
    28.               #pragma vertex vert
    29.               #pragma fragment frag
    30.  
    31.               #include "UnityCG.cginc"
    32.  
    33.               sampler2D _MainTex;
    34.               fixed4 _TintColor;
    35.               float _BrightnessFactor;
    36.               float _BrightnessHardness;
    37.               float _LineHardness;
    38.              
    39.               struct appdata_t {
    40.                   float4 vertex : POSITION;
    41.                   fixed4 color : COLOR;
    42.                   float2 texcoord : TEXCOORD0;
    43.               };
    44.  
    45.               struct v2f {
    46.                   float4 vertex : POSITION;
    47.                   fixed4 color : COLOR;
    48.                   float2 texcoord : TEXCOORD0;
    49.                   float4 position : TEXCOORD1;
    50.               };
    51.              
    52.               float4 _MainTex_ST;
    53.  
    54.               v2f vert( appdata_t v )
    55.               {
    56.                   v2f o;
    57.                   o.vertex = mul( UNITY_MATRIX_MVP, v.vertex );
    58.                   o.color = v.color;
    59.                   o.texcoord = TRANSFORM_TEX( v.texcoord,_MainTex );
    60.                   o.position = o.vertex;
    61.                   return o;
    62.               }
    63.  
    64.               sampler2D _CameraDepthTexture;
    65.              
    66.               fixed4 frag( v2f IN ) : COLOR
    67.               {
    68.                   half4 texColor = pow(tex2D( _MainTex, IN.texcoord ), _LineHardness );
    69.                   float brightness = 1.0f / pow(dot( IN.position, IN.position ), _BrightnessHardness) * texColor.a;
    70.                   return 2.0f * (IN.color )* _TintColor * texColor + (brightness * _BrightnessFactor) * 0.1f;
    71.               }
    72.               ENDCG
    73.           }
    74.       }    
    75.   }
    76.   }
     
  2. 1Time

    1Time

    Joined:
    Jun 13, 2013
    Posts:
    2
    I figured out the shader DOES work on Mac but it reacts different. The alpha stuff works fine but the lighting reacts way different on Mac than on Windows.