Note that I am a total newbie in shader programmin, so I’ve been trying to study it.
My intention on this script was to do, at least for now, a Shader that Accepts Tint Color and accepts an Albedo, for each 0 alpha areas on the Albedo, these would cut out from the rendering, this was supposed to be used on a character’s cloathes. There goes the code:
Shader "Custom/PBR Shader"
{
Properties
{
_TintColor ("Colour Tint", color) = (1,1,1,1)
_MainTex ("Albedo", 2D) = "white" {}
_CutOff ("CutOff", Range(0,1)) = 0.5
}
SubShader
{
Tags {"Queue" = "Transparent" "RenderType" = "Opaque"}
cull off
CGPROGRAM
#pragma surface surf Lambert finalcolor:mycolor alpha
struct Input
{
float2 uv_MainTex;
};
fixed4 _TintColor;
void mycolor (Input IN, SurfaceOutput o,inout fixed4 color)
{
color *= _TintColor;
}
sampler2D _MainTex;
float _CutOff;
void surf (Input IN, inout SurfaceOutput o)
{
float ca = tex2D(_MainTex, IN.uv_MainTex).a;
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
if (ca > _CutOff)
o.Alpha = ca;
else
o.Alpha = 0;
}
ENDCG
}
FallBack "Transparent/Diffuse"
}
Shader "Custom/PBR Shader"
{
Properties
{
_TintColor ("Colour Tint", color) = (1,1,1,1)
_MainTex ("Albedo", 2D) = "white" {}
_CutOff ("CutOff", Range(0,1)) = 0.5
}
SubShader
{
Tags {"Queue" = "Transparent" "RenderType" = "Opaque"}
cull off
CGPROGRAM
#pragma surface surf Lambert finalcolor:mycolor alpha
struct Input
{
float2 uv_MainTex;
};
fixed4 _TintColor;
void mycolor (Input IN, SurfaceOutput o,inout fixed4 color)
{
color *= _TintColor;
}
sampler2D _MainTex;
float _CutOff;
void surf (Input IN, inout SurfaceOutput o)
{
float ca = tex2D(_MainTex, IN.uv_MainTex).a;
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
if (ca > _CutOff)
o.Alpha = ca;
else
o.Alpha = 0;
}
ENDCG
}
FallBack "Transparent/Diffuse"
}
But the problem is, even fully alpha areas (And I checked the texture plane and those are indeed with no transparency at all) seems a little transparent. And I can’t figure out why. Does anyone know how to help me please? And If you have any optimization or performance advices on the code, please feel free to sugest.
Thanks;
Arthur