Skip to content

Instantly share code, notes, and snippets.

@kawashirov
Last active July 11, 2018 21:34
Show Gist options
  • Save kawashirov/9f08471a7d34bbdb8520e663b25b0a81 to your computer and use it in GitHub Desktop.
Save kawashirov/9f08471a7d34bbdb8520e663b25b0a81 to your computer and use it in GitHub Desktop.
FPS shader
Shader "Kawashirov/FPS"
{
Properties { _DigitsTex ("Digits", 2D) = "white" {} }
SubShader {
Tags { "RenderType" = "Opaque" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; };
sampler2D _DigitsTex;
v2f vert (float4 vertex : POSITION, float2 uv : TEXCOORD0) { v2f o; o.vertex = UnityObjectToClipPos(vertex); o.uv = uv; return o; }
fixed4 frag (v2f i) : SV_Target {
uint fps = round(unity_DeltaTime.w);
half4 tex = tex2D(_DigitsTex, half2(frac(i.uv.x * 2) / 10 + half((i.uv.x > 0.5 ? fps : (fps / 10)) % 10) / 10, i.uv.y));
half4 grad = lerp(half4(1,0,0,1), half4(0,1,0,1), unity_DeltaTime.w / 91.0h);
return tex * grad;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment