# Wrapping GUI textures

**URL:** <https://forum.defold.com/t/wrapping-gui-textures/67969>\
**Category:** Questions\
**Created:** [March 30, 2021, 3:50pm UTC](https://forum.defold.com/t/wrapping-gui-textures/67969 "2021-03-30T15:50:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [March 30, 2021, 3:50pm UTC](https://forum.defold.com/t/wrapping-gui-textures/67969/1 "2021-03-30T15:50:57Z")

</div>

I found an old thread discussing this here, but it’s a bit too complicated for me to understand: [Tiling gui textures possible?](https://forum.defold.com/t/tiling-gui-textures-possible/293)

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:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/6/3/6380bbe113226273e76ee50868b4c1b431445fb2.png)

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!

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [March 30, 2021, 6:12pm UTC](https://forum.defold.com/t/wrapping-gui-textures/67969/2 "2021-03-30T18:12:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [March 31, 2021, 8:40am UTC](https://forum.defold.com/t/wrapping-gui-textures/67969/3 "2021-03-31T08:40:26Z")

</div>

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

[https://github.com/defold/defold/issues/5706](https://github.com/defold/defold/issues/5706)

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? 👼
