Shader color from camera distance

Shader color from camera distance

pacox21
Enthusiast Enthusiast
1,368 Views
6 Replies
Message 1 of 7

Shader color from camera distance

pacox21
Enthusiast
Enthusiast

Hello 🙂


Is there a way to input the camera distance into a shader to control its color ?


I can't find any solution ...


Thanks for your help !


Francis

0 Likes
1,369 Views
6 Replies
Replies (6)
Message 2 of 7

peter.horvath6V6K3
Advisor
Advisor

You can access the ray length (Rl) via a state_float shader, which is the distance from the ray origin (camera) to the shading point.

0 Likes
Message 3 of 7

pacox21
Enthusiast
Enthusiast

Thanks Peter, I'll give it a try and share my progress !

0 Likes
Message 4 of 7

pacox21
Enthusiast
Enthusiast

I can't get it to work ... I don't get how to output a Z like render of my surface with a black and white gradient ... Any tip ?

0 Likes
Message 5 of 7

pacox21
Enthusiast
Enthusiast

I plug the output of the RL into a ramp_float node, but all I can get is a uniform color, even when I play with the spline or the UV projection

0 Likes
Message 6 of 7

peter.horvath6V6K3
Advisor
Advisor

It's an absolute distance (in meters), you need to remap with a range shader.

0 Likes
Message 7 of 7

pacox21
Enthusiast
Enthusiast

It works !! Thank you for your help Peter ! capture-decran-2021-02-18-a-152311.png

0 Likes