I wrote a simple shadertoy-like component in Godot 4.3, but after upgrading to 4.4, I found that this component no longer works as expected. The main issue is that in 4.3, I could modify TextureRect.material.shader.code to dynamically change the shader effect in real time. However, after upgrading to 4.4, this line of code no longer works properly.

I suspect this might be due to the introduction of the Ubershader feature in 4.4, but I don’t know much about Ubershader. So, I would like to know how to modify shader code in real time in Godot 4.4?

Only ShaderMaterial and Shader generated at runtime have issues, using existing ShaderMaterial resources is ok.

I got around this problem by modifying the following code. But, I don't know why.

# original code. can not update shader correctly.
# canvas.material = ShaderMaterial.new()
# canvas.material.shader = Shader.new()

# works properly.
canvas.material = canvas.material.duplicate(true)

# update shader code
canvas.material.shader.code = ShaderPreviewer.DEFAULT_SHADER_CODE