Search Unity

Modifying UV using texture sample causes white texture on OSX

Discussion in 'Shaders' started by pixelballoon, Apr 13, 2014.

  1. pixelballoon

    pixelballoon

    Joined:
    Mar 5, 2013
    Posts:
    11
    Hi,

    I'm having an odd issue when using the output of one tex2D call as an input to another. It works fine on Windows, but under OSX it causes the texture to appear white. It's not due to the shader not compiling, as modifying the _Color value adjusts the output.

    In the example below I have a noise texture and I'm feeding that back into the actual texture to randomly offset the UV values.

    Is there a specific graphics card requirement for doing this sort of feedback that Macs don't have?

    Any information you can shed on the issue would be greatly appreciated!

    Cheers,
    Jamie

    Code (csharp):
    1. Shader "Sprites/Enemy Glitch"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6.         _Color ("Tint", Color) = (1,1,1,1)
    7.         _GlitchAmount ("Glitch Amount", Float) = 1
    8.         _Noise ("Noise Texture", 2D) = "white" {}
    9.     }
    10.  
    11.     SubShader
    12.     {
    13.         Tags
    14.         {
    15.             "Queue"="Transparent"
    16.             "IgnoreProjector"="True"
    17.             "RenderType"="Transparent"
    18.             "PreviewType"="Plane"
    19.             "CanUseSpriteAtlas"="True"
    20.         }
    21.  
    22.         Cull Off
    23.         Lighting Off
    24.         ZWrite Off
    25.         Fog { Mode Off }
    26.         Blend One OneMinusSrcAlpha
    27.  
    28.         Pass
    29.         {
    30.         CGPROGRAM
    31.             #pragma vertex vert
    32.             #pragma fragment frag
    33.             #pragma fragmentoption ARB_precision_hint_fastest
    34.             #include "UnityCG.cginc"
    35.            
    36.             struct appdata_t
    37.             {
    38.                 float4 vertex   : POSITION;
    39.                 float4 color    : COLOR;
    40.                 float2 texcoord : TEXCOORD0;
    41.             };
    42.  
    43.             struct v2f
    44.             {
    45.                 float4 vertex   : SV_POSITION;
    46.                 fixed4 color    : COLOR;
    47.                 half2 texcoord  : TEXCOORD0;
    48.             };
    49.            
    50.             fixed4 _Color;
    51.  
    52.             v2f vert(appdata_t IN)
    53.             {
    54.                 v2f OUT;
    55.                 OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
    56.                 OUT.texcoord = IN.texcoord;
    57.                 OUT.color = IN.color * _Color;
    58.                
    59.                 return OUT;
    60.             }
    61.  
    62.             sampler2D _MainTex;
    63.             sampler2D _Noise;
    64.  
    65.             fixed4 frag(v2f IN) : COLOR
    66.             {
    67.                 half4 noiseOffset = tex2D(_Noise, IN.texcoord / 2.0) / 10; // I have tried with multiple values here just for testing purposes
    68.                 half2 uv = IN.texcoord; // Using a temp variable as a test, but passing it directly doesn't work either
    69.                 uv += noiseOffset.xy; // Commenting out this line causes the shader to display the sprite (but without the offsets of course!)
    70.                 return tex2D(_MainTex, uv) * IN.color; // IN.color is always displayed, so the shader always compiles and runs
    71.                 //return noiseOffset;
    72.             }
    73.         ENDCG
    74.         }
    75.     }
    76.    
    77.     Fallback "Sprites/Premultiplied"
    78. }
    79.