Search Unity

Question How to get more vertex color support?

Discussion in 'Shader Graph' started by BATTLEKOT, Jul 7, 2021.

  1. BATTLEKOT

    BATTLEKOT

    Joined:
    Oct 2, 2016
    Posts:
    179
    Hello everyne! i did a shader for my texture array 2d atlas.
    I have a modular wall pack, that builded from single 8192x8192 atlas that contain 8 textures.
    Each texture in atlas have size 2048x4096 pixels.
    So i did a 2D texture array from 2 columns and 4 rows.
    After that i decide to use vertex paint to show shader with texture i want to be have on surface.
    At begin i tried to use those colors: white,dark,red,green,blue,yellow,light blue and pink.
    So i was thinking that in split channel i can combine several channels to get yellow,pink etc. but this idea was not worked for me.

    After that i decide to use RGB + Multiply RGB by 0.5 (Dark version of colors).
    But that kinda works but not yet.
    Here is result:
    upload_2021-7-7_15-11-43.png
    Here is my shader graph shader:
    upload_2021-7-7_15-12-0.png
    I have 8 2d Array textures: from 0 to 7. So i did 8 "Texture Array [X] (Color)".
    After that i did a reader of vertex color.
    Where are i was have two split channels. for normal RGB and darker RGB (by multiply RGB 0.5)

    After that i lerp it over and over and over with each channel, but something went wrong.

    But result strange too...

    Anyone know how to get more vertex colors support from vertex color node? not just RGBA.

    Thanks!
     
  2. BATTLEKOT

    BATTLEKOT

    Joined:
    Oct 2, 2016
    Posts:
    179
    I know that i can divide a one single color by 8 time , but for me as Artist it will be hard to see with vertex color use this model.
    Here a example of dividing Red color by x 8 time (-.125 units per step) and i get result (No worry, dark suqares is just do not have a texture yet).
    So for me it would be more pleasure to have different colors RGB, yellow,pink etc for debug model
    upload_2021-7-7_15-59-16.png

    upload_2021-7-7_15-58-24.png
     
  3. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Maybe write a custom node with "if" statement, where you compare the vertex color with some value?
     
  4. Demostenes_cz

    Demostenes_cz

    Joined:
    Jun 10, 2017
    Posts:
    32
    Using one channel for all textures is proper solution. You can have any number of textures you like and also you can make shader MUCH faster. Instead of this terrible spagheti graph, where each new texture means other lerp (more and more instructions), you can use single lerp where A = Tn, B = T(n+1). Now for blend value. For 16 textures index n = floor(VC*15,999) - index starts at 0, blend value = (VC*15,999)-n. On 5 textures such shader will have cca 100 less instructions (cca 1/2). Also this allows you to have other 3 free channels for other stuff like dirt, grunges, coloring....
    Single channel has slight disadvantage, since vertex color is interpolating between verteces, transition between for example the first and the last texture will contain all textures from array. But this can be mitigated by textures inside array (layering as in real life - brick-> grout - > stucco) and also by knowing this and not painting textures with big difference in indexes besides. Even with this disadvantage it is worthy, because of performance and memory savings. AAA games do this very often, for example witcher 3.
     
    Last edited: Oct 6, 2021