I am very much new to custom shaders. My actual problem is that I want to fade a mesh in and out via C# in Unity. However, the materials on the mesh I am using are opaque and setting them to transparent was causing me headaches with how the mesh appears (parts of the mesh were showing through the front / facing the camera in weird ways).
So I turned to shaders and I looked up a very basic shader implementation. Once this shader is applied to the material, I'm able to set the alpha channel quite easily while maintaining the general look of the mesh.
However, just changing from the Standard shader to this basic one, causes the mesh to look different. I thought it was lighting related, but I have tried to search for more information and I'm coming up short. I also wondered whether it was the Blend part of it below but I have tried a few combinations and none seem to work.
Here's the shader I'm using ... I believe this is just the most basic they can be:
Shader "Custom/TransparentShader"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Texture", 2D) = "white" {}
}
SubShader
{
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(appdata v) {
v2f o;
o.position = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_TARGET{
fixed4 col = tex2D(_MainTex, i.uv);
col *= _Color;
return col;
}
ENDCG
}
}
}
Is there an obvious (noobie) reason the mesh looks so different with this basic shader?