Search Unity

Question Base gradient (Time) on lighting in ShaderGraph

Discussion in 'Shaders' started by petey, Jun 6, 2020.

  1. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hi there,

    Just getting into Shader Graph. Is there a way base the time value of a gradient on the direction of a light on an object? I thought it might be something like getting the dot product of the light direction and surface normals, but I can't seem to get anything to work.

    Could someone point me in the right direction?

    Screen Shot 2020-06-06 at 5.13.57 pm.png

    Thanks!
    Pete
     
  2. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hi, sorry to bump this but I'd still love to know if there's a solution. If not with lighting, is there a way to take the direction of an object and use that to control the way a gradient is applied to a surface? So I could sorta fake it?
     
  3. Beauque

    Beauque

    Joined:
    Mar 7, 2017
    Posts:
    61
    Hi, I think I had a question similar to yours and I figured it out myself in the end.
    I am using ASE not ShaderGraph but nodes are often the same. Not sure this is exactly what you were looking for, it might at least inspire you:
    https://forum.unity.com/threads/gradient-based-on-relative-direction.930810/

    EDIT: I basically got the dot product of the world position (could be a relative position to an object) and the local position transformed to world (I don't really get why it works though). It gives me a gradient directed toward the world origin.
    I think you can replace the local position transformed to world with the vertex normal if you need your gradient to be also based on the shape of your object.
     
    Last edited: Jul 16, 2020
    petey likes this.
  4. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Cool, thanks for that!
    Here's what I have -

    Screen Shot 2020-07-17 at 7.28.11 am.png

    Screen Shot 2020-07-17 at 7.30.41 am.png

    It seems that you can't edit gradients in the inspector, which is a bit annoying but other than that, It works pretty great!

    Thanks,
    Pete