The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

Hi there,
From the docs:

A variable can be declared as uniform. In this case, its value will come from outside the shader (it will be the responsibility of the material or whatever using the shader to provide it).

How can I access a variable declared as uniform in a shader script from inside the GD script ?
thanks,

in Engine by (530 points)

1 Answer

+1 vote
Best answer

This code gets a camera position and push it to shader. To get it, you can use get_shader_param.
var cameraPosition = get_node("actor/yaw/camera").get_global_transform().origin; get_node("crystalClearShader").get_mesh().surface_get_material(0).set_shader_param("CameraPosition", cameraPosition)

by (836 points)
selected by

you rock, I'm in 2D and this worked for me:
getmaterial().setshader_param("variable", value).
Now I can assign values for the shader from inside the gd script

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.