Could you get the distance from and object in a ShaderGraph shader?

Hi there,

I was trying to get an effect like this, when a character moves near a wall in shader graph but I’ve been struggling a bit, would it be possible to use the distance from an object’s pivot in a shader graph shader?
Might not be the way to approach it but I just thought I’d check it anyone knows a good way.
7449254--913763--Distance.gif

Thanks,
Pete

It is actually quite simple.
You can send position of object in world space to the shader and calculate each pixel position in world space in shader.
Than you calculate distance between those positions in shader (per pixel).

Hey thanks @koirat , how could you send the position to the shader? Would you make a vector 3 and feed it in like that?

Yes

Thanks @Antypodish , just getting into this stuff. :slight_smile:

Hi, I know this is an old thread but I’m currently trying to do the same by using SetVector but so far it doesn’t work out good. If I put a camera as an object it handles it fine. But if I set a Vector4 to some values it doesn’t do anything to the vector (I print the values to make sure I’ve changed them succesfully) Could it be because of the conversion from Vector4 to Vector3?

(the SetVector method only accepts Vector4 values with no overload)

Edit:
Nevermind it worked I just was using the name and not the reference (the naming convention of variables within Unity could use a tweak SetVector accepts Id or name as a first argument, whereas it should say it accepts a string REFERENCE or Id)