shader works in editor but not in runtime. why?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By J u s t N a t e

i made a simple shader to change the ‘select_colour’ to the ‘new_colour’, it works in the editor but when i run it there are no changes to the character.


also, how do i access the shader param in a .gd script e.g. script, im pretty sure there are get_shader_param() and set_shader_param() functions, i just don’t know how to access/use them?

To use get_shader_param() and set_shader_param(), you need to call it on the shader material. So, use node.material.get_shader_param().

exuin | 2020-10-02 01:49

exuln, im not getting any errors but it doesnt update the colour in runtime.

func _ready():
$Sprite.material.set_shader_param(“new_colour”, Color(180,82,82))

J u s t N a t e | 2020-10-02 01:58

:bust_in_silhouette: Reply From: exuin

I think it has something to do with floating point number imprecision. There’s an answer here that can help. You can also use the distance() function, too (I recreated your code and rounding / checking for a threshold worked).

could you give me an example of the code you used (i understand things better if i can see them)

J u s t N a t e | 2020-10-02 05:04

shader_type canvas_item;

uniform vec4 select_colour : hint_color;
uniform vec4 new_colour : hint_color;

void fragment(){
	COLOR = texture(TEXTURE, UV);
	if(distance(COLOR, select_colour) < 0.1)
		COLOR = new_colour;

exuin | 2020-10-02 05:11

IT WORKS, thanks exuln

J u s t N a t e | 2020-10-02 05:20

Thank you it works

trollchicken | 2023-05-09 21:41