Hello fellow unity developers.
I’ve already ask this question in the “Answers” section, but I haven’t got any solution.
My question is simple : how to make a custom shader displaying some transparency on a mesh renderer ?
I’m a programmer but not a shader artist and I’m really struggling with this simple task.
The following shader is used on a quad (with a mesh filter and a mesh renderer).
By varying the DisplayValue between 0.0 and 1.0, it should display a green gauge on transparent background.
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
}
}
}
But it display a green gauge on a black background, as if the return value in the else statement was half4(0,0,0,1) instread of half4(0,0,0,0).
Any idea about why it doesn’t work has I wish it to ? What I’m doing wrong ?
PS : Please forgive my mistakes, english is not my native language.