Wrapping GUI textures

I found an old thread discussing this here, but it’s a bit too complicated for me to understand: Tiling gui textures possible?

From another thread, I have figured out how to tile a sprite. However, I want to do it in gui so I can use dynamically loaded textures.

For reference, here is the material for the sprite:

I set up my gui material to be more or less the same, except it has the builtin gui.vp.

The sprite .fp:

varying mediump vec2 var_texcoord0;

uniform lowp sampler2D texture_sampler;
uniform lowp vec4 tint;
uniform lowp vec4 scale;

void main()
{
    // Pre-multiply alpha since all runtime textures already are
    lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
    lowp vec2 uv = vec2(var_texcoord0.x * scale.x, var_texcoord0.y * scale.y);
    gl_FragColor = texture2D(texture_sampler, uv.xy) * tint_pm;
}

I tried to modify gui.fp accordingly. My best attempt was this:

varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;
uniform lowp vec4 scale;

uniform lowp sampler2D texture_sampler;

void main()
{
    lowp vec2 uv = vec2(var_texcoord0.x * scale.x, var_texcoord0.y * scale.y);
    lowp vec4 tex = texture2D(texture_sampler, uv.xy);
    gl_FragColor = tex * var_color;
}

This doesn’t work - the texture just goes smooth, as if it’s become the average of all the colours.

Any ideas? Thank you!

A builtin tiling texture node for GUI would be really useful.

2 Likes

Agreed. I’ve added an issue about it, please updoot if you are interested in it:

Also let me know if my description is wrong/insufficient and I’ll happily edit it.

In the meantime, since I don’t expect this to be added in a hurry, does anyone have any insight into how to achieve this using a custom material/fp? :angel:

1 Like