Search Unity

Shader behaves differently on tvOS (Apple TV)

Discussion in 'Shaders' started by dotsquid, Dec 23, 2019.

  1. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    I've got a shader of 2d water with a foam. Nothing fancy or super complex.
    However I was unpleasantly surprised when I launched the game on tvOS: the shader was definitely working incorrectly since the water had to much foam.
    upload_2019-12-23_17-35-53.png
    Here is an abstract of the fragment shader responsible for the foam
    Code (CSharp):
    1. fixed4 frag(v2f IN) : SV_Target
    2. {
    3.     half2 dist1 = tex2D( _DistMap, IN.uvdist1 ).rg;
    4.     half2 dist2 = tex2D( _DistMap, IN.uvdist2 ).rg;
    5.     half2 dist = lerp(dist1, dist2, _DetailInfluence) * 2.0 - 1.0;
    6.  
    7.     fixed wave = sqrt(saturate(dist.x * dist.y));
    8.     fixed foam = step(_WaveFoam, wave);
    9.     fixed4 foamColor = fixed4(foam.xxx * _WaveFoamAlpha, 0.0);
    10.     ...
    11.     fixed4 color = tex2D( _ReflMap, reflUV );
    12.     ...
    13.     color += waveCrestColor;
    14.     return saturate(color);
    15. }
    16.  
    My first thought was about precision. I tried changing fixed to half, but it made no change.
    Also I had no saturate inside sqrt before, but it made no changes too.
    Any ideas why Apple TV's PowerVR runs my shader this way?
     
    Last edited: Dec 23, 2019
  2. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Actually it appeared the saturate inside sqrt indeed solved the problem.