Shader "URP/Environment/WeatherSystem/RainingNear" 
{
	Properties
	{
		_TintColor("Color", Color) = (1,1,1,1)
		_MainTex("Albedo", 2D) = "white" {}
	}

	SubShader
	{
		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
			"RenderPipeline" = "LightweightPipeline"
		}
		Blend SrcAlpha OneMinusSrcAlpha
		ColorMask RGB
		Cull Off Lighting Off ZWrite Off

		Pass {
			Name "ForwardLit"
			Tags{ "LightMode" = "LightweightForward" }
			
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 3.0
			#pragma exclude_renderers d3d11_9x
			#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"
			#include "Weather.hlsl"
			

            TEXTURE2D(_MainTex);	SAMPLER(sampler_MainTex);
			CBUFFER_START(UnityPerMaterial)
				half4  _TintColor;
				float4 _MainTex_ST;
			CBUFFER_END

			half _NearRainIntensity;
			
            struct appdata_t {
                float4 vertex : POSITION;
                half4 color : COLOR;
                float2 texcoord : TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2f {
                float4 vertex : SV_POSITION;
                half4 color : COLOR;
                float2 texcoord : TEXCOORD0;
                UNITY_VERTEX_OUTPUT_STEREO
            };

            v2f vert (appdata_t v)
            {
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				
				float3 wsPos = TransformObjectToWorld(v.vertex.xyz);
				float4 rainOccCoord = GetRainningOcclusionCoord(wsPos);
				half rainningMask = GetRainningOcclusion(rainOccCoord);
			
				
				// TODO : ???
				v.color = 1;
				rainningMask = 1;
				// TODO end

				v.vertex.xyz *= rainningMask;
				
                o.vertex = TransformObjectToHClip(v.vertex.xyz);
				
                o.color = v.color * _TintColor * rainningMask;
                o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);

					
				
                return o;
            }

            half4 frag (v2f i) : SV_Target
            {
				
                half4 col = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
			
                col.a = saturate(col.a*_NearRainIntensity); 
				
                return col;
            }
            ENDHLSL
        }



	}

	FallBack Off
}
