Skip to content

Instantly share code, notes, and snippets.

@thelucre
Created July 25, 2018 20:18
Show Gist options
  • Save thelucre/03a8fb33895b18379eb2d4a69d8d5800 to your computer and use it in GitHub Desktop.
Save thelucre/03a8fb33895b18379eb2d4a69d8d5800 to your computer and use it in GitHub Desktop.
Unity: Vertex Color Shader with Flat Color option
// Renders vertex colors on a mesh.
// Flat Shaded flag will ignore light. Useful for static Quill models
Shader "Custom/VertexColor" {
Properties {
[Toggle(FLAT_SHADED)]
_FlatShaded ("Flat Shaded", Float) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Lighting Off
CGPROGRAM
#pragma surface surf Lambert vertex:vert
#pragma target 4.0
#pragma shader_feature FLAT_SHADED
struct Input {
float4 vertColor;
};
void vert(inout appdata_full v, out Input o){
UNITY_INITIALIZE_OUTPUT(Input, o);
o.vertColor = v.color;
}
void surf (Input IN, inout SurfaceOutput o) {
#ifdef FLAT_SHADED
o.Emission = IN.vertColor.rgb;
#else
o.Albedo = IN.vertColor.rgb;
#endif
o.Alpha = IN.vertColor.a;
}
ENDCG
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment