Weird image tearing with this shader

Godot Version

v4.3

Question

Why are these images tearing with this code?

I have a very simple shader:

shader_type spatial;
uniform sampler2D[2] images : source_color;

void fragment() {
	ALBEDO = texture(images[int(step(0.5, UV.x))], UV).rgb;
}

But it’s tearing very oddly:

I expected a clean edge in the middle between the two images.

To recreate this, i just created a new Godot project and then:
Created a new 3D scene
Added a MeshInstance3D
Set the mesh as a new PlaneMesh
Set the material as a new ShaderMaterial and added a new shader
Copied the code above into the shader
Clicked on the only shader parameter
Clicked “add element” twice
Set the two images as icon.svg and any other image
You should be seeing the issue now

Bonus question: (solved)
How do i put code in one of these posts the correct way?

Thanks for taking the time to read!

Edit: solved it by adding a bunch of if statements checking for each index and returning the colour of that index, but I imagine this is mighty inefficient, so still looking for a better solution.

you can type in monospace by surrounding text in triple tildes ```like this```
1 Like

Thanks! Edited this post to use this and will use in future posts!

This looks like a bug. Could you open an issue on github?

1 Like

Absolutely! Here it is: Tearing when using UV to access an array of sampler2d's · Issue #98288 · godotengine/godot · GitHub
I’ll mark your reply as the solution, since this topic doesn’t belong here anymore.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.