Godot Version
4.3.stable
Question
For my project i needed to give a unique shader to each canvas item created with the Rendering server. found out that it just doesn’t work if you give it a Duplicated shader.
Code used
extends Sprite2D
@export var mat : ShaderMaterial
func _ready():
var duplicated_shader = mat.duplicate()
var player_rid = RenderingServer.canvas_item_create()
RenderingServer.canvas_item_set_parent(player_rid, get_canvas_item())
RenderingServer.canvas_item_add_texture_rect(player_rid, Rect2((-texture.get_size() * 2) / 2, texture.get_size() * 2), texture)
var xform_player = Transform2D(0, Vector2(400, 200))
RenderingServer.canvas_item_set_transform(player_rid, xform_player)
RenderingServer.canvas_item_set_material(player_rid, duplicated_shader.get_rid())
Shader code:
shader_type canvas_item;
void fragment() {
COLOR = vec4(0, 0, 1, 0.7);
}
mrcdk
November 5, 2025, 10:56am
2
EDIT:
Actually, nevermind. It’s not a bug. Explanation in this issue:
opened 01:27PM - 07 Jun 25 UTC
closed 01:51PM - 07 Jun 25 UTC
archived
discussion
documentation
### Tested versions
I managed to reproduce it both in latest stable: `v4.4.1.st… able.official [49a5bc7b6]`.
And in my project one: `v4.1.1.stable.official [bd6af8e0e]`.
### System information
Windows 10, Vulkan (Compatibility)
### Issue description
ShaderMaterial doesn't work after preload(), duplicate() and assigning it to CanvasItem using RenderingServer.
This one is annoying, sometimes it works for a new projects, for a short time, if assigned via export.
It also works when changing shader params later on with deferred call, like tween_method().
Thus, I suspect it has something to do with shader loading, compilation, etc.
Maybe material or shader doesn't have enough time to be initialized in frame, when it's assigned.
I suspect it is possibly related to: #105382
It also triggered 2 errors:
```
material_update_dependency: Parameter "material" is null.
material_get_instance_shader_parameters: Parameter "material" is null.
```
Short example:
```gdscript
extends Node2D
const mat_preload: Material = preload("res://material.tres")
func _ready() -> void:
var preload_ci_rid: RID = RenderingServer.canvas_item_create()
RenderingServer.canvas_item_set_parent(preload_ci_rid, get_canvas_item())
RenderingServer.canvas_item_set_material(preload_ci_rid, mat_preload.duplicate().get_rid())
RenderingServer.canvas_item_add_rect(preload_ci_rid, Rect2(100, 100, 100, 100), Color.RED)
```
Shader example:
```glsl
shader_type canvas_item;
void fragment() {
COLOR.a = 0.25;
}
```
You can find full example in attached MRP.
### Steps to reproduce
1. Load ShaderMaterial.
2. Duplicate.
3. Assign to CanvasItem via RenderingServer.
4. Be disappointed by lack of fancy effects.
### Minimal reproduction project (MRP)
[material_duplication_bug.zip](https://github.com/user-attachments/files/20638838/material_duplication_bug.zip)
Seems like a bug. I can reproduce it on Godot 4.5.1 with the following errors:
E 0:00:00:651 material_get_instance_shader_parameters: Parameter "material" is null.
<C++ Source> servers/rendering/renderer_rd/storage_rd/material_storage.cpp:2402 @ material_get_instance_shader_parameters()
E 0:00:00:651 material_update_dependency: Parameter "material" is null.
<C++ Source> servers/rendering/renderer_rd/storage_rd/material_storage.cpp:2414 @ material_update_dependency()
Please, open an issue in the issue tracker if there isn’t already one opened.
1 Like