Created
July 25, 2018 20:18
-
-
Save thelucre/03a8fb33895b18379eb2d4a69d8d5800 to your computer and use it in GitHub Desktop.
Unity: Vertex Color Shader with Flat Color option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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