![](https://knowercoder.com/wp-content/uploads/2023/11/CameraDistanceMask.gif)
If we want to make an object dull / darker when we move closer to it and brighter when we move far away, then what we need is a camera distance mask.
All we have to do is calculate the distance between the vertex position and the camera and add/scale it with some constant.
Distance Mask = ( Length( CameraPos – VertexPos ) + C1 ) * C2
First, Subtract the vertex position from the camera position. This will give the distance vector.
![](https://knowercoder.com/wp-content/uploads/2023/11/image-16.png)
The ‘Length’ node will calculate the scalar magnitude of the distance vector. Add and multiply it with some constant values based on how fast the transition between dark to bright should happen.
Finally, assign this value to the ‘Base Color’ to visualize the effect.
![](https://knowercoder.com/wp-content/uploads/2023/11/image-17-1024x451.png)