Created
August 16, 2018 10:50
-
-
Save Makizemi/fdc5aee15d4da8c9ab984e558762a3d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Unlit/UI_Gauge" | |
{ | |
Properties | |
{ | |
_ColorTex ("Color Texture", 2D) = "white" {} | |
_GaugeTex("GaugeTexture", 2D) = "white"{} | |
_Threshold("Threshold", Range(0, 1)) = 0 | |
_Offset("Offset", Float) = -0.05 | |
_FrameTex("FrameTexture", 2D) = "white"{} | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"Queue" = "Transparent" | |
"RenderType" = "Transparent" | |
} | |
LOD 100 | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
#include "MathFunctions.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _ColorTex; | |
float4 _ColorTex_ST; | |
sampler2D _GaugeTex; | |
half _Threshold; | |
float _Offset; | |
sampler2D _FrameTex; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _ColorTex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
fixed4 m = tex2D(_GaugeTex, i.uv); | |
//グレースケールに変換 | |
half gray = m.r * 0.2 + m.g * 0.7 + m.b * 0.1; | |
float threshold = Remap(_Threshold, float2(0, 1), float2(1, _Offset)); | |
float alpha = m.a * smoothstep(threshold, threshold - _Offset, gray); | |
fixed4 col = tex2D(_ColorTex, i.uv) * alpha; | |
fixed4 frameCol = tex2D(_FrameTex, i.uv); | |
return lerp(col, frameCol, frameCol.a); | |
} | |
ENDCG | |
} | |
} | |
FallBack "Transparent/Cutout/Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment