Shader "LSQ/EffectAchievement/BloodstainParticle"
{
SubShader
{
Tags
{
"RenderType"="Transparent"
"Queue"="Transparent"
"IgnoreProjector"="true"
"DisableBatching"="true"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
half4 color : COLOR;
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 texcoord : TEXCOORD0;
half4 color : COLOR;
};
float3 mod289(float3 x)
{
return x - floor(x / 289.0) * 289.0;
}
float2 mod289(float2 x)
{
return x - floor(x / 289.0) * 289.0;
}
float3 permute(float3 x)
{
return mod289((x * 34.0 + 1.0) * x);
}
float3 taylorInvSqrt(float3 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
float snoise(float2 v)
{
const float4 C = float4( 0.211324865405187,
0.366025403784439,
-0.577350269189626,
0.024390243902439);
float2 i = floor(v + dot(v, C.yy));
float2 x0 = v - i + dot(i, C.xx);
float2 i1;
i1.x = step(x0.y, x0.x);
i1.y = 1.0 - i1.x;
float2 x1 = x0 + C.xx - i1;
float2 x2 = x0 + C.zz;
i = mod289(i);
float3 p =
permute(permute(i.y + float3(0.0, i1.y, 1.0))
+ i.x + float3(0.0, i1.x, 1.0));
float3 m = max(0.5 - float3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0);
m = m * m;
m = m * m;
float3 x = 2.0 * frac(p * C.www) - 1.0;
float3 h = abs(x) - 0.5;
float3 ox = floor(x + 0.5);
float3 a0 = x - ox;
m *= taylorInvSqrt(a0 * a0 + h * h);
float3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.y = a0.y * x1.x + h.y * x1.y;
g.z = a0.z * x2.x + h.z * x2.y;
return 130.0 * dot(m, g);
}
float3 snoise_grad(float2 v)
{
const float4 C = float4( 0.211324865405187,
0.366025403784439,
-0.577350269189626,
0.024390243902439);
float2 i = floor(v + dot(v, C.yy));
float2 x0 = v - i + dot(i, C.xx);
float2 i1;
i1.x = step(x0.y, x0.x);
i1.y = 1.0 - i1.x;
float2 x1 = x0 + C.xx - i1;
float2 x2 = x0 + C.zz;
i = mod289(i);
float3 p =
permute(permute(i.y + float3(0.0, i1.y, 1.0))
+ i.x + float3(0.0, i1.x, 1.0));
float3 m = max(0.5 - float3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0);
float3 m2 = m * m;
float3 m3 = m2 * m;
float3 m4 = m2 * m2;
float3 x = 2.0 * frac(p * C.www) - 1.0;
float3 h = abs(x) - 0.5;
float3 ox = floor(x + 0.5);
float3 a0 = x - ox;
float3 norm = taylorInvSqrt(a0 * a0 + h * h);
float2 g0 = float2(a0.x, h.x) * norm.x;
float2 g1 = float2(a0.y, h.y) * norm.y;
float2 g2 = float2(a0.z, h.z) * norm.z;
float2 grad =
-6.0 * m3.x * x0 * dot(x0, g0) + m4.x * g0 +
-6.0 * m3.y * x1 * dot(x1, g1) + m4.y * g1 +
-6.0 * m3.z * x2 * dot(x2, g2) + m4.z * g2;
float3 px = float3(dot(x0, g0), dot(x1, g1), dot(x2, g2));
return 130.0 * float3(grad, dot(m4, px));
}
uint Hash(uint s)
{
s ^= 2747636419u;
s *= 2654435769u;
s ^= s >> 16;
s *= 2654435769u;
s ^= s >> 16;
s *= 2654435769u;
return s;
}
float Random(uint seed)
{
return float(Hash(seed)) / 4294967295.0;
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = v.texcoord;
o.color = v.color;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float seed = i.texcoord.z;
float time = i.texcoord.w;
float tp = 1 - time;
float radius = 1 - tp * tp * tp * tp;
float2 uv = i.texcoord.xy - 0.5;
float freq = lerp(1.2, 2.7, Random(seed * 48923.23));
float n1 = snoise(atan2(uv.x, uv.y) * freq + seed * 764.2174);
float n1p = n1 * n1;
n1p = n1p * n1p * n1p;
float n2 = snoise(uv * 8 / radius + seed * 1481.28943);
float p = radius * (0.23 + radius * radius * (n1p * 0.9 + n2 * 0.07));
float l = length(uv);
float a = smoothstep(l - 0.01, l, p);
return half4(i.color.rgb, i.color.a * a);
}
ENDCG
}
}
}
|