﻿/*
 * This code is compiled from the ShadowReceiver example from Cyanilux's URP_ShaderGraphCustomLighting repository:
 * https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
 *
 * All credit goes to Cyanilux for this shader
 */

 Shader "Custom/Matte Shadow"
 {
	 Properties
	 {
		 _ShadowColor("Color", Color) = (0, 0, 0, 0)
		 [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0
		 [HideInInspector]_QueueControl("_QueueControl", Float) = -1
		 [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
		 [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
		 [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
	 }
	 SubShader
	 {
		 Tags
		 {
			 "RenderPipeline"="UniversalPipeline"
			 "RenderType"="Transparent"
			 "UniversalMaterialType" = "Unlit"
			 "Queue"="Transparent"
			 "DisableBatching"="False"
			 "ShaderGraphShader"="true"
			 "ShaderGraphTargetId"="UniversalUnlitSubTarget"
		 }
		 Pass
		 {
			 Name "Universal Forward"
			 Tags
			 {
				 // LightMode: <None>
			 }
		 
		 // Render State
		 Cull Back
			 Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
			 ZTest LEqual
			 ZWrite Off
		 
		 // Debug
		 // <None>
		 
		 // --------------------------------------------------
		 // Pass
		 
		 HLSLPROGRAM
		 
		 // Pragmas
		 #pragma target 2.0
			 #pragma multi_compile_instancing
			 #pragma multi_compile_fog
			 #pragma instancing_options renderinglayer
			 #pragma vertex vert
			 #pragma fragment frag
		 
		 // Keywords
		 #pragma multi_compile _ LIGHTMAP_ON
			 #pragma multi_compile _ DIRLIGHTMAP_COMBINED
			 #pragma multi_compile _ USE_LEGACY_LIGHTMAPS
			 #pragma shader_feature _ _SAMPLE_GI
			 #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
			 #pragma multi_compile_fragment _ DEBUG_DISPLAY
			 #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
		 #pragma multi_compile_fragment _ _SHADOWS_SOFT
			 #pragma multi_compile _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
			 
			 
		 
		 // Defines
		 
		 #define ATTRIBUTES_NEED_NORMAL
		 #define ATTRIBUTES_NEED_TANGENT
		 #define FEATURES_GRAPH_VERTEX_NORMAL_OUTPUT
		 #define FEATURES_GRAPH_VERTEX_TANGENT_OUTPUT
		 #define VARYINGS_NEED_POSITION_WS
		 #define VARYINGS_NEED_NORMAL_WS
		 #define FEATURES_GRAPH_VERTEX
		 /* WARNING: $splice Could not find named fragment 'PassInstancing' */
		 #define SHADERPASS SHADERPASS_UNLIT
			 #define _FOG_FRAGMENT 1
			 #define _SURFACE_TYPE_TRANSPARENT 1
		 
		 
		 // custom interpolator pre-include
		 /* WARNING: $splice Could not find named fragment 'sgci_CustomInterpolatorPreInclude' */
		 
		 // Includes
		 #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
		 #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
		 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
		 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
		 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
		 #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
		 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
		 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
		 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
		 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
		 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
		 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
		 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
		 #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
		 
		 // --------------------------------------------------
		 // Structs and Packing
		 
		 // custom interpolators pre packing
		 /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPrePacking' */
		 
		 struct Attributes
			 {
				  float3 positionOS : POSITION;
				  float3 normalOS : NORMAL;
				  float4 tangentOS : TANGENT;
				 #if UNITY_ANY_INSTANCING_ENABLED || defined(ATTRIBUTES_NEED_INSTANCEID)
				  uint instanceID : INSTANCEID_SEMANTIC;
				 #endif
			 };
			 struct Varyings
			 {
				  float4 positionCS : SV_POSITION;
				  float3 positionWS;
				  float3 normalWS;
				 #if UNITY_ANY_INSTANCING_ENABLED || defined(VARYINGS_NEED_INSTANCEID)
				  uint instanceID : CUSTOM_INSTANCE_ID;
				 #endif
				 #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
				  uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
				 #endif
				 #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
				  uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
				 #endif
				 #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
				  FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
				 #endif
			 };
			 struct SurfaceDescriptionInputs
			 {
				  float3 WorldSpacePosition;
			 };
			 struct VertexDescriptionInputs
			 {
				  float3 ObjectSpaceNormal;
				  float3 ObjectSpaceTangent;
				  float3 ObjectSpacePosition;
			 };
			 struct PackedVaryings
			 {
				  float4 positionCS : SV_POSITION;
				  float3 positionWS : INTERP0;
				  float3 normalWS : INTERP1;
				 #if UNITY_ANY_INSTANCING_ENABLED || defined(VARYINGS_NEED_INSTANCEID)
				  uint instanceID : CUSTOM_INSTANCE_ID;
				 #endif
				 #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
				  uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
				 #endif
				 #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
				  uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
				 #endif
				 #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
				  FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
				 #endif
			 };
		 
		 PackedVaryings PackVaryings (Varyings input)
			 {
				 PackedVaryings output;
				 ZERO_INITIALIZE(PackedVaryings, output);
				 output.positionCS = input.positionCS;
				 output.positionWS.xyz = input.positionWS;
				 output.normalWS.xyz = input.normalWS;
				 #if UNITY_ANY_INSTANCING_ENABLED || defined(VARYINGS_NEED_INSTANCEID)
				 output.instanceID = input.instanceID;
				 #endif
				 #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
				 output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
				 #endif
				 #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
				 output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
				 #endif
				 #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
				 output.cullFace = input.cullFace;
				 #endif
				 return output;
			 }
			 
			 Varyings UnpackVaryings (PackedVaryings input)
			 {
				 Varyings output;
				 output.positionCS = input.positionCS;
				 output.positionWS = input.positionWS.xyz;
				 output.normalWS = input.normalWS.xyz;
				 #if UNITY_ANY_INSTANCING_ENABLED || defined(VARYINGS_NEED_INSTANCEID)
				 output.instanceID = input.instanceID;
				 #endif
				 #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
				 output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
				 #endif
				 #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
				 output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
				 #endif
				 #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
				 output.cullFace = input.cullFace;
				 #endif
				 return output;
			 }
			 
		 
		 // --------------------------------------------------
		 // Graph
		 
		 // Graph Properties
		 CBUFFER_START(UnityPerMaterial)
			 float4 _ShadowColor;
			 UNITY_TEXTURE_STREAMING_DEBUG_VARS;
			 CBUFFER_END
			 
			 
			 // Object and Global properties
		 
		 // Graph Includes
		 //#include_with_pragmas "Assets/URP_ShaderGraphCustomLighting-main/CustomLighting.hlsl"
		 
		 // -- Property used by ScenePickingPass
		 #ifdef SCENEPICKINGPASS
		 float4 _SelectionID;
		 #endif
		 
		 // -- Properties used by SceneSelectionPass
		 #ifdef SCENESELECTIONPASS
		 int _ObjectId;
		 int _PassValue;
		 #endif
		 
		 // Graph Functions

		 void MainLightShadows_float (float3 WorldPos, half4 Shadowmask, out float ShadowAtten){
			#ifdef SHADERGRAPH_PREVIEW
				ShadowAtten = 1;
			#else
				#if defined(_MAIN_LIGHT_SHADOWS_SCREEN) && !defined(_SURFACE_TYPE_TRANSPARENT)
				float4 shadowCoord = ComputeScreenPos(TransformWorldToHClip(WorldPos));
				#else
				float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
				#endif
				ShadowAtten = MainLightShadow(shadowCoord, WorldPos, Shadowmask, _MainLightOcclusionProbes);
			#endif
		}
		
		void MainLightShadows_float (float3 WorldPos, out float ShadowAtten){
			MainLightShadows_float(WorldPos, half4(1,1,1,1), ShadowAtten);
		}
		 
			 struct Bindings_MainLightShadows_f3ba9248037f69f429d9e52bc2e30940_float
			 {
			 float3 WorldSpacePosition;
			 };
			 
			 void SG_MainLightShadows_f3ba9248037f69f429d9e52bc2e30940_float(float3 Vector3_B87D7B6B, bool Vector3_B87D7B6B_7ea1bbbacf460c879f6d8c85fd91750d_IsConnected, half4 _Shadowmask, Bindings_MainLightShadows_f3ba9248037f69f429d9e52bc2e30940_float IN, out float ShadowAtten_4)
			 {
			 float3 _Property_65e443cb15a9fb859a50ebae06e81569_Out_0_Vector3 = Vector3_B87D7B6B;
			 bool _Property_65e443cb15a9fb859a50ebae06e81569_Out_0_Vector3_IsConnected = Vector3_B87D7B6B_7ea1bbbacf460c879f6d8c85fd91750d_IsConnected;
			 float3 _BranchOnInputConnection_a73253d1c5e2424c89b6af884a7eb179_Out_3_Vector3 = _Property_65e443cb15a9fb859a50ebae06e81569_Out_0_Vector3_IsConnected ? _Property_65e443cb15a9fb859a50ebae06e81569_Out_0_Vector3 : IN.WorldSpacePosition;
			 half4 _Property_3a2eacd6e269401591082a237182fdb5_Out_0_Vector4 = _Shadowmask;
			 float _MainLightShadowsCustomFunction_3be2118d2270ff818ec5f0f1353e249f_ShadowAtten_4_Float;
			 MainLightShadows_float(_BranchOnInputConnection_a73253d1c5e2424c89b6af884a7eb179_Out_3_Vector3, _Property_3a2eacd6e269401591082a237182fdb5_Out_0_Vector4, _MainLightShadowsCustomFunction_3be2118d2270ff818ec5f0f1353e249f_ShadowAtten_4_Float);
			 ShadowAtten_4 = _MainLightShadowsCustomFunction_3be2118d2270ff818ec5f0f1353e249f_ShadowAtten_4_Float;
			 }
			 
			 void Unity_OneMinus_float(float In, out float Out)
			 {
				 Out = 1 - In;
			 }
			 
			 void Unity_Multiply_float_float(float A, float B, out float Out)
			 {
				 Out = A * B;
			 }
		 
		 // Custom interpolators pre vertex
		 /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPreVertex' */
		 
		 // Graph Vertex
		 struct VertexDescription
			 {
				 float3 Position;
				 float3 Normal;
				 float3 Tangent;
			 };
			 
			 VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
			 {
				 VertexDescription description = (VertexDescription)0;
				 description.Position = IN.ObjectSpacePosition;
				 description.Normal = IN.ObjectSpaceNormal;
				 description.Tangent = IN.ObjectSpaceTangent;
				 return description;
			 }
		 
		 // Custom interpolators, pre surface
		 #ifdef FEATURES_GRAPH_VERTEX
		 Varyings CustomInterpolatorPassThroughFunc(inout Varyings output, VertexDescription input)
		 {
		 return output;
		 }
		 #define CUSTOMINTERPOLATOR_VARYPASSTHROUGH_FUNC
		 #endif
		 
		 // Graph Pixel
		 struct SurfaceDescription
			 {
				 float3 BaseColor;
				 float Alpha;
			 };
			 
			 SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
			 {
				 SurfaceDescription surface = (SurfaceDescription)0;
				 float4 _Property_b7156b6c180eec83909a21d448e5f0ff_Out_0_Vector4 = _ShadowColor;
				 Bindings_MainLightShadows_f3ba9248037f69f429d9e52bc2e30940_float _MainLightShadows_bcaa6286f8db748fa05184ae9f24de39;
				 _MainLightShadows_bcaa6286f8db748fa05184ae9f24de39.WorldSpacePosition = IN.WorldSpacePosition;
				 float _MainLightShadows_bcaa6286f8db748fa05184ae9f24de39_ShadowAtten_4_Float;
				 SG_MainLightShadows_f3ba9248037f69f429d9e52bc2e30940_float(float3 (0, 0, 0), false, half4 (1, 1, 1, 1), _MainLightShadows_bcaa6286f8db748fa05184ae9f24de39, _MainLightShadows_bcaa6286f8db748fa05184ae9f24de39_ShadowAtten_4_Float);
				 float _OneMinus_9fd032fbfa178187a186331edf8e300d_Out_1_Float;
				 Unity_OneMinus_float(_MainLightShadows_bcaa6286f8db748fa05184ae9f24de39_ShadowAtten_4_Float, _OneMinus_9fd032fbfa178187a186331edf8e300d_Out_1_Float);
				 float _Split_da961465d51b4fc9a720468376ba6e27_R_1_Float = _Property_b7156b6c180eec83909a21d448e5f0ff_Out_0_Vector4[0];
				 float _Split_da961465d51b4fc9a720468376ba6e27_G_2_Float = _Property_b7156b6c180eec83909a21d448e5f0ff_Out_0_Vector4[1];
				 float _Split_da961465d51b4fc9a720468376ba6e27_B_3_Float = _Property_b7156b6c180eec83909a21d448e5f0ff_Out_0_Vector4[2];
				 float _Split_da961465d51b4fc9a720468376ba6e27_A_4_Float = _Property_b7156b6c180eec83909a21d448e5f0ff_Out_0_Vector4[3];
				 float _Multiply_9c60cc4837f3425696f41abc29412d2e_Out_2_Float;
				 Unity_Multiply_float_float(_OneMinus_9fd032fbfa178187a186331edf8e300d_Out_1_Float, _Split_da961465d51b4fc9a720468376ba6e27_A_4_Float, _Multiply_9c60cc4837f3425696f41abc29412d2e_Out_2_Float);
				 surface.BaseColor = (_Property_b7156b6c180eec83909a21d448e5f0ff_Out_0_Vector4.xyz);
				 surface.Alpha = _Multiply_9c60cc4837f3425696f41abc29412d2e_Out_2_Float;
				 return surface;
			 }
		 
		 // --------------------------------------------------
		 // Build Graph Inputs
		 #ifdef HAVE_VFX_MODIFICATION
		 #define VFX_SRP_ATTRIBUTES Attributes
		 #define VFX_SRP_VARYINGS Varyings
		 #define VFX_SRP_SURFACE_INPUTS SurfaceDescriptionInputs
		 #endif
		 VertexDescriptionInputs BuildVertexDescriptionInputs(Attributes input)
			 {
				 VertexDescriptionInputs output;
				 ZERO_INITIALIZE(VertexDescriptionInputs, output);
			 
				 output.ObjectSpaceNormal =                          input.normalOS;
				 output.ObjectSpaceTangent =                         input.tangentOS.xyz;
				 output.ObjectSpacePosition =                        input.positionOS;
			 #if UNITY_ANY_INSTANCING_ENABLED
			 #else // TODO: XR support for procedural instancing because in this case UNITY_ANY_INSTANCING_ENABLED is not defined and instanceID is incorrect.
			 #endif
			 
				 return output;
			 }
			 
		 SurfaceDescriptionInputs BuildSurfaceDescriptionInputs(Varyings input)
			 {
				 SurfaceDescriptionInputs output;
				 ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
			 
			 #ifdef HAVE_VFX_MODIFICATION
			 #if VFX_USE_GRAPH_VALUES
				 uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex));
				 /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */
			 #endif
				 /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */
			 
			 #endif
			 
				 
			 
			 
			 
			 
			 
				 output.WorldSpacePosition = input.positionWS;
			 
				 #if UNITY_UV_STARTS_AT_TOP
				 #else
				 #endif
			 
			 
			 #if UNITY_ANY_INSTANCING_ENABLED
			 #else // TODO: XR support for procedural instancing because in this case UNITY_ANY_INSTANCING_ENABLED is not defined and instanceID is incorrect.
			 #endif
			 #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
			 #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN output.FaceSign =                    IS_FRONT_VFACE(input.cullFace, true, false);
			 #else
			 #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
			 #endif
			 #undef BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
			 
					 return output;
			 }
			 
		 
		 // --------------------------------------------------
		 // Main
		 
		 #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl"
		 #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl"
		 
		 // --------------------------------------------------
		 // Visual Effect Vertex Invocations
		 #ifdef HAVE_VFX_MODIFICATION
		 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/VisualEffectVertex.hlsl"
		 #endif
		 
		 ENDHLSL
		 }
	 }
	 CustomEditor "UnityEditor.ShaderGraph.GenericShaderGraphMaterialGUI"
	 CustomEditorForRenderPipeline "UnityEditor.ShaderGraphUnlitGUI" "UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset"
	 FallBack "Hidden/Shader Graph/FallbackError"
 }