一旦完成ハートver追加
Shader "Test"
{
Properties
{
_MainTex("MainTex", 2D) = "white"{}
_Value("Value", Range(0, 20)) = 20
_PatternCount("Count", Float) = 10
_StartPos("StartPos", Vector) = (1, 0,0,0)
}
CGINCLUDE
#include "UnityCG.cginc"
float _Value;
float _PatternCount;
fixed2 _StartPos;
sampler2D _MainTex;
float star(float2 st, float size)
{
st -= 0.5;
st /= size;
float a = atan2(st.y, st.x);// + _Time.y * 0.3;
float l = pow(length(st), 0.8);
float d = l - 0.5 + cos(a * 5.0) * 0.08;
return 1 - smoothstep(0, 0.1, d);
}
float box(float2 st, float size)
{
// 中心揃えにする四角形描画
size = 0.5 + size * 0.5;
st = step(st, size) * step(1 - st, size);
return st.x * st.y;
}
float wave(float2 uv, float2 n, float2 startPos)
{
// 0.5なら中心が原点
// 右下を原点とする
float2 offset = startPos;//float2(1, 0); or (-1, 0)
float speed = 3;
float waveNum = 3;
// nで除算して正規化している
float2 st = (floor(uv * n) + offset) / n;
float d = distance(offset, st);
// (1+ ~~~)*0.5は-1 ~ 1 => 0 ~ 1に正規化する処理
return d * _Value*0.5;
return (1 + sin(d * _Value)) * 0.5;
}
fixed4 frag(v2f_img i) : SV_Target
{
float offset = 0.5;
float2 puv = i.uv;
puv.x -= offset;
puv.x *= _ScreenParams.x / _ScreenParams.y;
puv.x += offset;
float n = _PatternCount;
float2 st = frac(puv * n);
float size = wave(puv, n, _StartPos);
float col = star(st, size);
clip(col-0.5);
fixed4 diffuse = tex2D(_MainTex, i.uv);
return col * diffuse + (1 - _Value / 20) * 0.2;
}
ENDCG
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
ENDCG
}
}
}