Skip to content

Instantly share code, notes, and snippets.

@lowteq
Created March 5, 2020 04:29
Show Gist options
  • Save lowteq/52c4d8031208b1f4835a7c4c30ae19dd to your computer and use it in GitHub Desktop.
Save lowteq/52c4d8031208b1f4835a7c4c30ae19dd to your computer and use it in GitHub Desktop.
文字をランダムに表示するシェーダー
Shader "Unlit/charshader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
float random (fixed2 p)
{
return frac(sin(floor(_Time.z)*dot(p, fixed2(12.9898,78.233))) * 43758.5453);
}
float noise(fixed2 st)
{
fixed2 p = floor(st);
return random(p);
}
fixed4 frag (v2f i) : SV_Target
{
int s = 10; //1列の表示文字数
int w = 3;//文字ソースの1列の文字数
float c = noise( i.uv*s + 1);
//return fixed4(c,c,c,1);
float x = frac(floor(c*w*w)/w);
float y = floor(c*w)/w;
float dx = frac(i.uv.x*s)/w;
float dy = frac(i.uv.y*s)/w;
fixed4 col = tex2D(_MainTex,float2(x+dx,y+dy));
return col;
}
ENDCG
}
}
}
@lowteq
Copy link
Author

lowteq commented Mar 5, 2020

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment