#Toggle Shader Influence via checkbox

4 messages · Page 1 of 1 (latest)

hard cairn
#

Hello!

I have a popup menu that I use as a debug info source. Inside the popup menu is a checkbox that I want to tie to the "Influence" parameter of a shader.

In the main script I have this function to update the checkbox:

func _on_popup_menu_id_pressed(id):
    if id == checkbox_index:
        rainbow_checkbox = !rainbow_checkbox
        update_popup_menu()
        toggle_rainbow_shader()
    elif id == delete_checkbox_index:
        queue_free()  # Delete the player```

Here's the actual function where the shader should be toggled at, called from the above:

```py
func toggle_rainbow_shader():
    #sprite_duck.get_material().set_shader_param("strength", 0.5 if rainbow_checkbox else 0.0)
    if rainbow_checkbox:
        sprite_duck["shader_parameter/influence"] = 0.5
    else:
        sprite_duck["shader_parameter/influence"] = 0.0```

Pretty sure I'm off the rails at the last part. The error I get is `Invalid call. Nonexistent function 'set_shader_param' in base 'ShaderMaterial'.`

Any guidance here is appreciated! Let me know if there's additional info needed.

(Also fairly new to Godot & programming in general, FYI)

Thanks!
grave elk
#

I think Godot 4 might have changed it to set_shader_parameter instead of set_shader_param

#

sprite_duck.set_shader_parameter("influence", 0.5) might work