// Made with Amplify Shader Editor v1.9.6.3
// Available at the Unity Asset Store - http://u3d.as/y3X 
Shader "Erosion_Voroni_Shader"
{
	Properties
	{
		_Cutoff( "Mask Clip Value", Float ) = -13.45
		_Smoothness("Smoothness", Range( 0 , 1)) = 0
		[HDR]_EmissionColor("Emission Color", Color) = (0,0,0,0)
		_Displacement("Displacement", Range( -1 , 1)) = 0
		[HDR]_Color("Color", Color) = (11.31371,2.902469,1.243915,1)
		[HideInInspector] _texcoord( "", 2D ) = "white" {}
		[HideInInspector] _texcoord2( "", 2D ) = "white" {}
		[HideInInspector] __dirty( "", Int ) = 1
	}

	SubShader
	{
		Tags{ "RenderType" = "TransparentCutout"  "Queue" = "AlphaTest+0" "IsEmissive" = "true"  }
		Cull Back
		CGPROGRAM
		#include "UnityShaderVariables.cginc"
		#pragma target 3.0
		#pragma surface surf Standard keepalpha addshadow fullforwardshadows vertex:vertexDataFunc 
		#undef TRANSFORM_TEX
		#define TRANSFORM_TEX(tex,name) float4(tex.xy * name##_ST.xy + name##_ST.zw, tex.z, tex.w)
		struct Input
		{
			float4 vertexColor : COLOR;
			float2 uv_texcoord;
			float4 uv2_texcoord2;
		};

		uniform float _Displacement;
		uniform float4 _Color;
		uniform float4 _EmissionColor;
		uniform float _Smoothness;
		uniform float _Cutoff = -13.45;


		inline float noise_randomValue (float2 uv) { return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453); }

		inline float noise_interpolate (float a, float b, float t) { return (1.0-t)*a + (t*b); }

		inline float valueNoise (float2 uv)
		{
			float2 i = floor(uv);
			float2 f = frac( uv );
			f = f* f * (3.0 - 2.0 * f);
			uv = abs( frac(uv) - 0.5);
			float2 c0 = i + float2( 0.0, 0.0 );
			float2 c1 = i + float2( 1.0, 0.0 );
			float2 c2 = i + float2( 0.0, 1.0 );
			float2 c3 = i + float2( 1.0, 1.0 );
			float r0 = noise_randomValue( c0 );
			float r1 = noise_randomValue( c1 );
			float r2 = noise_randomValue( c2 );
			float r3 = noise_randomValue( c3 );
			float bottomOfGrid = noise_interpolate( r0, r1, f.x );
			float topOfGrid = noise_interpolate( r2, r3, f.x );
			float t = noise_interpolate( bottomOfGrid, topOfGrid, f.y );
			return t;
		}


		float SimpleNoise(float2 UV)
		{
			float t = 0.0;
			float freq = pow( 2.0, float( 0 ) );
			float amp = pow( 0.5, float( 3 - 0 ) );
			t += valueNoise( UV/freq )*amp;
			freq = pow(2.0, float(1));
			amp = pow(0.5, float(3-1));
			t += valueNoise( UV/freq )*amp;
			freq = pow(2.0, float(2));
			amp = pow(0.5, float(3-2));
			t += valueNoise( UV/freq )*amp;
			return t;
		}


float2 voronoihash76( float2 p )
{
	
	p = float2( dot( p, float2( 127.1, 311.7 ) ), dot( p, float2( 269.5, 183.3 ) ) );
	return frac( sin( p ) *43758.5453);
}


float voronoi76( float2 v, float time, inout float2 id, inout float2 mr, float smoothness, inout float2 smoothId )
{
	float2 n = floor( v );
	float2 f = frac( v );
	float F1 = 8.0;
	float F2 = 8.0; float2 mg = 0;
	for ( int j = -1; j <= 1; j++ )
	{
		for ( int i = -1; i <= 1; i++ )
	 	{
	 		float2 g = float2( i, j );
	 		float2 o = voronoihash76( n + g );
			o = ( sin( time + o * 6.2831 ) * 0.5 + 0.5 ); float2 r = f - g - o;
			float d = 0.5 * dot( r, r );
	 //		if( d<F1 ) {
	 //			F2 = F1;
	 			float h = smoothstep(0.0, 1.0, 0.5 + 0.5 * (F1 - d) / smoothness); F1 = lerp(F1, d, h) - smoothness * h * (1.0 - h);mg = g; mr = r; id = o;
	 //		} else if( d<F2 ) {
	 //			F2 = d;
	
	 //		}
	 	}
	}
	return F1;
}


		void vertexDataFunc( inout appdata_full v, out Input o )
		{
			UNITY_INITIALIZE_OUTPUT( Input, o );
			float4 color63 = IsGammaSpace() ? float4(0,0,0,0) : float4(0,0,0,0);
			float3 ase_vertexNormal = v.normal.xyz;
			float2 panner42 = ( 1.0 * _Time.y * float2( 0.5,0 ) + float2( 0,0 ));
			float2 uv_TexCoord37 = v.texcoord.xy + panner42;
			float simpleNoise35 = SimpleNoise( uv_TexCoord37*20.0 );
			float4 lerpResult38 = lerp( color63 , float4( ( ase_vertexNormal * saturate( simpleNoise35 ) ) , 0.0 ) , _Displacement);
			v.vertex.xyz += lerpResult38.rgb;
			v.vertex.w = 1;
		}

		void surf( Input i , inout SurfaceOutputStandard o )
		{
			float mulTime25 = _Time.y * 5.0;
			float time76 = mulTime25;
			float2 voronoiSmoothId76 = 0;
			float voronoiSmooth76 = 0.2;
			float2 coords76 = i.uv_texcoord * 10.0;
			float2 id76 = 0;
			float2 uv76 = 0;
			float voroi76 = voronoi76( coords76, time76, id76, uv76, voronoiSmooth76, voronoiSmoothId76 );
			float temp_output_78_0 = (0.05 + (voroi76 - 0.0) * (1.0 - 0.05) / (1.0 - 0.0));
			o.Albedo = ( i.vertexColor * ( _Color * pow( temp_output_78_0 , i.uv2_texcoord2.y ) ) ).rgb;
			o.Emission = _EmissionColor.rgb;
			o.Smoothness = _Smoothness;
			o.Alpha = 1;
			float clampResult21 = clamp( i.uv2_texcoord2.x , 0.0 , 1.0 );
			clip( temp_output_78_0 - clampResult21);
			clip( 1.0 - _Cutoff );
		}

		ENDCG
	}
	Fallback "Diffuse"
	CustomEditor "ASEMaterialInspector"
}
/*ASEBEGIN
Version=19603
Node;AmplifyShaderEditor.PannerNode;42;-442.1204,935.5111;Inherit;False;3;0;FLOAT2;0,0;False;2;FLOAT2;0.5,0;False;1;FLOAT;1;False;1;FLOAT2;0
Node;AmplifyShaderEditor.SimpleTimeNode;25;-960,224;Inherit;False;1;0;FLOAT;5;False;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;77;-960,320;Inherit;False;Constant;_Float0;Float 0;5;0;Create;True;0;0;0;False;0;False;0.2;0;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.TextureCoordinatesNode;37;-225.5655,829.0217;Inherit;False;0;-1;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.VoronoiNode;76;-752,224;Inherit;True;0;0;1;0;1;False;1;False;True;False;4;0;FLOAT2;0,0;False;1;FLOAT;0;False;2;FLOAT;10;False;3;FLOAT;0;False;3;FLOAT;0;FLOAT2;1;FLOAT2;2
Node;AmplifyShaderEditor.TexCoordVertexDataNode;27;-585.9583,-47.98422;Inherit;True;1;4;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.NoiseGeneratorNode;35;47.79927,763.3312;Inherit;True;Simple;True;False;2;0;FLOAT2;88.99,1;False;1;FLOAT;20;False;1;FLOAT;0
Node;AmplifyShaderEditor.TFHCRemapNode;78;-464,224;Inherit;True;5;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;1;False;3;FLOAT;0.05;False;4;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.SaturateNode;71;314.3044,813.9454;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.NormalVertexDataNode;70;90.38747,613.2319;Inherit;False;0;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.TexCoordVertexDataNode;20;-601.5312,532.8273;Inherit;True;1;4;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.PowerNode;26;-193.599,83.3246;Inherit;False;False;2;0;FLOAT;0;False;1;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.ColorNode;73;-304.5495,-182.6996;Inherit;False;Property;_Color;Color;4;1;[HDR];Create;True;0;0;0;False;0;False;11.31371,2.902469,1.243915,1;11.31371,1.243916,9.593297,1;True;True;0;6;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4;FLOAT3;5
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;4;-18.08475,-40.45285;Inherit;True;2;2;0;COLOR;15,0,0,0;False;1;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;72;496.8785,676.361;Inherit;True;2;2;0;FLOAT3;0,0,0;False;1;FLOAT;0;False;1;FLOAT3;0
Node;AmplifyShaderEditor.VertexColorNode;28;17.04175,-210.9842;Inherit;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.ClampOpNode;21;-312.5313,535.8273;Inherit;False;3;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;39;367.8818,933.4809;Inherit;False;Property;_Displacement;Displacement;3;0;Create;True;0;0;0;False;0;False;0;0.272;-1;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.ColorNode;63;300.6651,447.6341;Inherit;False;Constant;_Color0;Color 0;5;0;Create;True;0;0;0;False;0;False;0,0,0,0;0,0,0,0;True;True;0;6;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4;FLOAT3;5
Node;AmplifyShaderEditor.RangedFloatNode;31;600.8024,170.2696;Inherit;False;Property;_Smoothness;Smoothness;1;0;Create;True;0;0;0;False;0;False;0;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.ColorNode;30;305.714,11.54015;Inherit;False;Property;_EmissionColor;Emission Color;2;1;[HDR];Create;True;0;0;0;False;0;False;0,0,0,0;0.01176471,0,0.006449694,1;True;True;0;6;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4;FLOAT3;5
Node;AmplifyShaderEditor.LerpOp;38;759.3436,603.9972;Inherit;True;3;0;COLOR;0,0,0,0;False;1;COLOR;1,0,0,0;False;2;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;29;299.0417,-106.9842;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.ClipNode;8;-61.59589,342.9718;Inherit;True;3;0;FLOAT;1;False;1;FLOAT;0;False;2;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.StandardSurfaceOutputNode;19;1109.509,-2.598209;Float;False;True;-1;2;ASEMaterialInspector;0;0;Standard;Erosion_Voroni_Shader;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;;0;False;;False;0;False;;0;False;;False;0;Masked;-13.45;True;True;0;False;TransparentCutout;;AlphaTest;All;12;all;True;True;True;True;0;False;;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;False;2;15;10;25;False;0.5;True;0;5;False;;10;False;;0;5;False;;10;False;;0;False;;0;False;;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;True;Relative;0;;0;-1;-1;-1;0;False;0;0;False;;-1;0;False;;0;0;0;False;0.1;False;;0;False;;False;17;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;16;FLOAT4;0,0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
WireConnection;37;1;42;0
WireConnection;76;1;25;0
WireConnection;76;3;77;0
WireConnection;35;0;37;0
WireConnection;78;0;76;0
WireConnection;71;0;35;0
WireConnection;26;0;78;0
WireConnection;26;1;27;2
WireConnection;4;0;73;0
WireConnection;4;1;26;0
WireConnection;72;0;70;0
WireConnection;72;1;71;0
WireConnection;21;0;20;1
WireConnection;38;0;63;0
WireConnection;38;1;72;0
WireConnection;38;2;39;0
WireConnection;29;0;28;0
WireConnection;29;1;4;0
WireConnection;8;1;78;0
WireConnection;8;2;21;0
WireConnection;19;0;29;0
WireConnection;19;2;30;0
WireConnection;19;4;31;0
WireConnection;19;10;8;0
WireConnection;19;11;38;0
ASEEND*/
//CHKSM=1609A0EDAB3D94299225D2DD25BC7A376066E423