Search Unity

Question Shader Graph Apply Different colours onto different sides of the model

Discussion in 'Shader Graph' started by Artpen, May 26, 2020.

  1. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Hi Guys,
    I am new to Shade Graph. Trying a simple shader which applies different colours to different sides of the model.
    I managed to do it with 3 faces , but opposite faces are black. I tried to add change vector orientation to -1 but it doesn't work.

    Any advice?
    Thank you for help

    Screenshot 2020-05-26 at 22.13.44.png Screenshot 2020-05-26 at 22.13.55.png
     

    Attached Files:

  2. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Should be easy, but I still can't find a solution? I had another thought, even if I will apply same material on opposite sides it will look strange while orbiting around the object.

    So shading should follow camera or directional light
     
  3. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Anyone?
     
  4. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    121
    Put an Absolute node after each Dot Product node.
     
    Artpen likes this.
  5. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    You could also use view direction, depending on what kind of effect you are looking for. Then the coloring would be view space relative, so that left side always stays certain color and so on.
     
    Artpen likes this.
  6. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Cool thank you guys. I think I have found a way. I used blend node.
    Screenshot 2020-08-16 at 20.35.54.png
     
  7. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Now just trying to find a way to control background colour. But I think there is no an easy way.
    I want to have background white after applying post effects.
     
  8. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    This is cool. It might help. Cause currently I have left and right side same color.
    So when I look from shadow side it looks strange light face in dark.

    Using view direction should solve this problem...
     
  9. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Are you typically going to be doing this with a cube? and you want each face to have its own color?

    Start with a Normal Vector Node, in Object Space. Split node that. Then, for X, drag that into a saturate node, then Multiply that by a new Color called Right. Again, for X, drag that into a Negate node, then Saturate, then multiply that by a new Color called Left.

    For Y, do the same thing, saturate, multiply by color TOP. Y, negate, saturate, multiply by color Bottom. For Z, again do the same thing, multiply by colors Front and Back.

    Add all 6 of them together. Output that (into Emissive or Color or where ever you want it)

    Use that in a material on a cube/sphere in your scene. Rotate the object/s. If you don't want to colors to stay aligned with the individual obect/s, change the Normal Vector to World Space.
     
    Kirbstar14 and Artpen like this.
  10. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Thank you @Jesus
    I did almost the way you described. I will have to use it on curved objects as well.
    I am now experimenting with view direction node. To avoid having light colours in shadow