I'm currently trying out the new shader globals in a project of mine. But I can't get it to update the value. I set up a very simple shader:
shader_type spatial;
uniform sampler2D _tex;
global uniform vec4 ccc;
void fragment() {
ALBEDO = ccc.rgb;
}
And set it up in the project settings:
I'm using this shader in a simple plane, and added a script to change the global variable as below:
extends Node3D
func _enter_tree() -> void:
print(ProjectSettings.get_setting("shader_globals/ccc"))
ProjectSettings.set_setting("shader_globals/ccc", Color.RED)
print(ProjectSettings.get_setting("shader_globals/ccc"))
But the image, nevertheless renders green, instead of red. The output from the code above is this:
--- Debugging process started ---
Godot Engine v4.0.alpha5.official.d7d528c15 - https://godotengine.org
Vulkan API 1.1.198 - Using Vulkan Device #0: AMD - AMD Radeon Pro 5300M
Registered camera OBS Virtual Camera with id 1 position 0 at index 0
Registered camera FaceTime HD Camera (Built-in) with id 2 position 0 at index 1
{type:color, value:(0, 1, 0, 1)}
(1, 0, 0, 1)
--- Debugging process stopped ---
So I tried to change the dictionary that is returned, to have the proper color:
extends Node3D
func _enter_tree() -> void:
var dict = ProjectSettings.get_setting("shader_globals/ccc")
print(dict)
dict.value = Color.RED
print(ProjectSettings.get_setting("shader_globals/ccc"))
The output looks better:
--- Debugging process started ---
Godot Engine v4.0.alpha5.official.d7d528c15 - https://godotengine.org
Vulkan API 1.1.198 - Using Vulkan Device #0: AMD - AMD Radeon Pro 5300M
Registered camera OBS Virtual Camera with id 1 position 0 at index 0
Registered camera FaceTime HD Camera (Built-in) with id 2 position 0 at index 1
{type:color, value:(0, 1, 0, 1)}
{type:color, value:(1, 0, 0, 1)}
--- Debugging process stopped ---
But it still renders green. And in the end I tried creating a new dictionary and setting it:
extends Node3D
func _enter_tree() -> void:
print(ProjectSettings.get_setting("shader_globals/ccc"))
ProjectSettings.set_setting("shader_globals/ccc", {type="color", value=Color.RED})
print(ProjectSettings.get_setting("shader_globals/ccc"))
But that doesn't work either. Anyone have any idea on how it works, or anything that I missed or could try?
Thanks in advance, Corintho