Search Unity

Error on Shader in Mac OS X but not on Windows.

Discussion in 'Shaders' started by markashburner, Jan 11, 2020.

  1. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    Hi

    I have this shader that works perfectly well on Windows 10 with a Nvidia GTX 1080 Graphics card.

    This is the shaders code:

    Code (CSharp):
    1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    2.  
    3. Shader"Universal Generator/Stars"
    4. {
    5.     Properties
    6.     {
    7.  
    8.         _SpaceBox1("SpaceBox1", 2DArray) = ""{}
    9.         _SpaceBox2("SpaceBox2", 2DArray) = ""{}
    10.         _SpaceBlend("SpaceBlend", Range(0,1)) = 0
    11.  
    12.         _Boxxed ("Space Baked", Range(0,1)) = 0
    13.         _GalaxySaturation("Space Saturation", Range(0,5)) = 0
    14.         _GalaxyBrightness("Space Brightness", Range(0,5)) = 0
    15.         _Amount1("Warp Box 1", Vector) = (0.01,0,0,0)
    16.         _Amount2("Warp Box 2", Vector) = (0.01,0,0,0)
    17.     }
    18.     SubShader{
    19.         Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
    20.         Blend SrcAlpha OneMinusSrcAlpha
    21.         Lighting Off ZWrite Off
    22.         Cull Front
    23.         Pass
    24. {
    25.         CGPROGRAM
    26.         // Physically based Standard lighting model, and enable shadows on all light types
    27.        
    28.  
    29.         // Use shader model 5.0 target
    30.         #pragma target 5.0
    31.         #pragma vertex vert
    32.         #pragma fragment frag
    33.         #include "UnityCG.cginc"
    34.         #include "TexArrayMap.cginc"
    35.         #include "Galaxy.cginc"
    36.  
    37.  
    38. float3 _Amount1;
    39. float3 _Amount2;
    40.  
    41.  
    42.  
    43. float _SpaceBlend;
    44. float _Boxxed;
    45.  
    46. float _GalaxySaturation;
    47. float _GalaxyBrightness;
    48.  
    49. UNITY_DECLARE_TEX2DARRAY(_SpaceBox1);
    50. UNITY_DECLARE_TEX2DARRAY(_SpaceBox2);
    51. struct ps_input
    52. {
    53.     float4 pos : SV_Position;
    54.     float3 viewDir : TEXCOORD0;
    55. };
    56.  
    57. ps_input vert(appdata_base v)
    58. {
    59.     ps_input o;
    60.  
    61.     o.pos = UnityObjectToClipPos(v.vertex);
    62.     o.viewDir = mul(unity_ObjectToWorld, v.vertex).xyz - _WorldSpaceCameraPos;
    63.     return o;
    64. }
    65. float3 Hue(float H)
    66. {
    67.     float R = abs(H * 6 - 3) - 1;
    68.     float G = 2 - abs(H * 6 - 2);
    69.     float B = 2 - abs(H * 6 - 4);
    70.     return saturate(float3(R, G, B));
    71. }
    72. float3 HSVtoRGB(float3 HSV)
    73. {
    74.     return float3(((Hue(HSV.x) - 1) * HSV.y + 1) * HSV.z);
    75. }
    76.  
    77. fixed4 frag(ps_input i) : COLOR
    78. {
    79.     //Bug if any vector length is 0
    80.     float a = normalize(i.viewDir);
    81.     //float3 data = UNITY_SAMPLE_TEX2DARRAY(Result, ArrayMapUV(lerp(i.viewDir, _Warp, 1 - distance(a, normalize(_Warp)) * 0.5f)));
    82.  
    83.     float4 sb = lerp(UNITY_SAMPLE_TEX2DARRAY(_SpaceBox1, ArrayMapUV(lerp(i.viewDir, _Amount1, 1 - distance(a, normalize(_Amount1)) * 0.4))), UNITY_SAMPLE_TEX2DARRAY(_SpaceBox2, ArrayMapUV(lerp(i.viewDir, _Amount2, 1 - distance(a, normalize(_Amount2)) * 0.4))), _SpaceBlend);
    84.  
    85.     float bw = (sb.x + sb.y*0.75 + sb.z*0.5) / 2.25;
    86.     sb.xyz = lerp(float3(0, 0, 0), lerp(bw, sb.xyz, _GalaxySaturation), _GalaxyBrightness);
    87.     sb.w = sb.w * _Boxxed;
    88.     return sb;
    89.         //return texCUBE(_Cube, i.viewDir);
    90. }
    91.        
    92.         ENDCG
    93.     }
    94. }
    95.  
    96. }
    However on Mac OS High Sierra with a GTX 1080 graphics card, the shader throws me this error on line 65 the redefinition of Hue.





    So how come the same exact code produces different results on each operating system? The shader works perfectly well on Windows 10 but throws the above error on mac.

    Can someone help?

    Thanks