- Home /
Circular Bar - problem with shader
Hi, I using AlphaCutoff shader to make my life bar circular. Its working half good - the texture disappears but it leaving black solid color behind it. How can I change to draw _BackText instead of just solid black?
Shader:
Shader "Custom/LifeBar" {
Properties {
_MainTex ("Base (RGB) Transparency (A)", 2D) = "" {}
_BackTex ("Texture", 2D) = "black" {}
_Cutoff ("Alpha cutoff", Range (0, 1)) = 0.5
}
SubShader {
Tags {"RenderType" = "Transparent" "Queue" = "Transparent" "IgnoreProjector" = "True"}
Pass{
AlphaTest Greater [_Cutoff]
Material {
Diffuse (1,1,1,1)
Ambient (1,1,1,1)
}
Lighting On
SetTexture [_MainTex] { combine texture * primary }
}
}
}
Script to draw bar:
if (Event.current.type.Equals(EventType.Repaint))
{
mat.SetFloat("_Cutoff", lifePerc);
Graphics.DrawTexture(new Rect((Screen.width - Screen.width / 6) - 5, (Screen.height - Screen.width / 6) - 5, Screen.width / 6, Screen.width / 6), gradient, mat);
}
Answer by Jona-Marklund · Aug 27, 2013 at 09:11 PM
Provided that you're trying to have the _MainTex be positioned on top of the _BackTex, this should work for you!
Shader "JM/LifeBar" {
//Jona Marklund 27th of August 2013
Properties {
_MainTex ("Base (RGB) Transparency (A)", 2D) = "" {}
_BackTex ("Texture", 2D) = "black" {}
_Cutoff ("Alpha cutoff", Range (0, 1)) = 0.5
}
SubShader {
Tags {"RenderType" = "Transparent" "Queue" = "Transparent" "IgnoreProjector" = "True"}
Pass{
AlphaTest Greater [_Cutoff]
Material {
Diffuse (1,1,1,1)
Ambient (1,1,1,1)
}
Lighting On
SetTexture [_BackTex] { combine texture * primary }
SetTexture [_MainTex] { combine texture, previous + texture }
}
}
}
Best Regards Jona
Answer by $$anonymous$$ · Aug 17, 2013 at 11:14 PM
It hast to do with line 4, replace
_BackTex ("Texture", 2D) = "black" {}
with
_BackTex ("Texture", 2D) = "" {}
This doesn't do the trick ;/. Still leaving black ins$$anonymous$$d of texture.
Answer by whydoidoit · Aug 20, 2013 at 01:35 PM
Add this to your shader:
Blend SrcAlpha OneMinusSrcAlpha
Hi, its not leaving solid black now but i want it to draw BackTex ins$$anonymous$$d of black color, not the $$anonymous$$ainTex. Sorry for not answering for so long but i was on wacations :). If somebody know what to do please help me please.
BU$$anonymous$$P! - I really need this and i newbie at shaders :(
Your answer
![](https://koobas.hobune.stream/wayback/20220613112422im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unlit, Transparent and Slice Shader 2 Answers
(c#) Transparency Problem - Toggle not Gradient 1 Answer
Shader to apply Alpha to other images 0 Answers
render Alpha only on another Alpha 0 Answers
normal map, mask different areas? 0 Answers