GI: Vertex colors as diffuse.

There is any solution to get GI properly working with vertex colors as diffuse shader?

Enlighten GI is not taken into account the vertex colors when used as diffuse, the result is that all bonced light is pure white. Any solution about that? Using textures is the only way to get the color information for GI?

I am working on making this possible, by adding shader pass support for emissive and albedo input. This will likely be ready in beta 18 or 19.

3 Likes

Thank you for taking this into account KEngelstoft, this is very important for mobile platforms and some toon shading techniques.

Really, thank you.

Unity 5 beta 19 GI still dont take into account vertex colors. This feature will be included in future versions KEngelsoft?

This is the shader im using for tests:

Shader "Custom/Vcol" {
    Properties {
        _Spec ("Specular and Gloss", Color) = (128,128,128,0)
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
       
        CGPROGRAM
        #include "UnityPBSLighting.cginc"
        #pragma surface surf Standard
       
        fixed4 _Spec;

        struct Input {
            fixed4 color : COLOR;
        };

        void surf (Input IN, inout SurfaceOutputStandard o) {
            o.Albedo = IN.color.rgb;
            o.Specular = _Spec.rgb;
            o.Smoothness = _Spec.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Yes, the feature will be available in beta 20. A new ‘meta’ pass will be used to generate albedo and emissive to be used as input to Enlighten. You can make your own shader pass or use the standard shader one.

1 Like

Hi there KEngelstoft,

Finally vertex colors are working with the new “meta” pass. Thanks allot for your support. The problem now is that I cant get the same results with Surface Shaders as using “Standard” shader. There is some AO missing, take a look at the screenshots (meshes are marked as static):

Standrad shader:
1923537--124211--GI.jpg

Custom Surface Shader using vertex colors:
1923537--124212--GI_Vcol.jpg

And here the custom shader:

Shader "Custom/Vcol" {
    Properties {
        _Spec ("Specular and Gloss", Color) = (128,128,128,0)
    }
   
    CGINCLUDE
        #define _GLOSSYENV 1
        #define UNITY_SETUP_BRDF_INPUT SpecularSetup
    ENDCG
   
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
       
        CGPROGRAM
        #include "UnityPBSLighting.cginc"
        #pragma surface surf Standard fullforwardshadows
        //#define _GLOSSYENV 1
        #pragma target 3.0

        fixed4 _Spec;

        struct Input {
            fixed4 color : COLOR;
        };

        void surf (Input IN, inout SurfaceOutputStandard o) {
            o.Albedo = IN.color.rgb;
            o.Specular = _Spec.rgb;
            o.Smoothness = _Spec.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

What I have to include to get the same AO?

The meta pass shouldn’t affect AO; I think it is because your shader outputs a different albedo than the Standard shader. Try calculating your albedo like this UnityLightmappingAlbedo (IN.color.rgb, _Spec.rgb, oneMinusRoughness /you have to come up with some roughness value that makes sense for your material/);
You can see the generated albedo in the GI - albedo scene view mode.

As you say, its somthing that makes Standard shader, not GI.
I cant get the same result with the surface shader, but tested with the legacy shaders and its doing the same (no AO). So I will wait till the documentation, because for the moment nobody knows to solve it.
Tested what you say and included lightmaping properties [LM_Specular] and still not getting the AO.
But thanks KEngelstoft for the help.

@Project-Mysh why don’t you grab the standard shader code and modify it so that it uses vertex colors? That’s what I did and it works pretty well. This way you’ll get the exact same results as the standard shader :slight_smile:

I can post my shader if you want - it’s for beta 20.

I’d like to see that if you don’t mind. I tried to modify the standard shader to turn it into a dissolve shader but it never quite matches the look of the standard.

Here it goes.

Unzip this file in your Assets/Shaders directory (o if you put this somewhere else, update the hardcoded #include paths in the shaders) and create a new material that uses “Custom/Standard - VertexColor”

Vertex colors are multiplied with the Albedo and the texture, so you can also use this same shader for non-vertex colored meshes because by default Unity sets your vertex colors to white. In this case, you just adjust the Albedo property as usual. And of course you can also use textures if you want.

This is for beta 20. If you want to use this in a later beta, you’ll have to diff this code against upstream and merge the changes. It’s not hard - in fact, I’ve just done it yesterday as I was upgrading from beta 16.

@Silly_Rollo_1 : I suspect this code won’t help you too much, because it doesn’t touch the way the color is calculated at all. My changes simply change from where the diffuse color comes from, but after that everything else stays exactly the same, which is why I get the exact same look as the stock Standard shader.

1927462–124509–Standard - Vertex Color - Unity5 b20.zip (8.63 KB)

Hi there,

Thanks for the shader, but I already did it. The problem is performance. This is actually a solution, but not if you want custom shaders with less Draw calls or functions, and the most important: custom shaders with the same lighting model than Standard shader.
Vertex Colors shader was only the start, I have my own surface shaders with vertex modifiers and more, simply I’m trying to port them to unity 5 standard PB lighting model.