Hello unity fellow developers.
Here is my question : how to make a custom shader displaying some transparency on a mesh renderer ?
I have to do this in a complex shader, but the point is I don’t even succeed doing the basic step of rendering transparent pixels.
Let’s try to do a very simple shader so we will be able to find out what I’m doing wrong :
**Shader "Custom/Gauge" {
Properties {
DisplayValue ("Value", Float) = 0
}
SubShader {
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Pass {
CGPROGRAM
#pragma target 3.0
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform float DisplayValue;
float4 frag(v2f_img input) : COLOR {
if (input.uv.x < DisplayValue)
{
return half4(0.0, 1.0, 0.0, 1.0);
}
else
{
return half4(0.0, 0.0, 0.0, 0.0);
}
}
ENDCG
}
}
}**
This is supposed to diplay green until uv.x reach the “display value” (it could be used as a gauge or a loading bar for exemple), but the mesh (a quad) is part green and part black depending the value used, it should be part green and part transparent.
Any idea about why it doesn’t work has I wish it to ?
PS : Forgive my mistakes, english is not my native language.
Thanks but that's not the problem. DisplayValue works fine. I've just say something wrong about the shader behavior, my bad : the mesh isn't full green with these color values, of course ; it is part green and part black, depending on the DisplayValue, it should be part transparent instead of part black. I don't see any more data to add to the question, there is no more data : a quad, a material, a shader and that's all. DisplayValue range is of course [0,1], and I set it in the inspector to check the shader. EDIT : I've edited the question to correct it.
– eMeldonian