|
Hi! I want to make a progress bar. The way i choose to control the bar is by shader cutoff value. You can find that solution somewhere in here for the circular progress bar. I also would want to have nice blending going on in that shader, so I have found a solution: (Sorry, I cant find the link to this). Its a shader that does what i want. Main texture is the progress bar, cutTex is the gradient alpha ramp. Problem is that this shader is a surface shader, and i want my texture to be unlit. So i tried to convert this shader to shaderlab, but cant get it to work. Any ideas? And is this solution better that say, making 3 textures(left end, right end, middle) and re sizing the middle(with re sizing mainTexture of the middle part texture)? Its for pc. Anyway i came up with this in shaderlab: Which texture should get the alpha test? Both of them? And how can I make the alpha test on the main texture? Can i do it in one pass? I know its not much, but Im not so fluent in writing shaders in shaderlab. Or any other shaders really :)
(comments are locked)
|
Shader "Custom/cutoutalpha"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_CutTex ("Cutout (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
ZWrite Off
Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
sampler2D _CutTex;
fixed4 _Color;
float _Cutoff;
struct appdata
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 frag(v2f i) : COLOR
{
fixed4 c = _Color * tex2D(_MainTex, i.uv);
fixed ca = tex2D(_CutTex, i.uv).a;
c.a *= ca > _Cutoff ? 1f : 0f;
return c;
}
ENDCG
}
}
Fallback "Transparent/VertexLit"
}
(comments are locked)
|

Both shaders are using shaderlab. If the first one does what you want, why not use that and disable lighting if that's all you need?
Ok, how to disable the lighting then? CGPROGRAM uses presets in calculating lighting. And people on the forums say that if you are not using light, then don't use surface shaders. And i didn't know that both of them are in shaderLab. I meant that one is in shaderlab(simple) and the other (surface) is with CGPROGRAM with light calculation presets(Lambert). Isn't the simple one faster than using surface shader?
Bascially everything outside the CGPROGRAM block is part of shaderlab. I'm no shader pro, but can't you simply throw a 'Lighting Off' above the CGPROGRAM block in the original shader (inside the subshader)?
I though about that:) It seems it cannot be done. Even so, its still doing the lambert calculations in CGPROGRAM.
Hmm, suck. Don't think I can help. Shaders aren't my strong point (have 'The CG Tutorial' book on the way atm so hoping to change that soon!). Best of luck.