Passing player's position into visual shader?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By textrivers

I need to make a visual shader material that would turn partially transparent (ie lower the alpha) when the mesh is between the player and the camera. I can get the camera position, and I can do the calculations (“if object is between player’s position and camera position, lower alpha”) – how do I pass in the player’s position?

:bust_in_silhouette: Reply From: jtarallo

Use uniforms:

They also work in visual shaders, just like in scripted ones. You add them as any other node.

Thank you! Yeah I was looking at that. So do I just give it a reference with an absolute path to the player? And (assuming every object with this shader on it is updating the player’s position every frame) is that a problem for performance?

textrivers | 2020-06-09 23:19

I’d create a Vector3 uniform and have it be updated with the player’s position in a process function of a scene which has access to the shader. Don’t think performance will be an issue, but it depends in the complexity of the shader.

jtarallo | 2020-06-09 23:30

I’ll try that. Thank you!

textrivers | 2020-06-09 23:50

Working! The key to this was making sure that my uniform was a vec3, not a xform, so that when I passed in the translation it accepted it correctly. Thank you so much!!

textrivers | 2020-06-10 21:27

No problem! Glad to help. Good luck!

jtarallo | 2020-06-10 22:40