Advertisement
Guest User

Progressbar.shader

a guest
Jul 28th, 2022
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2. // very simple edit to turn into progressbar by @Minionsart
  3. Shader "UI/ProgressBar"
  4. {
  5.     Properties
  6.     {
  7.         _MainTex ("Main Texture", 2D) = "white" {}
  8.         _ColorMap ("Color Map", 2D) = "white" {}  
  9.         _FillSlider("Fill Slider", Range(0,1)) = 1.0
  10.         _Edge("Edge", Range(0,1)) = 1.0
  11.         _Color ("Edge Tint", Color) = (1,1,1,1)
  12.  
  13.         _StencilComp ("Stencil Comparison", Float) = 8
  14.         _Stencil ("Stencil ID", Float) = 0
  15.         _StencilOp ("Stencil Operation", Float) = 0
  16.         _StencilWriteMask ("Stencil Write Mask", Float) = 255
  17.         _StencilReadMask ("Stencil Read Mask", Float) = 255
  18.  
  19.         _ColorMask ("Color Mask", Float) = 15
  20.  
  21.         [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  22.     }
  23.  
  24.     SubShader
  25.     {
  26.         Tags
  27.         {
  28.             "Queue"="Transparent"
  29.             "IgnoreProjector"="True"
  30.             "RenderType"="Transparent"
  31.             "PreviewType"="Plane"
  32.             "CanUseSpriteAtlas"="True"
  33.         }
  34.  
  35.         Stencil
  36.         {
  37.             Ref [_Stencil]
  38.             Comp [_StencilComp]
  39.             Pass [_StencilOp]
  40.             ReadMask [_StencilReadMask]
  41.             WriteMask [_StencilWriteMask]
  42.         }
  43.  
  44.         Cull Off
  45.         Lighting Off
  46.         ZWrite Off
  47.         ZTest [unity_GUIZTestMode]
  48.         Blend SrcAlpha OneMinusSrcAlpha
  49.         ColorMask [_ColorMask]
  50.  
  51.         Pass
  52.         {
  53.             Name "Default"
  54.             CGPROGRAM
  55.             #pragma vertex vert
  56.             #pragma fragment frag
  57.             #pragma target 2.0
  58.  
  59.             #include "UnityCG.cginc"
  60.             #include "UnityUI.cginc"
  61.  
  62.             #pragma multi_compile_local _ UNITY_UI_CLIP_RECT
  63.             #pragma multi_compile_local _ UNITY_UI_ALPHACLIP
  64.  
  65.             struct appdata_t
  66.             {
  67.                 float4 vertex   : POSITION;
  68.                 float4 color    : COLOR;
  69.                 float2 texcoord : TEXCOORD0;
  70.                 UNITY_VERTEX_INPUT_INSTANCE_ID
  71.             };
  72.  
  73.             struct v2f
  74.             {
  75.                 float4 vertex   : SV_POSITION;
  76.                 fixed4 color    : COLOR;
  77.                 float2 texcoord  : TEXCOORD0;
  78.                 float2 texcoord2  : TEXCOORD2;
  79.                 float4 worldPosition : TEXCOORD1;
  80.                 UNITY_VERTEX_OUTPUT_STEREO
  81.             };
  82.  
  83.             sampler2D _MainTex, _ColorMap;
  84.             fixed4 _Color;
  85.             fixed4 _TextureSampleAdd;
  86.             float4 _ClipRect;
  87.             float4 _MainTex_ST;
  88.             float _FillSlider;
  89.             float _Edge;
  90.  
  91.             v2f vert(appdata_t v)
  92.             {
  93.                 v2f OUT;
  94.                 UNITY_SETUP_INSTANCE_ID(v);
  95.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  96.                 OUT.worldPosition = v.vertex;
  97.                 OUT.vertex = UnityObjectToClipPos(v.vertex);
  98.  
  99.                 OUT.texcoord = v.texcoord;
  100.                 OUT.texcoord2 = TRANSFORM_TEX(v.texcoord, _MainTex);
  101.                 OUT.color = v.color ;//* _Color;
  102.                 return OUT;
  103.             }
  104.  
  105.             fixed4 frag(v2f IN) : SV_Target
  106.             {
  107.                 // grab the main color as a base (could be a noise texture for fun results)
  108.                 half4 color = (tex2D(_MainTex, IN.texcoord2) + _TextureSampleAdd) * IN.color;
  109.                 // use the main texture to colorize the whole thing
  110.                 half4 colorMap = tex2D(_ColorMap, color);
  111.                 #ifdef UNITY_UI_CLIP_RECT
  112.                     colorMap.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  113.                 #endif
  114.                 // comment out the sin version and just us the _FillSlider for manual control
  115.                 //float fillAmount = _FillSlider;
  116.                 float fillAmount = sin(_Time.y * _FillSlider);
  117.                 // base bar
  118.                 float cutoffpoint =step( IN.texcoord.y , fillAmount- _Edge);
  119.                 colorMap *= cutoffpoint;
  120.                 // create an edge at the end
  121.                 float endbit = step( IN.texcoord.y , fillAmount ) - cutoffpoint;
  122.                 colorMap.a += endbit;
  123.                 // clipping
  124.                 #ifdef UNITY_UI_ALPHACLIP
  125.                     clip (colorMap.a - 0.001);
  126.                 #endif
  127.                 // add colored edge
  128.                 colorMap.rgb += saturate(endbit) * _Color;
  129.                
  130.  
  131.                 return colorMap;
  132.             }
  133.             ENDCG
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement