﻿Shader "Mobile/Brightness"
{
    Properties
    {
	_MainTex ("textue", 2D) = "white" {}
    }
    SubShader
    {
        Pass
        {
		ZTest Always Cull Off ZWrite Off
           
			CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"


            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
			float4 _MainTex_TexelSize;
			half _Brightness;
			half _Saturation;
			half _Contrast;

            v2f vert (appdata_img v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.texcoord;

                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
				fixed4 renderTex = tex2D(_MainTex, i.uv);
                // apply Brightness
				fixed3 finalColor = renderTex.rgb * _Brightness;

				// apply saturation
				fixed luminance = 0.2125*renderTex.r + 0.7154*renderTex.g + 0.0721*renderTex.b;
				fixed3 luminanceColor = fixed3(luminance, luminance, luminance);
				finalColor = lerp(luminanceColor, finalColor, _Saturation);

				// apply contrast
				fixed3 avgColor = fixed3(0.5, 0.5, 0.5);
				finalColor = lerp(avgColor, finalColor, _Contrast);

                return fixed4(finalColor, renderTex.a);
				// return renderTex;
			}
            ENDCG
        }
    }
}
