Gradient Based On Distance

Hi everyone, I just want to make a shader like this.
(Gradient color based on how far is from camera)


However If I move the camera their color will change to same value at the same time like the gif below.
5881448--626459--gradient.gif
Is it because all the gameobjects shared a same material? Or do I choose the wrong node?
How to make them calculate the distance individually so that they could show different color at different distance?
Any advice would be appreciated.Thanks!

Camera node position is in world space, so I would assume you want your Position node to also use world space, if you are calculating the distance between them.

1 Like

You’re right, Thanks!

1 Like