101 lines
3.2 KiB
Plaintext
101 lines
3.2 KiB
Plaintext
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
|
|
|
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
|
|
|
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
|
|
|
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
|
|
|
|
// Simplified Diffuse shader. Differences from regular Diffuse one:
|
|
// - no Main Color
|
|
// - fully supports only 1 directional light. Other lights can affect it, but it will be per-vertex/SH.
|
|
|
|
|
|
Shader "Carmen/SDF/Timer"
|
|
{
|
|
Properties
|
|
{
|
|
_Tint ("Tint", Color) = (1.0, 1.0, 1.0, 1.0)
|
|
|
|
_Crosshairs ("Crosshairs", 2D) = "white" {}
|
|
_CrosshairsThickness ("Thickness", Range(0.0, 1.0)) = 0.5
|
|
|
|
_WiperProgress ("Wiper Progress", Range(0.0, 1.0)) = 1.0
|
|
}
|
|
SubShader
|
|
{
|
|
Tags { "Queue"="Transparent" "RenderType"="Transparent" "CanUseSpriteAtlas"="True" "ForceNoShadowCasting"="True" }
|
|
LOD 200
|
|
|
|
Pass {
|
|
Cull Back
|
|
Lighting Off
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
|
|
CGPROGRAM
|
|
#include "UnityCG.cginc"
|
|
#pragma target 4.5
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
half4 _Tint;
|
|
|
|
UNITY_DECLARE_TEX2D(_Crosshairs);
|
|
half4 _Crosshairs_ST;
|
|
half _CrosshairsThickness;
|
|
half _WiperProgress;
|
|
|
|
struct Data
|
|
{
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct V2F
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
V2F vert(Data v)
|
|
{
|
|
V2F o;
|
|
|
|
o.position = UnityObjectToClipPos(v.vertex);
|
|
o.uv = TRANSFORM_TEX(v.uv, _Crosshairs);
|
|
|
|
return o;
|
|
}
|
|
|
|
fixed4 frag(V2F i) : SV_TARGET
|
|
{
|
|
half crosshairs_sample = UNITY_SAMPLE_TEX2D(_Crosshairs, i.uv).r;
|
|
half crosshairs_halfchange = (abs(ddx(crosshairs_sample)) + abs(ddy(crosshairs_sample))) / 2.0;
|
|
half crosshairs_loweredge = 0.5 - crosshairs_halfchange;
|
|
half crosshairs_upperedge = 0.5 + crosshairs_halfchange;
|
|
half crosshairs = saturate((crosshairs_sample - crosshairs_loweredge) / (crosshairs_upperedge - crosshairs_loweredge));
|
|
|
|
half wiper_circlemask_sample = distance(float2(0.5, 0.5), i.uv) * 1.9;
|
|
half wiper_circlemask_halfchange = (abs(ddx(wiper_circlemask_sample)) + abs(ddy(wiper_circlemask_sample))) / 2.0;
|
|
half wiper_circlemask_loweredge = 0.5 - wiper_circlemask_halfchange;
|
|
half wiper_circlemask_upperedge = 0.5 + wiper_circlemask_halfchange;
|
|
half wiper_circlemask = 1.0 - saturate((wiper_circlemask_sample - wiper_circlemask_loweredge) / (wiper_circlemask_upperedge - wiper_circlemask_loweredge));
|
|
|
|
half2 wiper_quadrantmask_sample = ceil((i.uv) - half2(0.5, 0.5));
|
|
half wiper_quadrantmask = saturate(1.0 - ceil(wiper_quadrantmask_sample.g - (wiper_quadrantmask_sample.r + wiper_quadrantmask_sample.g / 2.0)));
|
|
|
|
half2 uvcentre = i.uv - 0.5;
|
|
half pixelsize = ((1.0 / _ScreenParams.x) + (1.0 / _ScreenParams.y)) / 2.0;
|
|
half wiper = smoothstep(_WiperProgress - pixelsize, _WiperProgress + pixelsize, ((atan2(uvcentre.y, uvcentre.x) / 3.141592) + 1.0) / 1.5075);
|
|
|
|
wiper = wiper * wiper_quadrantmask * wiper_circlemask;
|
|
|
|
return fixed4(_Tint.r, _Tint.g, _Tint.b, saturate(crosshairs + wiper) * _Tint.a);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
FallBack "Diffuse"
|
|
}
|
|
|