Standard shader with vertex colors

Hello, everyone!
I needed to use vertex colors in materials for my current project, with flexibility of Unity 5 standard shader.
So here it is in action: Standard shader modified to support vertex colors of your models.
Latest version (0.91) with additive pass (multiple lights supported)
Version for Unity 5.4.0 (0.92) with vertex alpha in shadows support

vertex color intensity support

vertex alpha in shadows support

25 Likes

This is exactly what I was looking for! Thank you

You are welcome to use it any way you want

Awesome! Thanks again.

Thank you very much !

Hi everyone!
Here is an updated version with vertex color intensity and vertex color automatic disabling (just standard shader style)


2057399–133895–UnityVC.unitypackage (55.1 KB)

2 Likes

This is exactly what I was just looking for to work with sprites. Thanks so much!

Any ideas on adding per vertex fading like the fade rendering mode but controlled by the vertex alpha? I can’t figure out where in the shader the SurfaceOutput alpha is being set.

It’s not a surface shader, thats why it has no SurfaceOutput. I’ve modified shader to support transparency, but I need to figure out proper shadow rendering for transparent areas. And for some reason vertex alpha is not working with Cutout rendering mode.

2067709–134882–UnityVC.rar (3.92 KB)

1 Like

So, I’m pretty new to custom shaders and very new to vertex colors. I’m wondering if someone can explain what I may be doing wrong here? I’m modelling in 3DS Max and exporting an FBX with a Vertex Color Map to use in Unity 5.
When I import the model into Unity and apply the vertex color shader, the colors are all smeared instead of clean. Any ideas as to why this is happening?

In Max you need to detach faces with different colors to separate elements (Note: elements not objects).

1 Like

Thanks for this. I’ll play around with it and see if I can figure out the shadows issue.

Thanks for this shader, it’s working great for me in the Unity player. The transparency doesn’t seem to be working on Android. Can you think of any reason why?

Oh man thank you so much for helping me figure this out!

I’m not sure and I don’t have decent device to test it right now.

About this question: Combine Lights and Clamp intesity.

I thought of using a vertex color shader to create ambient light on the object, and change color, clamp intensity through its vertex color.

Would it be possible with this shader? I tried the following code does not work:

using UnityEngine;
using System.Collections;

public class VertexColor : MonoBehaviour {

    public Color color;

    void Start () {

        Mesh mesh = Instantiate<Mesh>(GetComponent<MeshFilter>().sharedMesh);
        for(int i=0;i<mesh.colors.Length;i++) mesh.colors[i] = color;
        GetComponent<MeshFilter>().sharedMesh = mesh;
   
    }

}

Another question, other usage could be creating fog of war, but would need to be transparent shader. This would be possible?

Thanks.

Use vertex color modification like that:

void Start(){
        Mesh mesh = Instantiate<Mesh>(GetComponent<MeshFilter>().sharedMesh);
        Color[] colors = mesh.colors;
        for (int i = 0; i < colors.Length; i++)
            colors[i] = color;
        mesh.colors = colors;
        GetComponent<MeshFilter>().sharedMesh = mesh;
    }

Yes it can be transparent

No I get it to work on my computer.

Does not change the color.

Only change the intensity, if Vertex Color factor is modified in the material.

Adding this test project, if the problem is not the script (I have installed Unity 5.0.1f1 Personal Edition, the graphics card is something old, Nvidia GeForce 9500GS)

2086894–136446–TestVC.unitypackage (24.9 KB)

That’s because unity primitives don’t have vertex colors by default (uninitialized arrays) so you first need to create it.
Note that if you use imported model with vertex colors this script will overwrite those colors.

2088346–136567–VertexColor.cs (446 Bytes)

Yes, that was the problem.