Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Vertex Color precision on various devices.

Discussion in 'Shaders' started by wzhevago, Mar 4, 2024.

  1. wzhevago

    wzhevago

    Joined:
    Nov 22, 2018
    Posts:
    1
    I'm making a shader in which the R channel of Vertex Color is used as a bit mask with 8 flags, with which I want to mark the places where different textures should apply. But, I have concerns about the accuracy of vertex color on various devices. How likely is it that in different stressful situations, or for example on different devices, my vertex color may not be accurate enough, causing various visual artifacts?
     
  2. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,110
    Data from vertics is not compressed like textures. so inputs of vertex shader everything will be fine.
    but everything else depend on platform and shader code
     
  3. aras-p

    aras-p

    Joined:
    Feb 17, 2022
    Posts:
    75
    Vertex colors in Unity, out of the box, are either 8 bit/channel, 0..1 range (Color32) or 32 bit/channel, full float (Color). You can also make the Mesh colors attribute your own custom format, if you really want to, using Mesh scripting API.

    So yes, it all should work fine. Use default Color32 (Mesh.colors32), that way you get 32 bits total (8 bits/channel). In your shader you will get a value in 0..1 range for each channel, so multiply that by 255 to get into 0..255 range.

    And then, unless you are on WebGL 1.0 or OpenGL ES 2.0 (both of these are no longer supported by Unity, I think?), you can cast to an integer and do bit mask operations to check your "flags" etc.
     
    DevDunk likes this.