GUI stencil with alpha

I’m using GUI exclusively and I’ve got a texture for a button which has rounded corners, and ideally I would like the child textures to be masked.
The stencil works on the box shape, but is there a way to mask with alpha? Even if I can round the corners of the box, that would be ideal.

As far as I know, there’s no direct way. I also wish that GUI supports masking.

I wonder if there is a way to cheat this technique…? I want to animate the content on my button, and I really need to find a way to mask for the corners of the button.

You can add another node inside your button which having stencil mode, that way your content will not be overlapped outside but of course it’s not something close to your wish

Yeah, I had that thought but not really close, but you’ve given me an idea that I could draw a border to fake the mask - might be a cheap workaround. Shame there’s no other way.

After a few minutes of working with shader, I’m now able to use mask with alpha on Defold. I’m glad because with this it could help me to reduce my current project app size.

In case you still need it, you can reference at baochungit/defold-masking-example (


Fantastic! Is this for GUI?

It’s for sprites. I’m finding a way to use it for GUI. It seems GUI material ignores Fragment constants and custom samples. I will look into render stuff to see if there’s another way.

1 Like

Could you clarify what you mean by this? Afaik this is not true, but it could depend on what you are expecting to happen, and how you are using the material.

Ah yes, maybe it’s just not working as the way I’m expecting.
First is material Samplers. I added a new one but it doesn’t show in Properties panel for the node using that material. So, I guess I have to set its texture value in code?
Second is Fragment Constants. After added a new constant, how can I access to it? Using gui.set(node, name, value) not working. I guess gui.animate will not working either.

Sorry, I don’t know anything about shader coding to help with this.
Is this similar to the issue with passing constants to a GUI shader? How to set shader constants for GUI? (SOLVED) - #12 by Mathias_Westerdahl

Although it could help, I’m finding a way for doing per node, here it’s a solution per predicate (material tags). What if we have many different nodes with different constants, it’s painful…
The same for samplers…

1 Like

In my own usage I use masks sparingly, but it’s a shame there’s no simple way to achieve this.

1 Like