Shader "URP/Environment/WeatherSystem/RainingFar"
{
	Properties
	{
		_Color("Color", Color) = (1,1,1,1)
		_MainTex("Albedo", 2D) = "white" {}
		_RainSpeed("Rain Speed 2D", Vector) = (1,1,0,0)
	}

	SubShader
	{
		Tags
		{
			"Queue" = "Transparent+999"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
			"RenderPipeline" = "LightweightPipeline"
		}

		Pass
		{
			Name "ForwardLit"
			Tags{ "LightMode" = "LightweightForward" }
			Blend One One
			Cull Front
			ZWrite Off
			//ZTest Off

			HLSLPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_instancing
			#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" 
			#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl"
			#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
			#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

			struct appdata_full {
				float4 vertex : POSITION;
				float4 tangent : TANGENT;
				float3 normal : NORMAL;
				float4 texcoord : TEXCOORD0;
				float4 texcoord1 : TEXCOORD1;
				float4 texcoord2 : TEXCOORD2;
				float4 texcoord3 : TEXCOORD3;
				half4 color : COLOR;
				UNITY_VERTEX_INPUT_INSTANCE_ID
			};

			struct v2f
			{
				float4 pos				: SV_POSITION;
				//float3 viewDir			: TEXCOORD1;
				float2 uv				: TEXCOORD2;
			};

			TEXTURE2D(_MainTex);	SAMPLER(sampler_MainTex);
			float4 _MainTex_ST;
			half4 _Color;
			half2 _RainSpeed;


			//uniform fixed _bias;
			//uniform fixed _strength;
			//uniform fixed _maskCameraFar;
			//uniform float4x4 _maskView;
			//uniform float4x4 _maskVPBias;
			//uniform float4x4 _invProjectMatrix;
			//uniform float4x4 _invViewMatrix;
			//uniform sampler2D _rainMaskTex;
			//uniform sampler2D _SceneDepthTexture;

			v2f vert(appdata_full v)
			{
				v2f o;
				//UNITY_INITIALIZE_OUTPUT(v2f, o);
				o = (v2f)0;
				o.pos = TransformObjectToHClip(v.vertex.xyz);
				//o.viewDir = mul(UNITY_MATRIX_MV, v.vertex).xyz;
				o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
				return o;
			}

			half3 _GlobalLightColor;
			half _GlobalLightIntensity;
			half _FarRainIntensity;

			half4 frag(v2f i) : COLOR
			{
				float2 texCoord = _Time.y * _RainSpeed.xy + i.uv;
				half4 mainTex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, texCoord);
				half4 color = half4(mainTex.r * _Color.rgb, 1) * _FarRainIntensity;
				//color.rgb += mainTex.r * _GlobalLightColor * _GlobalLightIntensity * 0.5;
				color.a = mainTex.r;
				if (color.a < 0.0001f)
					discard;

				/*float4 screenPos = ComputeScreenPos(i.clipPos);
				float depth = SAMPLE_DEPTH_TEXTURE_PROJ(_SceneDepthTexture, UNITY_PROJ_COORD(screenPos));
				float3 posView = normalize(i.viewDir) * LinearEyeDepth(depth);
				float4 posWorld = mul(_invViewMatrix, float4(posView,1));

				float3 rainMaskUV = mul(_maskVPBias, float4(posWorld.xyz, 1));
				rainMaskUV.z = -(mul(_maskView, float4(posWorld.xyz, 1)).z * _maskCameraFar);
				float rainMask = tex2D(_rainMaskTex, rainMaskUV.xy).r;
				float fade = (rainMaskUV.x > 1 || rainMaskUV.x < 0 || rainMaskUV.y > 1 || rainMaskUV.y < 0) ? 1 : max(step(rainMaskUV.z - _bias, rainMask), 0);
				color *= fade;*/
				return color;
			}


			ENDHLSL
		}



	}

	FallBack Off
}
