Skip to content

Instantly share code, notes, and snippets.

@tayl0r
Created March 6, 2014 02:26
Show Gist options
  • Save tayl0r/9381064 to your computer and use it in GitHub Desktop.
Save tayl0r/9381064 to your computer and use it in GitHub Desktop.
unity3d shader based progress bar
Shader "Custom/ProgressBar"
{
Properties
{
_MaskTex ("Mask Tex", 2D) = "white" {}
_BarTex ("Bar Tex", 2D) = "white" {}
_Progress ("Progress", range(0, 1)) = .5
_C1 ("C1", Color) = (1, 1, 1, 0)
//_C2 ("C2", Color) = (0, 0, 0, 1)
_ScrollU ("Scroll Speed U", float) = 0
}
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off
Lighting Off
Cull Off
Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
LOD 110
CGPROGRAM
#pragma surface surf Unlit alpha noambient noforwardadd novertexlights nolightmap nodirlightmap
//#pragma vertex vert_vct
//#pragma fragment frag_mult
//#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "../Shaders/Unlit.cginc"
uniform sampler2D _MaskTex;
uniform sampler2D _BarTex;
uniform float _Progress;
uniform fixed4 _C1;
//uniform fixed4 _C2;
uniform float _ScrollU;
struct Input {
float2 uv_MaskTex;
float2 uv_BarTex;
};
void surf(Input IN, inout SurfaceOutput o) {
float2 uv = IN.uv_MaskTex;
float timeMod = _SinTime.r / 20;
float yMod = sin(_Time.b + uv.y * 3) / 80;
float p = floor(1 - uv.x + _Progress + timeMod + yMod);
IN.uv_BarTex.x += frac(_Time.r * _ScrollU);
fixed4 _C2 = tex2D(_BarTex, IN.uv_BarTex);
fixed4 final = lerp(_C1, _C2, p);
o.Albedo = final.rgb;
o.Alpha = final.a * tex2D(_MaskTex, uv).a;
}
ENDCG
}
FallBack "Diffuse"
}
fixed4 LightingUnlit(SurfaceOutput s, fixed3 lightDir, fixed atten) {
fixed4 c;
c.rgb = s.Albedo;
c.a = s.Alpha;
return c;
}
@tayl0r
Copy link
Author

tayl0r commented Mar 6, 2014

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