﻿Shader "VRCOSC/Trackers/Battery"
{
    Properties
    {
        _MainTex ("Texture Atlas", 2D) = "white" {}
        _CutOff ("CutOff", Range(0.0, 1.0)) = 0.5
        _Emission ("Emission", Range(0.0, 1.0)) = 0.0
        _Battery ("Battery", Range(0.0, 1.0)) = 0.0
        [Toggle] _Charging ("Charging", float) = 0
    }
    SubShader
    {
        Tags { 
            "RenderType" = "Cutout"
            "Queue" = "AlphaTest"
        }
        
        LOD 200

        CGPROGRAM
        
        #pragma surface surf Standard fullforwardshadows
        #pragma target 3.0

        sampler2D _MainTex;
        float _CutOff;
        float _Emission;
        float _Battery;
        float _Charging;

        struct Input
        {
            float2 uv_MainTex;
        };
        
        bool isLevel0()
        {
            return _Battery >= 0 && _Battery <= 0.025;
        }
        
        bool isLevel1()
        {
            return _Battery > 0.025 && _Battery <= 0.25;
        }
        
        bool isLevel2()
        {
            return _Battery > 0.25 && _Battery <= 0.5;
        }
        
        bool isLevel3()
        {
            return _Battery > 0.5 && _Battery <= 0.75;
        }
        
        bool isLevel4()
        {
            return _Battery > 0.75 && _Battery <= 1.0;
        }
        
        bool isFullyCharged()
        {
            return _Battery == 1.0;
        }
        
        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            fixed2 uv_MainTex_New = IN.uv_MainTex;
            
            if (_Charging == 1 && !isLevel0() && !isFullyCharged() && _SinTime.w * 100 < 0.0)
            {
                uv_MainTex_New -= fixed2(0.2, 0.0);
            }
        
            if (isLevel0())
            {
               uv_MainTex_New += fixed2(0.0, 0.0);
            }
            else if (isLevel1())
            {
               uv_MainTex_New += fixed2(0.2, 0.0);
            }
            else if (isLevel2())
            {
               uv_MainTex_New += fixed2(0.4, 0.0);
            }
            else if (isLevel3())
            {
               uv_MainTex_New += fixed2(0.6, 0.0);
            }
            else if (isLevel4())
            {
               uv_MainTex_New += fixed2(0.8, 0.0);
            }
        
            fixed4 c = tex2D(_MainTex, uv_MainTex_New);
            clip(c.a - _CutOff);
            o.Albedo = c.rgba;
            o.Emission = c.rgb * _Emission;
        }
        
        ENDCG
    }
    FallBack "Diffuse"
}
