Search Unity

shader changes based on object position (shader forge)

Discussion in 'Shaders' started by afresh, Apr 9, 2017.

  1. afresh

    afresh

    Joined:
    Jul 11, 2015
    Posts:
    2
    I was wounder if any one had experience or could shed light on how to make a shader that changes based on an object position?

    Example would be I have an object that is in X,Y,Z space and it moves around in the environment controlling a ramp that is used in a shader that is applied to another object.

    Like a fake Fresnel that can moved/slide on the object based on another object position.

    Hope that make sense.

    I'm building the shader in shader forge.

    Cheers,
    Allen
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    The only way a shader can know about another object is by passing that information to the shader via a custom script. This isn't something shader forge can handle for you by itself, but you can add input parameters to the shader that you can set yourself.

    https://docs.unity3d.com/ScriptReference/Material.SetVector.html
     
  3. afresh

    afresh

    Joined:
    Jul 11, 2015
    Posts:
    2
    Cool.. I'll look into it. Thanks for the tip. Cheers.