Hey guys
I’m trying to make use of the ability to set vertex colors on a Mesh. I have all of the logic figured out, but unfortunately it seems the only way to actually see the fruits of my labor is to use a vertex shader.
Are there any stock Unity shaders that should work for me here?
I’ve tried to save the following shaders in my project but for some reason I get a syntax error on line 3 in both:
http://wiki.unity3d.com/index.php?title=VertexColor
http://wiki.unity3d.com/index.php/AlphaVertexColor
I’m currently using the stock Transparent/Diffuse shader, so I don’t want to lose my alpha map functionality.
I’m very new to playing with shaders in Unity, so I’m sure I’ve overlooked something simple.
Thanks,
Ves
The built-in particle shaders use vertex colours, because that is where per-particle colour is stored.
Tzan
March 27, 2014, 5:24pm
3
This is a shader I am using to do some boxy procedural terrain.
I dont use a color texture map, just vert color and a detail texture on top.
The detail texture has an alpha channel I use to vary the Gloss.
The only way I figured out how to do this was from some code another guy posted here.
So good luck.
Shader "DAB/Vertex Detail Specular"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
//_MainTex ("Base (RGB)", 2D) = "white" {}
_Detail ("Detail (RGB) Gloss (A)", 2D) = "gray" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 300
CGPROGRAM
#pragma surface surf BlinnPhong vertex:vert
//#pragma surface surf BlinnPhong
//#pragma surface surf Lambert
//sampler2D _MainTex;
sampler2D _Detail;
float4 _Color;
float _Shininess;
struct Input
{
//float2 uv2_MainTex;
float2 uv_Detail;
float3 vertColors;
};
void vert(inout appdata_full v, out Input o)
{
o.vertColors= v.color.rgb; // grab vertex colors from appdata
o.uv_Detail = v.texcoord; // maybe need this
}
void surf (Input IN, inout SurfaceOutput o)
{
//half4 c = tex2D(_MainTex, IN.uv2_MainTex) * _Color;
half3 c = IN.vertColors.rgb * _Color.rgb; //half3 check to see that alpha works
c.rgb *= tex2D(_Detail,IN.uv_Detail).rgb*2;
o.Albedo = c.rgb;
o.Gloss = tex2D(_Detail,IN.uv_Detail).a;
//o.Alpha = c.a * _Color.a;
o.Specular = _Shininess;
//o.Normal = UnpackNormal(tex2D(_Detail, IN.uv_Detail));
}
ENDCG
}
Fallback "Specular"
}
This image got shrunk, so its hard to see the speckled detail texture, but those edge lines are on the detail too.
5 Likes