issue.zip (8.9 KB)
The issue is because the whole atlas is treated as a texture and that was an assumption in the example - and in your case, using this image, it is having such free spaces - image is 192x240 px and atlas texture is 256x256 px:
To fix this, you need to pass the information to the shader, that you want to have this part of the atlas texture only, e.g. via Fragment Constant:
I adjusted the default values for the image you’re using. And you need to slightly modify the fragment program to take into account this size and position:
- Add
vec4 atlas_texel_size;inside thefs_uniformsdeclaration. - Change slightly the calculation of the size:
// Two atlas-space edges of the sprite region.
vec2 axis0 = var_texture_transform[0].xy;
vec2 axis1 = var_texture_transform[1].xy;
// Region size in atlas UV space.
vec2 atlas_size = abs(axis0) + abs(axis1);
- Change the calculation of the final UV:
vec2 repeatedUV = fract(localUV * var_repeat);
// Convert back to atlas space.
vec2 finalUV = atlas_pos + atlas_texel_size.xy * 0.5 + repeatedUV * (atlas_size - atlas_texel_size.xy);
Project: (I added git, so you can see only the commit diff):
issue_fixed_repeating_background.zip (125.6 KB)
This makes the sprite be filled with repeated texture’s images:
Btw, this shouldn’t be an issue when using similar material with model, because model accepts a single image as a texture, not an atlas. Check out this example:



