godot 4 shader get/set parameter
Asked Answered
P

1

0

hello,
Is there a way to change a shader paramenter in GDscript ?
The old code is not working anymore

	var shdBlur = $CanvasLayer/ColorRect.get("shader_param/amount");
	
	if ( shdBlur == null ):
		print(shdBlur);
	
	if ( shdBlur != null ):
	
		if ( Input.is_action_just_pressed('key_w') && shdBlur < 4 ):
			$CanvasLayer/ColorRect.material.set("shader_param/amount", shdBlur + 0.0001);
		elif ( Input.is_action_just_pressed('key_s') && shdBlur > 0 ):
			$CanvasLayer/ColorRect.material.set("shader_param/amount", shdBlur - 0.0001);

I am dragging the parameters on to the script editor.
"shader_param" seems to be "shader_parameter" now. However it still doesnt work,
it seems to work with all other options ex: "visible", "modulate", "show_behind_parent", etc...

"shader_parameter" always returns <NULL>

Platt answered 25/1, 2023 at 14:47 Comment(0)
P
0

just releazied the error .material was missing from "var shdBlur = $CanvasLayer/ColorRect.get("shader_param/amount");"

	#-------------//--shader--//---------------------------------
	
	var shdBlur = $CanvasLayer/ColorRect.material.get("shader_parameter/amount");
	
	if ( shdBlur != null ):
		
		if ( Input.is_action_just_pressed('key_w') && shdBlur < 4 ):
			$CanvasLayer/ColorRect.material.set("shader_param/amount", shdBlur + 0.0001);
		elif ( Input.is_action_just_pressed('key_s') && shdBlur > 0 ):
			$CanvasLayer/ColorRect.material.set("shader_param/amount", shdBlur - 0.0001);

Although ( get ) can only be accessed with "shader_parameter"
( set ) can use both "shader_parameter" and "shader_param"

	#-------------//--shader--//---------------------------------
	
	var shdBlur = $CanvasLayer/ColorRect.material.get("shader_param/amount");
	
	if ( shdBlur == null ):
		print ("jkdfhfkjsdhfkjdsh");
Platt answered 25/1, 2023 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.