Shader, sampler2D updates doesnt work

Godot Version

v4.2.1.stable.official [b09f793f5]


Hello. I have a problem with updating uniform sampler2D shader in godot. What im doing, Im drawing Image pixels, in print() section I see that image been updated, but visual doesnt update. What could be the problem? My function for updating sampler2D:

mask_texture.set_pixel(x, y, Color.BLACK)
print("UPDATE: ", mask_texture.get_data())  # this print changes of image
material.set_shader_parameter("mask_tex", mask_texture)  # but it doesnt update  

Fragment shader:

float mask = texture(mask_tex, UV).r - 0.5;
mask = smoothstep(blend_amount, blend_amount + 0.1, mask);
ALBEDO = mix(base_albedo, blend_albedo, mask);

Is your mask_texture of type Image? No, you should be using the ImageTexture type. Use ImageTexture.create_from_image(image) to convert the type.

1 Like

I’ve encountered a similar predicament where set_shader_parameter fails to throw an error for incorrect parameter types, costing me an entire afternoon to track down the issue`(>﹏<)′

I tried to use Image to ImageTexture conversion and still have no result. Idk why

Check your shader code. As a debugging step, try commenting out other parts of the shader and focus solely on observing whether the Mask is functioning correctly.

Shader was fine. It works fine after adjustments. Thanks for helping