Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vertex color doesn't show!

Discussion in 'Shaders' started by Seith, Nov 10, 2012.

  1. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Hello, this is my first post. I'm a newbie at Unity and so far I'm very impressed with what I see (I use the Unity 4 Beta).

    I have been able to import my animated character from Maya 2012 without problem (using the fbx exporter version 2011), but I met a strange issue: the vertex color information on my meshes is not displayed (I use the Bumped Specular shader, but I tried pretty much all the available shaders and the problem is still there).

    Now I know that Unity sees the vertex color data, since in the preview window it says "uv, color, skin". And the diffuse and normal maps are showing just fine. But again the vertex color are nowhere to be seen.

    Now I know this is an ultra basic newbie thing, but could anyone please help me...?

    [B]Update:[/B] This time I've tried with a simple cube, added a color set (tried with RGB and RGBA), painted a different color on each corner, exported and still no vertex color. Please don't tell me Unity doesn't support vertex color...
     
    Last edited: Nov 10, 2012
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The standard built-in shaders don't support vertex colors, aside from the particle shaders. You can make your own or modify the existing ones.

    --Eric
     
  3. yursiv

    yursiv

    Joined:
    Nov 9, 2010
    Posts:
    2
    Unity supports vertex colors, but standart materials in unity do not respect vertex colors, you need special shader for this.

    Try this one
    Code (csharp):
    1.  
    2. Shader "BumpedSpecularVtxCol" {
    3. Properties {
    4.     _Color ("Main Color", Color) = (1,1,1,1)
    5.     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    6.     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    7.     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    8.     _BumpMap ("Normalmap", 2D) = "bump" {}
    9. }
    10. SubShader {
    11.     Tags { "RenderType"="Opaque" }
    12.     LOD 400
    13.    
    14. CGPROGRAM
    15. #pragma surface surf BlinnPhong
    16.  
    17.  
    18. sampler2D _MainTex;
    19. sampler2D _BumpMap;
    20. fixed4 _Color;
    21. half _Shininess;
    22.  
    23. struct Input {
    24.     float2 uv_MainTex;
    25.     float2 uv_BumpMap;
    26.     half4 color : COLOR0;
    27. };
    28.  
    29. void surf (Input IN, inout SurfaceOutput o) {
    30.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    31.     o.Albedo = tex.rgb * _Color.rgb * IN.color.rgb;
    32.     o.Gloss = tex.a;
    33.     o.Alpha = tex.a * _Color.a;
    34.     o.Specular = _Shininess;
    35.     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    36. }
    37. ENDCG
    38. }
    39.  
    40. FallBack "Specular"
    41. }
    42.  
    43.  
     
    Last edited: Nov 10, 2012
    ErzaScarlet324 likes this.
  4. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Oh my. How strange. But thank you very much guys, that works now!

    However this is an extremely basic feature anyone is expecting out of the box and I'm frankly very surprised it isn't included in the standard shaders. I can't quite imagine why...
     
  5. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Every feature that is "supported" by a shader has a fixed cost, whether you use it or not. Most people use textures rather than vertex colours, so there would be a lot of wasted GPU time around the world if every shader was using undefined vertex colours to no effect.
     
  6. yursiv

    yursiv

    Joined:
    Nov 9, 2010
    Posts:
    2
    Yes, you are totally right. But why devs cant just include both versions : with vertex colors and no vertex colors? If you look at shader that i post you ll see that it is just standart blinn shader with 2 little edits. But it might be a problem for non-techy or newtounity people.
     
  7. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    There are all sorts of modifications you could make to the standard shaders with a couple edits. At some point UT have to assess what most people will use, and then just do their best to make sure that what everyone else wants is possible.
     
  8. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Thanks for you reply, Daniel. I understand what you're saying, but as Yursiv pointed out the best thing to do would be to at least include those shaders. Again it might be obvious for a Unity veteran, but to a beginner (with a lot of experience with other engines) it's a little bit like you've got a new car with four doors but the doors in the back won't open. Because some people don't need them to open (?!). Honestly it feels almost like a mistake that at least one shader with vertex coloring isn't included in the standard release.

    And it's all the more puzzling because to my beginner's eyes all of Unity seems amazingly straightforward and well thought-out. I love it!
     
  9. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Actually, particle colours are done with vertex attributes, so all the particle shaders support vertex colours.
     
    Kerihobo likes this.
  10. kablammyman

    kablammyman

    Joined:
    Nov 22, 2010
    Posts:
    507
    thaks for this! I wish teh docs provided this info!
     
  11. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    someone know how keep vertex color from zbrush obj please ? thank's
     
  12. Kerihobo

    Kerihobo

    Joined:
    Jun 26, 2013
    Posts:
    65
    Aaaaah thank you for this info! you just ended my endless search!
     
  13. UkkosTukki

    UkkosTukki

    Joined:
    Dec 31, 2015
    Posts:
    4
    Thanks a lot dude!
     
  14. ErzaScarlet324

    ErzaScarlet324

    Joined:
    Oct 28, 2016
    Posts:
    1


    I just wanted to say thank you ive spent hours trying fix this until i found this thank you
     
  15. CatNotDeveloper

    CatNotDeveloper

    Joined:
    Sep 30, 2021
    Posts:
    3
    Hey man i don't know how i can use the shader if it doesn't let me
     
  16. qzen

    qzen

    Joined:
    Jul 15, 2021
    Posts:
    5

    Hello! I am from future XD
    i just wanted to ask that, where am i gonna use this code?
    i realy dont know...