Shader /*ase_name*/ "Hidden/FZDL_Shader/JR_Template_Particle" /*end*/
{
	Properties
	{
		/*ase_props*/

        [Header(Advanced)]
        [Main(Soft Particle,_SOFTPARTICLES_ON,0)] FZDL_SOFT_PARTICLE("Soft Particle",float) = 0
        [Title(Soft Particle,Distance)]
        // [Sub(Soft Particle)] _SoftParticle_Near("Near",Range(0.0 , 5.0)) = 1 
        // [Sub(Soft Particle)] _SoftParticle_Far("far",Range(0.0 , 10.0)) = 1 
        [Sub(Soft Particle)] _DepthFade("Depth Fade",Range( 0.001 , 20)) = 0.1 
        [Sub(Soft Particle)] _DepthThresh("Depth Thresh",Range( 0.001 , 20)) = 2 

        [Main(Edge Particle,_EDGE_ON,0)] FZDL_EDGE_PARTICLE("Edge Particle",float) = 0
        [Title(Edge Particle, EdgeValue)]
        [SubToggle(Edge Particle, _EDGE_WITHOUTMASK_ON)] _EdgeMaskWithOut("Edge mask without", float) = 0
        [Sub(Edge Particle)] [HDR]_EdgeColor("Edge Color", color) = (1,1,1,1)
        [Sub(Edge Particle)] _EdgeRange("Edge Range",Range( 0.001 , 20)) = 0.1 
        [Sub(Edge Particle)] _EdgeThresh("Edge Thresh",Range( 0.001 , 20)) = 2 

        [Main(Camera Fading,_FADING_ON,0)] FZDL_CAMERA_FADE("Camera Fading",float) = 0
        [Title(Camera Fading,Distance)]
        [Sub(Camera Fading)] _Fade_Near("Near",float) = 1 
        [Sub(Camera Fading)] _Fade_Far("far",float) = 1 

        [Toggle(_VOLUMETRIC_FOG_ON)] _VolumetricFog("Volumetric Fog",float) = 1
        [Toggle(_ALPHATEST_ON)] _AlphaTest("Alpha Test",float) = 0

		[Header(CullMode)]
        [Enum(UnityEngine.Rendering.CullMode)]_Cull("剔除模式", float) = 2

        [Header(Depth)]
        [Enum(Off, 0, On, 1)]_ZWrite("是否写入深度", float) = 0

        [Enum(UnityEngine.Rendering.BlendMode)]_Src("源颜色", float) = 5
        [Enum(UnityEngine.Rendering.BlendMode)]_Dst("目标颜色", float) = 10
        [Enum(UnityEngine.Rendering.BlendOp)]_BlendOp("混合模式", float) = 0
	}
	
	SubShader
	{
		/*ase_subshader_options:Name=Settings
			Option:GPU Instancing:false,true:true
				true:SetDefine:pragma multi_compile_instancing
				false:RemoveDefine:pragma multi_compile_instancing
Option:Use Alpha Clip:false,true:false
true:SetDefine:_ALPHATEST_ON 1
false:RemoveDefine:_ALPHATEST_ON 1
		*/		


            
                  
                  
        Tags 
        { 
            "RenderPipeline" = "UniversalPipeline"
            "RenderType" = "Transparent"
            "Queue" = "Transparent+100"
        }
 
		/*ase_pass*/
 
		Pass
		{ 
            Name "Forward"
            Tags{ }
			
            Cull [_Cull]
            ZWrite [_ZWrite]
            Blend [_Src] [_Dst]
            BlendOp [_BlendOp]
            LOD 100

			HLSLPROGRAM



            #pragma shader_feature_local _SOFTPARTICLES_ON
            #pragma shader_feature_local _EDGE_ON
            #pragma shader_feature_local _EDGE_WITHOUTMASK_ON
            #pragma shader_feature_local _FADING_ON
            #pragma shader_feature_local _ALPHATEST_ON
            #pragma shader_feature_local _VOLUMETRIC_FOG_ON

            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
            #include "../../Shader/HLSL/Environment/Sky&Fog/VolumetricFogForObject.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
            /*ase_pragma*/


            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                half4 color : COLOR;
                /*ase_vdata:p=p;uv0=tc0.xy;c=c*/
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };
 
            struct v2f
            {
                half4 color                     : COLOR;
                float4 uv                       : TEXCOORD0;
                float4 vertex                   : SV_POSITION;
            #if defined(_SOFTPARTICLES_ON) || defined(_EDGE_ON) || defined(_FADING_ON) || defined(_DISTORTION_ON)
                float4 JRScreen        : TEXCOORD1;
            #endif

            #if defined(_VOLUMETRIC_FOG_ON)
                float4 fogCoord : TEXCOORD2;
            #endif    
                /*ase_interp(3,):sp=sp.xyzw;uv0=tc0.xy;c=c;uv1=tc1.xyzw;uv2=tc2.xyzw*/
                UNITY_VERTEX_INPUT_INSTANCE_ID     
                UNITY_VERTEX_OUTPUT_STEREO           
            };


            CBUFFER_START(UnityPerMaterial)
            float _Fade_Near;
            float _Fade_Far;
            // float _SoftParticle_Near;       //无用参数
            // float _SoftParticle_Far;        //无用参数
            float _DepthFade;
            float _DepthThresh;

            float4 _EdgeColor;
            float _EdgeRange;
            float _EdgeThresh;
            CBUFFER_END

            TEXTURE2D(_CameraColorTexture);
            SAMPLER(sampler_CameraColorTexture);
            // TEXTURE2D(_CameraDepthTexture);
            // SAMPLER(sampler_CameraDepthTexture);

            /*ase_globals*/

            v2f vert (appdata v /*ase_vert_input*/)
            {
                v2f o;
                UNITY_SETUP_INSTANCE_ID ( v );
                UNITY_TRANSFER_INSTANCE_ID(v, o);

                // ase common template code
                /*ase_vert_code:v=appdata;o=v2f*/

                float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3*/0/*end*/;

                VertexPositionInputs PosIN = GetVertexPositionInputs(v.vertex.xyz + vertexValue);
                o.vertex = PosIN.positionCS;
                o.uv.xy = v.uv;
            #if defined(_SOFTPARTICLES_ON) || defined(_EDGE_ON) || defined(_FADING_ON) || defined(_DISTORTION_ON)
                o.JRScreen = ComputeScreenPos(PosIN.positionCS);
            #endif
                o.color = v.color;

            #if defined(_VOLUMETRIC_FOG_ON)    
                o.fogCoord = VolumetricFog_GetFogCoord(PosIN.positionNDC, PosIN.positionVS.z);
            #endif    

                return o;
            }

            half4 frag (v2f i /*ase_frag_input*/) : SV_Target
            {   

                // ase common template code
                /*ase_frag_code:i=v2f*/


                half3 fin_rgb = /*ase_frag_out:Color;Float3*/1/*end*/;
                half fin_a = /*ase_frag_out:Alpha;Float*/1/*end*/;
            #if defined(_EDGE_ON)
                float4 screenPos2 = i.JRScreen;
                float2 uv2 = UnityStereoTransformScreenSpaceTex(screenPos2.xy / screenPos2.w);
                float eyeDepth2 = LinearEyeDepth((SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, uv2)).r,_ZBufferParams);
                float TempOutput2 = eyeDepth2 - screenPos2.w;
                half edge = (1 - lerp( saturate(_EdgeRange * TempOutput2) , 1 , saturate(TempOutput2 / _EdgeThresh)));
                half3 edgeColor = edge * _EdgeColor.rgb;
            #if defined(_EDGE_WITHOUTMASK_ON)
                //edge = (1 - lerp( saturate(_EdgeRange * TempOutput2) , 1 , saturate(TempOutput2 / _EdgeThresh))) * _EdgeColor.rgb;
                fin_a = saturate(edge + fin_a);
            #endif
                fin_rgb = lerp(fin_rgb, edgeColor,edge);
            #endif


                //alphatest
            #ifdef _ALPHATEST_ON
                half clip_thresh = /*ase_frag_out:clip thresh;Float*/0/*end*/;

                AlphaDiscard(fin_a, clip_thresh);

            #endif
 
                fin_rgb *= i.color;

            #if defined(_SOFTPARTICLES_ON)
                float4 screenPos = i.JRScreen;
                float2 uv = UnityStereoTransformScreenSpaceTex(screenPos.xy / screenPos.w);
                //float eyeDepth = Linear01Depth(SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, screenPos).r, _ZBufferParams);
                float eyeDepth = LinearEyeDepth((SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, uv)).r,_ZBufferParams);
                float TempOutput = eyeDepth - screenPos.w;
                fin_a = lerp( saturate(_DepthFade * TempOutput) , 1 , saturate(TempOutput / _DepthThresh)) * fin_a;
                //fin_a *= SoftParticles(_SoftParticle_Near,1.0/(_SoftParticle_Far - _SoftParticle_Near),i.projectedPosition);
            #endif


 
            #if defined(_FADING_ON)
                fin_a *= CameraFade(_Fade_Near, 1.0/(_Fade_Far - _Fade_Near), i.JRScreen);
            #endif

            #if defined(_DISTORTION_ON)
                float2 distortionOffset = /*ase_frag_out:Distortion;Float3*/0/*end*/;
                float distortionBlend = /*ase_frag_out:Distortion Intensity;Float*/0/*end*/;
                float2 screenUV = (i.projectedPosition.xy / i.projectedPosition.w) + distortionOffset;
                screenUV = UnityStereoTransformScreenSpaceTex(screenUV);
                float4 Distortion = SAMPLE_TEXTURE2D_X(_CameraColorTexture, sampler_CameraColorTexture, screenUV);
                fin_rgb = lerp( Distortion.rgb, fin_rgb,saturate(fin_a - distortionBlend));
            #endif      


            #if defined(_VOLUMETRIC_FOG_ON)    
                fin_rgb = i.fogCoord.w == 0 ? fin_rgb : VolumetricFog_GetFog(fin_rgb, i.fogCoord);
            #endif  

                return half4(fin_rgb,fin_a);
            }
            ENDHLSL
		}
	}

    CustomEditor "FZDL.ShaderDrawer.LWGUI" 
    FallBack "Hidden/InternalErrorShader"
}