I want to have a slider that the player uses to change how a shader affects the color of a sprite.
Here is the shader:
shader_type canvas_item;
uniform vec4 color : source_color;
void fragment(){
vec4 pixelColor = texture(TEXTURE, UV);
float brightness = (0.7 * pixelColor.r + 0.7 * pixelColor.g + 0.70 * pixelColor.b);
vec4 greyScale = vec4(brightness, brightness, brightness, pixelColor.a);
COLOR = greyScale * color;
I’ve been testing it with this button that randomizes the color and it’s great:
func _on_button_pressed():
material.set_shader_parameter("color", Color(randf(), randf(), randf(), 1.0))
Now I want to be able to control the hue of the color.
I have made a class script for the hues levels. I then imported it to the script that contains the sliders and sprite as a variable named HueClass.
class HueCodes:
var red = Color(0.7607843137, 0.0823529412, 0.0823529412, 1.0); //it goes on throughout the rainbow
I’m kind of lost on what to do next though! I thought of doing something like this:
func _on_hue_value_changed(value):
HueClass[value]
if value == 0:
ShaderParam.set_shader_parameter("color",HueClass.red)
print(value)
but I got an error saying “Invalid get index ‘2’ (on base:GDscript)”. If anyone could point me into the right direction, let me know. Thank you.