Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Standard shader with vertex colors

Discussion in 'Shaders' started by defaxer, Apr 5, 2015.

  1. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    696
    I tested this one but normal maps not working? or that just me?
     
  2. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    36
    Hi,

    I tried version 0.92 and while I get it working on 5.5 using workarounds mentioned before, there are new problem in 5.6b4.

    Error I get is:

    Shader error in 'Standard (Vertex Color)': invalid subscript 'tangentToWorldAndPackedData' at Assets/UnityVC/UnityVC.cginc(149) (on d3d11)

    Compiling Vertex program with DIRECTIONAL _VERTEXCOLOR_OFF
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP
     
  3. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    36
    Okay, I fixed it and got it working for versions for 5.5 and 5.6b (or at least it seems to be working)

    If someone needs them. I can post them here or somewhere
     
    Tzan likes this.
  4. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    509
    Thanks Masolnar, that would be great if you could post things when you get them working!

    I can't test it myself yet. I've still been on 5.3.5f1 because I just need to get more code written, I don't think the newer versions add much I need and Unity keeps breaking the shader.

    I do download the latest for use in the future, I do expect to move up my version eventually.

    Thanks!
     
  5. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    36
    Both files can be found in https://gist.github.com/H-man/d5cc76afd930f90dc18b06e69cd9f503

    For 5.6 version I had to change:
    half4 tangentToWorldAndParallax[3] : TEXCOORD2; --> half4 tangentToWorldAndPackedData[3] : TEXCOORD2;

    and also needed to add float4 posWorld : TEXCOORD8; in VertexOutputForwardAdd_VC struct

    VC_shader.JPG
     
    Wolffsen and Player7 like this.
  6. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    509
    Thanks!
     
  7. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    175
    I can't make it work on 5.5. several hours in. Had anybody any luck? The shader above doesn't compile, and I cant fix it.
     
    Last edited: Jan 23, 2017
  8. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    36
    Can you post the error message and shader code? Maybe I can help..
     
  9. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    87
    Just to follow up on @Tzan's point that @Coredumping is using the standard shader with a couple of small mods - this is currently working for me on 5.5.

    Code (CSharp):
    1.  
    2.  Shader"Custom/VertexColor" {
    3. Properties {
    4.  _Color ("Color", Color) = (1,1,1,1)
    5.  _MainTex ("Albedo(RGB)", 2D) = "white" {}
    6.  _Glossiness ("Smoothness", Range(0,1)) = 0.5
    7.  _Metallic ("Metallic", Range(0,1)) = 0.0
    8.  }
    9. SubShader {
    10. Tags { "RenderType"="Opaque" }
    11.  LOD 200
    12.  
    13. CGPROGRAM
    14. //PhysicallybasedStandardlightingmodel,andenableshadowsonalllight types
    15. #pragmasurfacesurfStandardfullforwardshadows
    16.  
    17. //Useshadermodel3.0target,togetnicerlooking lighting
    18. #pragmatarget3.0
    19.  
    20. sampler2D _MainTex;
    21.  
    22. struct Input {
    23. float2 uv_MainTex;
    24. float4color : COLOR;
    25.  };
    26.  
    27. half _Glossiness;
    28. half _Metallic;
    29. fixed4 _Color;
    30.  
    31. void surf (Input IN, inout SurfaceOutputStandard o) {
    32. //Albedocomesfromatexturetintedby color
    33. fixed4 cc = IN.color;
    34. fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * cc * _Color;
    35.  
    36.  o.Albedo = c.rgb;
    37. //Metallicandsmoothnesscomefromslider variables
    38.  o.Metallic = _Metallic;
    39.  o.Smoothness = _Glossiness;
    40.  o.Alpha = c.a;
    41.  }
    42. ENDCG
    43.  }
    44. FallBack"Diffuse"
    45. }
    46.  
     
    Tzan likes this.
  10. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    175
    Thank you!

    There is an error:

    I'v imported 0.92 version and replaced UnitiVC with one from your github link (5.5 one)
     
  11. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    36
    Strange. I think it must be some of those #ifdef:s around lines 263 - 288 that are defined different in your project.

    I attached my test project that works on my machine at least.
     

    Attached Files:

  12. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    175
    Thank you! I managed to get it working by changing 299 line from
    Code (CSharp):
    1. #if UNITY_SPECCUBE_BOX_PROJECTION
    to
    Code (CSharp):
    1. #if UNITY_SPECCUBE_BOX_PROJECTION || UNITY_LIGHT_PROBE_PROXY_VOLUME
    But new problem arrived. I need that shader to fade away over time ejected gun shells particles. And they really do become transparent.
    But in fade (and transparent) mode meshes loose their ability to recieve shadows, so they shine in a shadow.
    I have no experience in shaders, so question might be plain dumb, but - Can it be helped?
     
    Last edited: Jan 25, 2017
  13. xiaojwan

    xiaojwan

    Joined:
    Jan 25, 2017
    Posts:
    2
    Hi, defaxer,
    Thanks for the great shader first :) However, when I was importing it to Unity 5.5.0f3, it reports such error:"Shader error in 'Standard (Vertex Color)': 'MainLight': no matching 1 parameter function at Assets/Shaders/UnityVC/UnityVC.cginc(125) (on d3d11)"

    Since I am new to Unity, do you know why it report this error?

    Thanks
     
  14. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    175
    Hi! Look for an attachment from couple posts above by @MasoInar . It fixes that error. And you could apply my one-line patch from above too if something won't work..
     
  15. xiaojwan

    xiaojwan

    Joined:
    Jan 25, 2017
    Posts:
    2
    Hi, thanks for the suggestions. I have used UnityVC.cgnic in https://gist.github.com/H-man/d5cc7...f503/bff05d6dc6f671799c750c45b4e9b8032aa77a0d
    However, it still reports this error "Shader error in 'Standard (Vertex Color)': invalid subscript 'posWorld' at Assets/UnityVC/UnityVC.cginc(299) (on d3d11)" :-(
     
  16. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    175
    2 posts above is the solution that solved that error for me.
     
  17. gambikules

    gambikules

    Joined:
    Aug 3, 2015
    Posts:
    3
    i have unity 5.5.1f1 and i get this error

    Shader error in 'Standard Specular (Vertex Color)': invalid subscript 'posWorld' at Assets/UnityVC/UnityVC.cginc(299) (on glcore)

    Compiling Vertex program with DIRECTIONAL SHADOWS_SCREEN
    Platform defines: UNITY_NO_SCREENSPACE_SHADOWS UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF2 SHADER_API_DESKTOP UNITY_HARDWARE_TIER3 UNITY_COLORSPACE_GAMMA

    i have import version 0.92 and replaced UnitiVC with one from github link 5.5!

    UnitiVC already has #if UNITY_SPECCUBE_BOX_PROJECTION || UNITY_LIGHT_PROBE_PROXY_VOLUME

    at line 298
     
  18. Wolffsen

    Wolffsen

    Joined:
    Apr 21, 2014
    Posts:
    1
  19. JamesNJ

    JamesNJ

    Joined:
    Feb 24, 2017
    Posts:
    1
    Hi
    I am trying to make a simple project just to get an understanding how to color the surface on a mesh in unity.
    I work as a developer and have been doing C# development for 8 years and want to learn how to work with 3D graphics.
    I have been trying to just make a project where I can use vertex coloring to set different colors on the sides of a cube, but haven't had any success. I have tried all the file and projects in this thread, and anything else I can find online, but haven't been able to get any of them to work in Unity 5.5.
    Except for unityVC_test_550f3 which worked until I tried to move the shader and material to be able to use it on my cube, then I got a bunch of errors I have no idea what they means.
    I have been trying to get my head around how this works for months now, but still haven't really made any progress.

    Could someone please point me in the direction of a good sample project or tutorial if you know of one?
    Or could someone that understands this stuff, please make a really simple project for me with a cube with a color array that sets the vertex's to give different sides of the cube different colors.
     
  20. tkamruzzaman

    tkamruzzaman

    Joined:
    Jun 28, 2015
    Posts:
    7

    on UnityVC.cginc remove this || UNITY_LIGHT_PROBE_PROXY_VOLUME from line 298
    also comment all the block / function from lines 363 to 411
     
  21. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    36
    Hi, I made super simple unity project with two simple vertex color shaders (lit and unlit) and script that allows you to set different colors to top, bottom and sides of the cube at runtime. It might be too simple for your needs, but hopefully you get the basic idea of setting vertex colors :)

    https://github.com/H-man/SimpleVertexColors
     
  22. petersvp

    petersvp

    Joined:
    Dec 20, 2013
    Posts:
    30
    It does not work in 5.5.
     
  23. caseysteffen

    caseysteffen

    Joined:
    Mar 29, 2017
    Posts:
    1
    Anybody figure out how to get this building on Android or iPhone. Everything works fine on the PC, but when I build to test on my android phone, materials turn pink. Please feel free to point me to the solution if I missed a comment on this thread. Thanks Masolnar.
     
  24. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    36
    Hi, I got it working on Android (tested on editor and actual device) and made a github repo for you, but it's for unity 5.6.0f2. I Hope it helps. I don't currently have any IOS device, so I can't test with that.

    https://github.com/H-man/UnityVertexColors
     
  25. Herstt

    Herstt

    Joined:
    Apr 22, 2017
    Posts:
    1
    Hey I'm using Unity 5.5.3f1 and getting this error

    invalid subscript 'posWorld' 'FragmentSetup': no matching 5 parameter function
    Compiling Vertex program with DIRECTIONAL
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA

    I did all the changes to the code on this post, but since I started to use shaders this week I don't know how to fix this error.
    Thanks for the help
     
  26. hwilliams

    hwilliams

    Joined:
    Nov 29, 2016
    Posts:
    4

    I could Kiss you! But I'll just thank you immensely!!!!
     
    MasoInar likes this.
  27. ArthDev

    ArthDev

    Joined:
    May 14, 2017
    Posts:
    1
    Thanks !
     
  28. DanaScully

    DanaScully

    Joined:
    Oct 27, 2016
    Posts:
    1
    Hi guys. This looks pretty cool but I couldn't use it in Unity 5.5.1. It says:

    Shader error in 'Standard (Vertex Color)': 'MainLight': no matching 1 parameter function at Assets/Shaders/UnityVC/UnityVC.cginc(154) (on d3d11)

    I am not sure how to resolve this problem
     
  29. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    509
    So I started using
    Unity 5.5.2f1
    StandardVC.shader v.91
    UnityVC.cginc v.92.1

    Not using a Metalic texture works fine.
    When I add texture, the R channel interacts with the normal map wrong, highlights are hitting in wrong ways.
    The Alpha channel seems to be ignored entirely.

    I could provide images if someone was interested.

    I tested my texture with the Unity Standard shader + cube, alpha is there and works fine.
     
  30. buexe

    buexe

    Joined:
    Jul 17, 2013
    Posts:
    1
    Works like a charm for me. Thank you so much everybody who made this possible!!! :)
     
    MasoInar likes this.
  31. iperov

    iperov

    Joined:
    Dec 13, 2015
    Posts:
    21
    nothing works in latest unity
     
  32. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    36
    Alverik likes this.
  33. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    733
    Great job! i just tested it i was also using 2017.1.0f1, and working on a webgl 2.0 port of my android game. and it works in chrome!
     
    MasoInar likes this.
  34. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    733
  35. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    124
    While this does work nicely, the colors are incorrect when working in linear space. I'm no expert but changing the vertex shader outputs from o.color = v.color to something like

    Code (CSharp):
    1. #ifdef UNITY_COLORSPACE_GAMMA
    2.     o.color = v.color;
    3. #else
    4.     o.color.rgb = GammaToLinearSpace(v.color.rgb);
    5.     o.color.a = v.color.a;
    6. #endif
    should handle it?
     
  36. gsoft9999

    gsoft9999

    Joined:
    Jul 17, 2017
    Posts:
    2
    Thanks guys, this is the only Shader i ever needed. If i make some money from my game I will Donate some money. Thanks again :D
     
  37. gsoft9999

    gsoft9999

    Joined:
    Jul 17, 2017
    Posts:
    2
    I got a problem with this shader. Im assigning it at runtime and its vertex properties wown't work unless i expand the material in editor. now i found this in script ref https://docs.unity3d.com/Manual/MaterialsAccessingViaScript.html
    and i have enabled everythining i could but i can't find how to enable vertex. Anyone knows how to enable it?
     
  38. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    733
    if you add the vertex colored to your model in either c# code, or in the modeling program, it will give your 3d model vertex coloring.

    I do both. I set some things in my 3d program to be a certain vertex color per object.

    And in the case of that link i gave, i use code to assign house colors, and even in the map editor i low editing users to color the house. All using vertex color.
     
  39. Sphax84

    Sphax84

    Joined:
    Jun 23, 2015
    Posts:
    27
    Hi,

    I am on Unity 5.5 and get this error message:
    Code (CSharp):
    1.  
    2. Shader error in 'Standard (Vertex Color)': invalid subscript 'posWorld' at Assets/Shaders/UnityVC/UnityVC.cginc(299) (on d3d11)
    3.  
    4. Compiling Vertex program with DIRECTIONAL _VERTEXCOLOR_OFF
    5. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA
    6.  
    I replaced UnityVC.cginc code by the one from Github by MasoInar...

    Can anyone help?