Rain texture not repeating when loaded via shader

Godot Version

4.4

Question

I am having trouble getting my rain texture to repeat for the shader I am developing.

shader_type canvas_item;

uniform sampler2D rain_texture : source_color;

void fragment()
{
vec2 uv = SCREEN_UV * 3.0; // tile for visibility
COLOR = texture(rain_texture, uv);
}

I have loaded a rainy texture into rain_texture, but it rather than repeating across the whole display, things get weird.

You can see the correct rain texture in the top left.

I assumed I would need to enable texture Repeat, but in Godot 4.x, this property is accessed via the texture’s parent. So I enabled it in the ColorRect I was using.

But then I realised that it was the shader, not the rain texture, that was attached to the ColorRect. The rain texture is loaded via the shader parameter rain_texture.

So I have three related questions.

  1. Is the weird output due to the texture not repeating?
  2. Am I right in thinking that because the rain texture does not belong to the ColorRect, setting Texture → Repeat = Enabled within ColorRect won’t affect the rain texture?
  3. How do I get it so that the rain texture is shown across the whole screen, instead of these graphical artifacts?

Hi!

1/ Most likely, yes. The last row and columns of your textures are repeating endlessly, and it may be happening to be fully gray on one side due to some texture filtering stuff.

2/ Yes, at least I think so.

3/ Have you tried using repeat_enable?

uniform sampler2D rain_texture: repeat_enable;
1 Like

I have now - and it works perfectly! Thank you!

I really must get into the habit of remembering that I can still apply settings in code if it doesn’t work in the Inspector.

1 Like