Skip to content

Instantly share code, notes, and snippets.

@ruccho
Created October 31, 2019 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruccho/a1ce9176efc613d967223932cc27e58c to your computer and use it in GitHub Desktop.
Save ruccho/a1ce9176efc613d967223932cc27e58c to your computer and use it in GitHub Desktop.
背景用シェーダー。Quadとかに貼ってつかってください。
Shader "Unlit/BG_DottedWave"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_UpperColor("Upper Color", Color) = (1.0,1.0,1.0,1.0)
_LowerColor("Lower Color", Color) = (1.0,1.0,1.0,1.0)
_SurfaceHeight("Surface Height", Float) = 0.5
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 pos : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _UpperColor;
fixed4 _LowerColor;
float _SurfaceHeight;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.pos = ComputeScreenPos(o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 resolution = _ScreenParams.xy;
float2 uv = i.pos.xy / i.pos.w;
fixed4 col = fixed4(0.0,0.0,0.0, 1.0);
//Dot
//Repeat
float2 rectUv = uv * resolution / resolution.x;
float2 gridLocal = frac(rectUv * 50);
float2 gridIndex = floor(rectUv * 50);
float2 gridRounded = (gridIndex / 50) * resolution.x / resolution;
// Wave
float d = sin(gridRounded.x * 3.14 * 6 + _Time.y * 2.0) * 0.1 + (_SurfaceHeight + sin(gridRounded.x * 3.14 * 2 - _Time.y * 3.0) * 0.05);
float d2_a = smoothstep(d, d + 0.2, gridRounded.y);
float d3_a = step(distance(float2(0.5, 0.5), gridLocal), 0.4 * d2_a);
float d2_b = smoothstep(gridRounded.y, gridRounded.y+0.2, d);
float d3_b = step(distance(float2(0.5, 0.5), gridLocal), 0.4 * d2_b);
col = _UpperColor * d3_a;
col += _LowerColor * d3_b;
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment