// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X 
Shader "URP/Effects/Particle/HSV_Add"
{
	Properties
	{
		_MainTex("MainTex", 2D) = "white" {}
		_Depth ("Depth", Float ) = 0.25
		_H("H", Range( -1 , 1)) = 0
		_S("S", Range( -1 , 1)) = 0
		_V("V", Range( -1 , 1)) = 0
	}

	SubShader
		{
			Pass
		{

			Tags{ "RenderType" = "Custom"  "Queue" = "AlphaTest+0" "IsEmissive" = "true"  }
			Cull Back
			ZWrite Off
			Blend One One// , One One
			BlendOp Add
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"
			#include "Include/FX_Depth.cginc"

			struct Attributes
			{
					float4 vertex   : POSITION;
					float2 texcoord     : TEXCOORD0;
					float4 vertexColor  : COLOR;
					UNITY_VERTEX_INPUT_INSTANCE_ID
			};

			struct v2f
			{
				float4 pos : SV_POSITION;
				float4 vertexColor : COLOR;
				float2 uv : TEXCOORD0;
				float4 projPos : TEXCOORD1;
				UNITY_VERTEX_INPUT_INSTANCE_ID
				UNITY_VERTEX_OUTPUT_STEREO
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			float _H;
			float _S;
			float _V;

			float3 HSVToRGB(float3 c)
			{
				float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
				float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
				return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
			}

			float3 RGBToHSV(float3 c)
			{
				float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
				float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
				float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
				float d = q.x - min(q.w, q.y);
				float e = 1.0e-10;
				return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
			}

			v2f vert(Attributes v)
			{
				v2f o;
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_TRANSFER_INSTANCE_ID(v, o);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);

				o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
				o.vertexColor = v.vertexColor;

				//VertexPositionInputs vertexInput = GetVertexPositionInputs(v.positionOS.xyz);
				//o.vertex = vertexInput.positionCS;

				o.pos = UnityObjectToClipPos(v.vertex);
				o.projPos = ComputeScreenPos (o.pos);
                COMPUTE_EYEDEPTH(o.projPos.z);
				return o;
			}

			float4 frag(v2f i) : SV_Target
			{
				UNITY_SETUP_INSTANCE_ID(i);
				UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);

				float4 tex2DNode1 = tex2D(_MainTex, i.uv);
				float3 hsvTorgb6 = RGBToHSV(tex2DNode1.rgb);
				float3 hsvTorgb5 = HSVToRGB(float3((hsvTorgb6.x + _H),(hsvTorgb6.y + _S),(hsvTorgb6.z + _V)));
				//o.Emission = ( float4( hsvTorgb5 , 0.0 ) * tex2DNode1.a * i.vertexColor * i.vertexColor.a ).rgb;
				//o.Alpha = 1;
				tex2DNode1 = (float4(hsvTorgb5*Depth(i.projPos), 0.0) * tex2DNode1.a * i.vertexColor * i.vertexColor.a);
				//tex2DNode1.a = 1;
				return tex2DNode1;
			}
			ENDCG
		}
	}
}
