Search Unity

Spherical Water shader crash on LG G2

Discussion in 'Shaders' started by TheoSabattie, Apr 26, 2017.

  1. TheoSabattie

    TheoSabattie

    Joined:
    Mar 11, 2016
    Posts:
    15
    Hi everyone,



    I have been searching for a week the origin of a crash.
    I found the line related to the crash but I don't understand where is the mistake.

    The shader :

    Code (CSharp):
    1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
    2.  
    3. Shader "Unlit/Prog_Water_Shader"
    4. {
    5.     Properties
    6.     {
    7.         _Color("Color", Color) = (1,1,1,0.5)
    8.         _Amplitude("Amplitude", Float) = 0.02
    9.         _FresnelForce("Fresnel force", Float) = 0.0
    10.         _Speed("Speed", Float) = 1
    11.         _Variety("Variety", Int) = 6
    12.         _VarietyAjustor("VarietyAjustor", Int) = 70
    13.     }
    14.     SubShader
    15.     {
    16.         Tags {
    17.             "IgnoreProjector" = "True"
    18.             "Queue" = "Transparent"
    19.         }
    20.         LOD 100
    21.         ZWrite Off
    22.         Blend SrcAlpha OneMinusSrcAlpha
    23.  
    24.         Pass
    25.         {
    26.             CGPROGRAM
    27.             #pragma vertex vert
    28.             #pragma fragment frag
    29.             #pragma multi_compile_fog
    30.            
    31.             #include "UnityCG.cginc"
    32.  
    33.             struct VertexInput
    34.             {
    35.                 float4 position : POSITION;
    36.                 float4 normal : NORMAL;
    37.                 uint id : SV_VertexID;
    38.             };
    39.  
    40.             struct VertexOutput
    41.             {
    42.                 float4 position : SV_POSITION;
    43.                 fixed4 color:COLOR;
    44.             };
    45.  
    46.             float _Amplitude;
    47.             float _VarietyAjustor;
    48.             int _Variety;
    49.             fixed4 _Color;
    50.             float _Speed;
    51.             float _FresnelForce;
    52.  
    53.             int modulo(uint reference, uint modulo) {
    54.                 float divisionResult = reference / modulo;
    55.                 return reference - round(divisionResult) * modulo;
    56.             }
    57.  
    58.             float AxisLength(float3 axis) {
    59.                 return sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z);
    60.             }
    61.  
    62.             float AngleBetweenAxis(float3 axisA, float3 axisB) {
    63.                 return acos(dot(axisA, axisB) / (AxisLength(axisA)*AxisLength(axisB)));
    64.             }
    65.  
    66.             VertexOutput vert (VertexInput input)
    67.             {
    68.                 VertexOutput output;
    69.  
    70.                 output.color = _Color - (dot(input.normal, UNITY_MATRIX_IT_MV[2]) * _FresnelForce);
    71.  
    72.                 float vertexMathID = AxisLength((float4(input.normal.x, input.normal.y, input.normal.z, 0) * 0.5 + 0.5) * _VarietyAjustor);
    73.  
    74.                 input.position += sin(_Time[1] * modulo(vertexMathID, _Variety) * _Speed) * input.normal * _Amplitude;
    75.                 output.position = UnityObjectToClipPos(input.position);
    76.                 return output;
    77.             }
    78.            
    79.             fixed4 frag (VertexOutput i) : COLOR
    80.             {
    81.                 return i.color;
    82.             }
    83.             ENDCG
    84.         }
    85.     }
    86. }
    87.  
    The line invoking the crash :
    Code (CSharp):
    1. output.color = _Color - (dot(input.normal, UNITY_MATRIX_IT_MV[2]) * _FresnelForce);
    The shader works on several devices but not on LG G2

    details of the device:
    model(s) - LG G2
    memory 16 Go (10,6 Go for the user)
    RAM 2Go
    processor Qualcomm S800 - 2.26 GHz
    Version OS Android 4.4.2
    Resolution 440 dpi
    Definition 1920x1080

    Thanks!