Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Using only Vertex Colors result in faded / too light colors

Discussion in 'Shaders' started by artofcode, Jul 21, 2018.

  1. artofcode

    artofcode

    Joined:
    Mar 18, 2013
    Posts:
    8
    I pass a vertex color to the mesh and use this as the only source of color (no Texture), but if I have a standard material with the same color value on a second mesh, it's a totally different color. Not sure what I'm doing wrong here. This is what it looks like:

    upload_2018-7-21_3-3-49.png

    The dark orange is using the 'Standard' shader, the mesh around it is using the above shader. Both use the same RGBA values.

    The shader doesn't do much, as you can see below. Is there anything I forgot to do here or am doing horribly wrong?

    Code (CSharp):
    1.  
    2. Shader "Custom/VertexColor Shader"
    3. {
    4.  
    5.     SubShader
    6.     {
    7.         Tags { "RenderType" = "Opaque" }
    8.         LOD 200
    9.        
    10.         CGPROGRAM
    11.         #pragma surface surf Lambert vertex:vert
    12.         #pragma target 3.0
    13.         struct Input
    14.         {
    15.             float4 vertColor;
    16.         };
    17.  
    18.         void vert (inout appdata_full v, out Input o)
    19.         {
    20.             UNITY_INITIALIZE_OUTPUT(Input, o);
    21.             o.vertColor = v.color;
    22.         }
    23.  
    24.         void surf (Input IN, inout SurfaceOutput o)
    25.         {
    26.             o.Albedo = IN.vertColor.rgb;
    27.         }
    28.         ENDCG
    29.     }
    30.  
    31.     FallBack "Diffuse"
    32.  
    33. }
    34.  
    Thanks for any insight you might have!
     
  2. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    960
    Light?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,522
    This is because vertex colors aren't gamma corrected when you're using linear color space.

    o.Albedo = GammaToLinearSpace(IN.vertColor.rgb);
     
    Buckslice and artofcode like this.
  4. artofcode

    artofcode

    Joined:
    Mar 18, 2013
    Posts:
    8
    Thank you so much!
     
  5. Anthony0506

    Anthony0506

    Joined:
    Oct 13, 2016
    Posts:
    75
    man it's like everytime i'm having a problem bgolus has already answered the question.
     
  6. Gian1983

    Gian1983

    Joined:
    Jan 2, 2019
    Posts:
    6
    Dear all,

    I haven't found any 'standard' shader in Unity which supports vertex colors thus I tried this one (thanks a lot !), without the correction suggested by bgolus. But as you can see on the picture below, light colors (here it's supposed to be a very light yellow and I have the same issue with very light grey) are shining and blur !



    And it's the same with bgolus' correction (even if colors are obviously different).

    Do you know what I can do to avoid this effect ??