Tiling gui textures possible?

I would like to have my textures to tile instead of stretch when I make my gui-nodes bigger, is this possible?

This is something I am used to being as simple as a checkbox setting in other engines or frameworks but I can’t find any way of doing this in Defold.

The use cases are many, from creating a tiling backgrounds for dialogue-boxes to making beams of variable length tiling in one direction only.

2 Likes

That should be possible with a new custom material and shader that you assign to the gui scene.

2 Likes

Please note that this requires that you use an atlas with a single image in it and that the image has power of two dimensions. Otherwise the resulting texture would be larger than your image, and you would sample outside it when modifying the UVs. You could of course hard code some values to counter this, but that’s a bit messy.

We should add better support for doing dynamic texturing.

5 Likes

Alright. Been mucking around a bit with a custom shader, but multiplying the texcoordinates there gives me a clamped result when uv-value is > 1. Not sure I got the atlas thing right, but I tried using an atlas with a single image in it that is 64x64 in size, and it gave me the same result.

Is the default setting for texture wrap in Defold set to Clamp? If so, is there any way for me to set it to Repeat?

Yes, you set it when creating a new render target. See http://www.defold.com/ref/render#render.render_target

You can specify it as a parameter if you create a render target (render.render_target), but not sure that is the best way to achieve what you want

Also, if you have custom material you can set wrapping modes per sampler;

1 Like

Thanks for the replies!
I think setting it in my material is the easiest and most appropriate way to do it in this case. I’ll experiment some more later tonight.

1 Like

Ok, so making a tiling texture sampler in my material worked perfectly, but now I need to tell the shader how much to scale the uv’s, since the uv scale is dependent on how large my gui-box-node is during the current frame. There doesn’t seem to be any gui.set_constant, so I’m wondering if you guys have any ideas on how to make this happen.

What I am trying to do is a beam that grows out from the avatar, and I want the texture to be the same “resolution” from start to finish.

I thought long and hard how to solve this as awkward and complicated as possible and I think I have an idea!

  1. Put a specific tag on the material, e.g. “gui_beam”
  2. Send off the box-size-factor from the gui-script to the render-script, msg.post("@render:", “beam”, …)
  3. Draw the “gui_beam” tag using a separate predicate and supply the factor as shader constants!

The big flaw with this is that it sort of hard-codes the amount of beams, at least you need to count or address them on a global scope (since the constants are set in the global render-script).

Some links to achieve it:

2 Likes

In other words, I think we need a new feature here! I’m thinking of something along the lines of letting a gui-node tile its texture (new option), which would create dynamic mesh geometry to counter for the texture coming from an arbitrary atlas. It also needs to account for a uv-offset which should be controllable like the other gui-properties (possible to animate them etc). Is that sort of what you are looking for?

3 Likes

That sounds perfect for what I am trying to do now and for any sort of dialogue-box tiling backgrounds, frames of variable width/height etc. I agree, and I’m thinking that the options for this would be something like uv-offset (x&y) and uv-scale (x&y). Animatable uv-offset sounds super-useful!:smiley:

For the specific case with the beams that I’m working on now, and with the current feature set, I’m thinking it might be best to use a gameobject for each beam, containing a sprite that is scaled through go.set(). It seems a bit messier (I really like working with the gui-system and the animation of nodes etc. because it’s so awesomely flexible and easy to use) but it might be the best solution right now.

2 Likes

will be really great. want to add some noise cheaply to my gui and faced the same issue.