Search Unity

Standard shader with vertex colors

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

  1. Player7

    Player7

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

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    126
    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:
    126
    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:
    736
    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:
    126
    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:
    736
    Thanks!
     
  7. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    307
    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:
    126
    Can you post the error message and shader code? Maybe I can help..
     
  9. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    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:
    307
    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:
    126
    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:
    307
    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:
    307
    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:
    307
    2 posts above is the solution that solved that error for me.
     
  17. polysoft3D

    polysoft3D

    Joined:
    Aug 3, 2015
    Posts:
    29
    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:
    3
    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:
    8

    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:
    126
    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:
    63
    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:
    126
    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:
    7

    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:
    736
    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:
    36
    nothing works in latest unity
     
  32. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    126
    m4d and Alverik like this.
  33. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    744
    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:
    744
  35. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    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:
    744
    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:
    36
    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?
     
  40. hacaro76

    hacaro76

    Joined:
    Oct 14, 2015
    Posts:
    25


    Same for me on Unity 5.6.2f1 anyone have ideas ?
     
  41. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    736
    These generally only work in the version it says it works with.
    There is no guarantee it works on any other version.
    I'm still on 5.5.2 because the version I'm using sort of works but not fully.
    Read my post from June.
     
  42. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    126
    Quick update, I just updated to latest stable unity (2017.1.1f1) and tested vertex colors shaders. Everyhting seems to work fine and without any errors.

    If you want to check it out, I also updated the codes to github and moved everything to master branch. I made unity5.6 branch for backup, but I can't currently test or fix problems with that version.. Sorry about that.

    Edit: link to git: https://github.com/H-man/UnityVertexColors
     
    Last edited: Sep 10, 2017
    Tzan likes this.
  43. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    736
    The link above to the GIT is broken.
    But I found it anyway :)

    If you made changes to the important files you should probably update the comment notes at the top to mention the version its been adjusted for and/or currently supports.
    I'm not sure if the current comments are accurate.
    .shader
    .cginc

    Thanks for the support!
     
    MasoInar likes this.
  44. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    126
    Just updated VC shaders so GPU instancing can now be enabled like in default standard shader. Also tried to find and update those comments in .shader and .cginc files ;)
     
  45. ramminus

    ramminus

    Joined:
    Apr 9, 2017
    Posts:
    1
    Why do vertex coloured shaders look washed out in linear colour space, I really need the vertex colour one for my particle system but have to use gamma colour space which looks terrible
     
  46. VOTRUBEC

    VOTRUBEC

    Joined:
    Dec 17, 2014
    Posts:
    106
    Just a shout out to Masolnar for the top work keeping this asset alive. Thanks mate!
     
    MasoInar likes this.
  47. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    126
    Hi, I tested those shaders with linear and gamma mode and yes, the results look different. It might be the different blending that causes this (see: https://docs.unity3d.com/Manual/LinearRendering-LinearOrGammaWorkflow.html)

    Anyways I updated and tested the shaders with Unity 2017.2.0f3 and all seems to work fine. I also attached the screen shot where you can see that in linear color space the colors are not so bright and vibrant, but maybe you can 'correct' those with post processing?
    linearVSgamma.png
     
    Alverik likes this.
  48. mraeclo

    mraeclo

    Joined:
    Dec 3, 2016
    Posts:
    10
    Hello everybody, sorry for the noob question but how am I supposed to use this latest version?

    The first version came as an unity package, the one available on github is a unity project, Ive tried to import the shaders and it asked for the UnityVC file, I`ve imported it and now its asking for the editor file, pretty sure it will ask for something else after this. How can I import the necessary assets to another project?

    thanks in advance, and Masolnar, thanks for sharing this content, Its really helping me out
     
    Last edited: Nov 23, 2017
  49. MasoInar

    MasoInar

    Joined:
    Feb 20, 2014
    Posts:
    126
    Could you just copy the UnityVC folder in your project's asset folder? You can delete that example scene, fbx and textures if you want.
     
  50. TabuuForteAkugun

    TabuuForteAkugun

    Joined:
    Sep 28, 2015
    Posts:
    58
    Hi.

    @Masolnar I've downloaded your 2017.2.0 version and the shaders give me "Can't find UnityVC.cginc" and "UnityVCShadow.cginc" errors, even after importing the CGIncs first. The shaders can't find them. What can I do?

    Thanks. :)

    EDIT: Never mind, I imported it wrong: I copied the UnityVC folder into Assets then moved everything to the folders I made, worked great. Sorry for the bother!
     
    Last edited: Dec 1, 2017
    MasoInar likes this.