Access hint_range of uniform parameters in shaders to produce matching Sliders?

Godot Version

4.2.1

Question

Hello, I have a couple of shader uniforms:

uniform float distortion : hint_range(0.0, 1.0) = 0.1;
uniform float distortion_speed : hint_range(0.0, 32.0) = 1.0;

And then I have sliders that control these:

func _on_distortion_slider_value_changed(value):
	(self.material as ShaderMaterial).set_shader_parameter("distortion", value)


func _on_distortion_speed_slider_value_changed(value):
	(self.material as ShaderMaterial).set_shader_parameter("distortion_speed", value)

However, in order to create those Sliders in the UI, I manually matched the hint_ranges to minimum, maximum and default values.

Is it please possible to do all of this automatically and read hint_ranges when creating the UI Sliders (and, for example, set the minimum and maximum values in their _ready functions?

Thank you.

here’s the code
mat is the shadermaterial you wished to get
change the uniform_property_name to the uniform property you want to get.

var uniform_property_name="degree"
var properties=mat.get_property_list()
var the_hint_range:String
for i in range (properties.size()):
	var property = properties[i]
	if property.name == "shader_parameter/"+uniform_property_name:
		the_hint_range=property.hint_string
		break
var ranges=the_hint_range.split(",")
print("min = %s, max = %s, default = %s"%[str(ranges[0]),str(ranges[1]),str(ranges[2])])
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.