0 votes

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?

in Engine by (126 points)
edited by

1 Answer

0 votes

Use uniforms:

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

by (380 points)

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?

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.

I'll try that. Thank you!

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!!

No problem! Glad to help. Good luck!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.