Infinite Sprite

Shader to use in a Sprite. Usefull if you want to render an infinite background.

The shader is intended for use in a Sprite. You can use the whole texture or a region. The Offset/Centered must be disabled to work properly.

If you want an infinite background tou can create a sprite that is child of the camera and update all the uniforms in the shader.

Shader code
shader_type canvas_item;

uniform vec2 position = vec2(0); // Global position of the sprite
uniform vec2 scale = vec2(1); // Scale of the sprite
uniform vec2 offset = vec2(0); // Offset in pixels

uniform bool regionEnabled = false; // Enable Sprite Region
uniform vec2 regionPosition = vec2(0); // Region Sprite Position
uniform vec2 regionSize = vec2(16); // Region Sprite Size

void fragment() {
	vec2 uv = UV + (position + offset) * TEXTURE_PIXEL_SIZE / scale;
	if (regionEnabled) {
		uv -= regionPosition * TEXTURE_PIXEL_SIZE;
		uv = mod(uv * scale, regionSize * TEXTURE_PIXEL_SIZE) + regionPosition * TEXTURE_PIXEL_SIZE;
	else {
		uv = mod(uv * scale, 1.0);
	COLOR = texture(TEXTURE, uv);
2d, background, infinite, sprite
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from christt105

Sprite Water Reflection Pixel Art Pokémon Style

Related shaders

Infinite Ground Grid

Burn Sprite

2d sprite based vfx gradient shader

Notify of

Inline Feedbacks
View all comments