﻿Shader "Mobile/Brightness2"
{
    Properties
    {
    }
    SubShader
    {
        Pass
        {
			ZTest Always Cull Off ZWrite Off
            
			CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"


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

            
			half _Brightness;
			half _Saturation;
			half _Contrast;
			

            v2f vert (appdata_img v)
            {
                v2f o;
                o.vertex = v.vertex;
                o.uv = ComputeScreenPos( o.vertex );
				//#if UNITY_UV_STARTS_AT_TOP
				//	if (_MainTex_TexelSize.y < 0)
				//		o.uv.y = 1-o.uv.y;
				//#endif
                return o;
            }
			
			sampler2D _ScreenTex;
			float4 _ScreenTex_TexelSize;

            fixed4 frag (v2f i) : SV_Target
            {
				fixed4 renderTex = tex2D(_ScreenTex, (i.uv.xy/i.uv.w) );
                // 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
        }
    }
}
