I’m a little bit desperate since I try to get this “simple” shader running without success since 2 days. I have no real clue about shaders and tutorials and books helped me to display “something” but not what I want. So I hope someone with more experience can give me a helping hand in debugging (and understanding) it.
I create a procedural mesh of quads. Those quads represent hexagonal tiles and overlay each other since I want to display different information with different coloured symbols. So for example in a single hexagon I want to draw a grey outline and a red center (controlled by different uv coordinates). The mesh is built properly and I want to control what is displayed simply by changing the vertexcolors (with transparency) of the mesh. So the outline vertices would recive a grey color and the center vertices a red color and when i want an empty hex i simply set alpha to zero in the color.
When I use shader Legacy/Transparent/Diffuse I get this result (mesh is ok!):
https://dl.dropboxusercontent.com/u/44944089/scr_diffuse.png
When I use my custom shader I get this:
https://dl.dropboxusercontent.com/u/44944089/scr_custom.png
So obviously something is messed up but since debugging shaders is actually not easy I want to ask if someone can see obvious mistakes when looking over my Shadercode:
Shader "Custom/HexShader"
{
Properties
{
_MainTex ("HexTexture", 2D) = "white" {}
_TransVal ("Transparency Value", Range(0,1)) = 0.5
}
SubShader
{
Tags
{
"Queue" = "Transparent"
}
ZWrite Off // don't write to depth buffer in order not to occlude other objects
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
float _TransVal;
struct vertInput
{
float4 vertPos : POSITION;
float4 vertColor : COLOR0;
float2 uv_MainTex : TEXCOORD0;
};
struct vertOutput
{
float4 scrPos: SV_POSITION;
float4 pixColor : COLOR0;
float2 uv_MainTex : TEXCOORD0;
};
vertOutput vert(vertInput IN)
{
vertOutput OUT;
OUT.pixColor = IN.vertColor;
OUT.uv_MainTex = IN.uv_MainTex;
OUT.scrPos = mul(UNITY_MATRIX_MVP, IN.vertPos);
return OUT;
}
half4 frag(vertOutput IN) : COLOR
{
half4 color = tex2D(_MainTex, IN.uv_MainTex);
color.a = color.a * _TransVal * IN.pixColor.a;
color.rgb = color.rgb * IN.pixColor.rgb;
return color.rgba;
}
ENDCG
}
}
}
Note: the _TransVal property shall actually set the transparency. In the textures the outline and center are (partially) opaque and with this float i want to reduce it to my liking. Its set to 1 here for comparison.
Questions:
This shader should target shader model 2.0 for maximum compatibility (option of targeting mobile later). Is this sufficient?
Can I use a built in shader instead for what I want to achieve? Have tried some but mentioned diffuse seems to ignore my color changes.
What is wrong with my shader? There are overlapping effects and outline is “ignored” completely.
Should I use a surface shader instead of a fragment shader? The mesh shall not be influenced by lighting.
Thanks for your time.