Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Setherino |
I have a shader and I want it to get more extreme with the players speed. How would I edit this shader’s parameters in runtime?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Setherino |
I have a shader and I want it to get more extreme with the players speed. How would I edit this shader’s parameters in runtime?
Reply From: | kidscancode |
You need to get a reference to the material. If it’s a CanvasItem (2D) you can get it with material
. If it’s a MeshInstance, you can use its GeometryInstance.material_override
or Mesh.surface_get_material
or PrimitiveMesh.material
. I’ve linked to the class docs if you need details.
After that it depends on what kind of material it is:
ShaderMaterial: You can change any uniform
parameter with set_shader_param()
ShaderMaterial — Godot Engine (3.1) documentation in English
SpatialMaterial: set the parameter name directly:
SpatialMaterial — Godot Engine (3.1) documentation in English
For example, if you have a boolean parameter, grayscale, to turn on and off grayscale:
$Sprite.material.set_shader_param(‘grayscale’,true)
attunemm | 2023-06-30 20:38