Skip to content

Instantly share code, notes, and snippets.

@MichaelZhou
Last active June 18, 2019 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelZhou/c3056f5efed0129171fc4e84770062e7 to your computer and use it in GitHub Desktop.
Save MichaelZhou/c3056f5efed0129171fc4e84770062e7 to your computer and use it in GitHub Desktop.
Shader that allows 3D meshes that support vertex colors (.fbx, .ply) to be colored by their vertices
Shader "Custom/VertexColor" { // Where it will appear inside of the Shader Dropdown Menu of the Material / Name of the shader
Properties{
_Toggle ("Toggle context", int) = 1
}
SubShader{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
#pragma target 3.0
#include "UnityCG.cginc"
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) {
#include "UnityCG.cginc"
o.Albedo = IN.vertColor.rgb;
clip(Toggle * (0.5f - IN.vertColor.b));
}
ENDCG
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment