Skip to content

Instantly share code, notes, and snippets.

@jhorikawa
Created January 15, 2018 18:39
Show Gist options
  • Save jhorikawa/7a236ae0b801bf2aca2d8a3038b9bf40 to your computer and use it in GitHub Desktop.
Save jhorikawa/7a236ae0b801bf2aca2d8a3038b9bf40 to your computer and use it in GitHub Desktop.
Unity Shader to visualize vertex color.
Shader "Custom/VertexColor" {
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
#pragma target 3.0
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) {
o.Albedo = IN.vertColor.rgb;
}
ENDCG
}
FallBack "Diffuse"
}
@manuelrossner
Copy link

@jhorikawa Still works great for Unity 2019.2.
Do you have an idea how to use it with the Lightweight-Renderpipeline?

@Hamu72
Copy link

Hamu72 commented Jun 9, 2020

hi jhorikawa

Thank you for sharing this shader code! I'm not a programmer just a gfx guy :)

I made a test. I changed your code in line 20:
o.Emissive = IN.vertColor.rgb;
because I want only vertex color lit on the scene without any lamp. (vertex color with ambient support)

But I have a "small" problem in Unity.
image
Left is the original mesh in Maya without lighting/shading - vertex color as "emissive"
The mesh's edges are smooth (each vertex has 1 vertex normal).

When I importing the mesh with vertex color and give this shader to them the colors

  1. changed to yellow (no lights in the scene)
  2. looks like there is some kind of shading and looks like the vertex normals changed

I don't know how can I fix this.
Do you have any idea?

@Hamu72
Copy link

Hamu72 commented Jun 9, 2020

Ok!

I solved the bug. I tweaked Maya baking and fixed the bug!
Your shader working well!!!
image
(The gamma is different)

@fakhirali
Copy link

Lifesaver🙌🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment