// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X 
Shader "FZDL_Shader/Environment/JR_Env_Cloud"
{
	Properties
	{
		[HideInInspector] _AlphaCutoff("Alpha Cutoff ", Range(0, 1)) = 0.5
		[HideInInspector] _EmissionColor("Emission Color", Color) = (1,1,1,1)
		[ASEBegin]_MainTex("MainTex", 2D) = "white" {}
		_Noise("Noise", 2D) = "white" {}
		_Noise_Scale("Noise_Scale", Range( 0 , 1)) = 0
		_Noise_Speed_U("Noise_Speed_U", Float) = 0
		_Noise_Speed_V("Noise_Speed_V", Float) = 0
		_DarkColor("DarkColor", Color) = (0.5,0.5,0.5,0)
		_LightColor("LightColor", Color) = (1,1,1,0)
		_EdgeColor("EdgeColor", Color) = (1,1,1,0)
		[ASEEnd]_Dissolve("Dissolve", Range( 0 , 1)) = 0


        [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(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) = 0
        [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
	{
				


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

			HLSLPROGRAM



            #pragma multi_compile_instancing
            #define ASE_SRP_VERSION 70501




            #pragma shader_feature_local _SOFTPARTICLES_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"
            


            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                half4 color : COLOR;
                float3 ase_normal : NORMAL;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };
 
            struct v2f
            {
                half4 color                     : COLOR;
                float4 uv                       : TEXCOORD0;
                float4 vertex                   : SV_POSITION;
            #if defined(_SOFTPARTICLES_ON) || defined(_FADING_ON) || defined(_DISTORTION_ON)
                float4 JRScreen        : TEXCOORD1;
            #endif

            #if defined(_VOLUMETRIC_FOG_ON)
                float4 fogCoord : TEXCOORD2;
            #endif    
                float4 ase_texcoord3 : TEXCOORD3;
                UNITY_VERTEX_INPUT_INSTANCE_ID     
                UNITY_VERTEX_OUTPUT_STEREO           
            };


            CBUFFER_START(UnityPerMaterial)
            float4 _DarkColor;
            float4 _LightColor;
            float4 _Noise_ST;
            float4 _MainTex_ST;
            float4 _EdgeColor;
            float _Noise_Speed_U;
            float _Noise_Speed_V;
            float _Noise_Scale;
            float _Dissolve;
            float _Fade_Near;
            float _Fade_Far;
            // float _SoftParticle_Near;       //无用参数
            // float _SoftParticle_Far;        //无用参数
            float _DepthFade;
            float _DepthThresh;
            CBUFFER_END

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

            sampler2D _MainTex;
            sampler2D _Noise;


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

                // ase common template code
                float3 ase_worldNormal = TransformObjectToWorldNormal(v.ase_normal);
                o.ase_texcoord3.xyz = ase_worldNormal;
                
                
                //setting value to unused interpolator channels and avoid initialization warnings
                o.ase_texcoord3.w = 0;

                float3 vertexValue = 0;

                VertexPositionInputs PosIN = GetVertexPositionInputs(v.vertex.xyz + vertexValue);
                o.vertex = PosIN.positionCS;
                o.uv.xy = v.uv;
            #if defined(_SOFTPARTICLES_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 ) : SV_Target
            {   

                // ase common template code
                float2 appendResult40 = (float2(_Noise_Speed_U , _Noise_Speed_V));
                float2 uv_Noise = i.uv.xy * _Noise_ST.xy + _Noise_ST.zw;
                float2 panner37 = ( 1.0 * _Time.y * appendResult40 + uv_Noise);
                float4 tex2DNode31 = tex2D( _Noise, panner37 );
                float2 appendResult33 = (float2(tex2DNode31.r , tex2DNode31.g));
                float2 uv_MainTex = i.uv.xy * _MainTex_ST.xy + _MainTex_ST.zw;
                float4 tex2DNode20 = tex2D( _MainTex, ( ( appendResult33 * _Noise_Scale ) + uv_MainTex ) );
                float4 lerpResult73 = lerp( _DarkColor , _LightColor , tex2DNode20.r);
                float3 ase_worldNormal = i.ase_texcoord3.xyz;
                float dotResult72 = dot( -_MainLightPosition.xyz , ase_worldNormal );
                float4 lerpResult76 = lerp( lerpResult73 , _EdgeColor , ( saturate( dotResult72 ) * tex2DNode20.g ));
                


                half3 fin_rgb = lerpResult76.rgb;
                half fin_a = ( tex2DNode20.a * saturate( (0.0 + (tex2DNode20.b - 0.0) * (( 1.0 - _Dissolve ) - 0.0) / (0.5 - 0.0)) ) );


                //alphatest
            #ifdef _ALPHATEST_ON
                half clip_thresh = 0;

                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 = 0;
                float distortionBlend = 0;
                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"
	
}/*ASEBEGIN
Version=18800
1920;58;1920;1001;3370.047;856.186;2.542575;True;False
Node;AmplifyShaderEditor.RangedFloatNode;39;-2555.203,540.9362;Inherit;False;Property;_Noise_Speed_V;Noise_Speed_V;4;0;Create;True;0;0;0;False;0;False;0;0.01;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;38;-2555.203,463.9361;Inherit;False;Property;_Noise_Speed_U;Noise_Speed_U;3;0;Create;True;0;0;0;False;0;False;0;-0.03;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.TextureCoordinatesNode;36;-2546.203,332.9361;Inherit;False;0;31;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.DynamicAppendNode;40;-2365.203,484.9361;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.PannerNode;37;-2236.203,336.9361;Inherit;False;3;0;FLOAT2;0,0;False;2;FLOAT2;0,0;False;1;FLOAT;1;False;1;FLOAT2;0
Node;AmplifyShaderEditor.SamplerNode;31;-2008.205,307.9361;Inherit;True;Property;_Noise;Noise;1;0;Create;True;0;0;0;False;0;False;-1;59b16ecd58fc02445a88231894ea915a;59b16ecd58fc02445a88231894ea915a;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.RangedFloatNode;35;-1953.205,520.9362;Inherit;False;Property;_Noise_Scale;Noise_Scale;2;0;Create;True;0;0;0;False;0;False;0;0.015;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.DynamicAppendNode;33;-1718.205,336.9361;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.WorldSpaceLightDirHlpNode;67;-1317.302,-56.75598;Inherit;False;False;1;0;FLOAT;0;False;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;34;-1570.205,419.9361;Inherit;False;2;2;0;FLOAT2;0,0;False;1;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.TextureCoordinatesNode;41;-1329.854,432.5001;Inherit;False;0;20;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleAddOpNode;42;-1051.876,412.4928;Inherit;False;2;2;0;FLOAT2;0,0;False;1;FLOAT2;0,0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.WorldNormalVector;68;-1112.302,16.24402;Inherit;False;False;1;0;FLOAT3;0,0,1;False;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.NegateNode;71;-1098.302,-56.75598;Inherit;False;1;0;FLOAT3;0,0,0;False;1;FLOAT3;0
Node;AmplifyShaderEditor.RangedFloatNode;82;-591.015,758.5974;Inherit;False;Property;_Dissolve;Dissolve;8;0;Create;True;0;0;0;False;0;False;0;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.DotProductOpNode;72;-901.3019,-7.755974;Inherit;True;2;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SamplerNode;20;-790.5823,385.5341;Inherit;True;Property;_MainTex;MainTex;0;0;Create;True;0;0;0;False;0;False;-1;c47c8f29c11ca0b4eb26b26d0f284664;c47c8f29c11ca0b4eb26b26d0f284664;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.OneMinusNode;86;-267.5979,762.3965;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SaturateNode;79;-694.3612,-7.573235;Inherit;True;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.ColorNode;74;-367.1689,-355.3444;Inherit;False;Property;_DarkColor;DarkColor;5;0;Create;True;0;0;0;False;0;False;0.5,0.5,0.5,0;0,0,0,0;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.ColorNode;75;-362.1689,-178.3444;Inherit;False;Property;_LightColor;LightColor;6;0;Create;True;0;0;0;False;0;False;1,1,1,0;0,0,0,0;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.TFHCRemapNode;85;-61.5979,631.3965;Inherit;True;5;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0.5;False;3;FLOAT;0;False;4;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;78;34.74995,84.12109;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.LerpOp;73;10.83105,-94.34436;Inherit;False;3;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;2;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.ColorNode;77;375.8672,-58.73235;Inherit;False;Property;_EdgeColor;EdgeColor;7;0;Create;True;0;0;0;False;0;False;1,1,1,0;0,0,0,0;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SaturateNode;87;223.4021,631.3965;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.LerpOp;76;797.5311,-66.54435;Inherit;True;3;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;2;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.SaturateNode;84;236.0435,407.6605;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleSubtractOpNode;81;-7.541191,382.0302;Inherit;True;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;83;457.623,482.9441;Inherit;True;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;1214.6,11.19999;Float;False;True;-1;2;FZDL.ShaderDrawer.LWGUI;0;19;FZDL_Shader/Environment/JR_Env_Cloud;f6a8202377f89fa43a72ef913b737a61;True;Forward;0;0;Forward;6;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Transparent=RenderType;Queue=Transparent=Queue=100;False;0;True;1;0;True;-5;0;True;-6;0;1;False;-1;0;False;-1;True;0;True;-7;0;False;-1;False;False;False;False;False;False;False;True;0;True;-8;False;False;False;False;False;True;0;True;-4;False;False;True;0;False;0;Hidden/InternalErrorShader;0;0;Standard;2;GPU Instancing;1;Use Alpha Clip;0;0;1;True;False;;False;0
WireConnection;40;0;38;0
WireConnection;40;1;39;0
WireConnection;37;0;36;0
WireConnection;37;2;40;0
WireConnection;31;1;37;0
WireConnection;33;0;31;1
WireConnection;33;1;31;2
WireConnection;34;0;33;0
WireConnection;34;1;35;0
WireConnection;42;0;34;0
WireConnection;42;1;41;0
WireConnection;71;0;67;0
WireConnection;72;0;71;0
WireConnection;72;1;68;0
WireConnection;20;1;42;0
WireConnection;86;0;82;0
WireConnection;79;0;72;0
WireConnection;85;0;20;3
WireConnection;85;4;86;0
WireConnection;78;0;79;0
WireConnection;78;1;20;2
WireConnection;73;0;74;0
WireConnection;73;1;75;0
WireConnection;73;2;20;1
WireConnection;87;0;85;0
WireConnection;76;0;73;0
WireConnection;76;1;77;0
WireConnection;76;2;78;0
WireConnection;84;0;81;0
WireConnection;81;0;20;3
WireConnection;83;0;20;4
WireConnection;83;1;87;0
WireConnection;0;0;76;0
WireConnection;0;1;83;0
ASEEND*/
//CHKSM=D3A89F0D3D1300B97872431D30A3EA211CE52B67