Search Unity

Question How to make zebra shader?

Discussion in 'Shader Graph' started by dccoo, Nov 5, 2020.

  1. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    Suppose I have a big object like this:

    upload_2020-11-5_12-1-52.png

    I want to make a shader that looks like this: it gets the world position of the pixel (in the x-axis, for example) and chooses the color based on it. In the figure, each unit is a color.

    I tried but my shader is not repeating the colors. How can I do it?
     
    Last edited: Nov 5, 2020
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,

    So what have you tried so far. Can you show us a Graph?
     
  3. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    I've just done it. I used the Position node (with space World), got the Z axis coordinate using a Split node and getting the B channel, then I used a Modulo node, doing B channel modulo 2, to get a result between 0 and 2. With a Comparison node, I asked whether this result is less than 1, if it is, then I chose one color, otherwise I chose another, using a Branch node to do the choice. The output of the Branch node goes to the Albedo of the main node (PBR Master).
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    @dccoo here's another way you could do it. I didn't include it in my example, but you could use the resulting black and white to pick the colors and so on.

    See my example here. It might be a bit simpler than yours. And if you want smooth transitions, you could use smoothstep to control the steepness of the transition from black to white.

    Graph

    20201105_Unity_zebra_stripes_worldspace.PNG

    Result

    20201105_Unity_zebra_stripes_worldspace2.PNG
     
    SanyaBane and dccoo like this.