# GUI: Animated light effect on logo

**URL:** <https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420>\
**Category:** Questions\
**Created:** [January 13, 2025, 4:58pm UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420 "2025-01-13T16:58:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ape](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ape/32/26976_2.png) [@Ape](https://forum.defold.com/u/Ape)\
**Post date:** [January 13, 2025, 4:58pm UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/1 "2025-01-13T16:58:16Z")

</div>

In the following picture you can see two lines on the logo…

 ![logo](https://forum-defold-uploads.b-cdn.net/original/3X/3/6/36336800b8e93f344f20cdf2897643b843a2559b.png)

…that should move from left to right to imitate a light effect.

What I’ve achieved so far:

Logo (Parent)

- Box as child (one line) as stencil mask
- 
  - Logo as grandchild

The problem: If I animate the position.x of the box, the second logo (grandchild) moves also. I could probably reverse the movement by animating the logo’s position.x too but that looks overcomplicated to me. Is there an easy why to achieve that?

---

<div class="post-metadata">

**Author:** ![chemosit](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/chemosit/32/24448_2.png) [@chemosit](https://forum.defold.com/u/chemosit)\
**Post date:** [January 13, 2025, 5:05pm UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/2 "2025-01-13T17:05:03Z")

</div>

if parent is a GUI node, you can use stencil mode on it. Remove grandchild.

---

<div class="post-metadata">

**Author:** ![Ape](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ape/32/26976_2.png) [@Ape](https://forum.defold.com/u/Ape)\
**Post date:** [January 14, 2025, 1:11pm UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/3 "2025-01-14T13:11:28Z")

</div>

The problem with your approach is that the child (the box) would be cut off (stencil mask) by the parent’s box not by the parent’s non-transparent area.

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [January 14, 2025, 4:34pm UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/4 "2025-01-14T16:34:52Z")

</div>

It can be done with a shader - here’s an easy example, but with sprite:

> **[Glimmer Shader Defold by FlexYourBrain](https://flexyourbrain.itch.io/glimmer-shader-defold)**
>
> Glimmering / Highlighting shader demo

I see, if I can make something like this in GUI quickly 😉

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [January 14, 2025, 5:51pm UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/5 "2025-01-14T17:51:34Z")

</div>

Ok, first version would be something like this:

 ![Zrzut ekranu z 2025-01-14 18-30-10](https://forum-defold-uploads.b-cdn.net/original/3X/8/3/835765fd2af420b443aed1ebfb0a5760c68d07bb.png)

Fragment program for this is very simple:

```glsl
varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;

uniform lowp sampler2D texture_sampler;
uniform lowp vec4 tint;
uniform mediump vec4 stripe_data; // (x - position, y - width, z - sharpness, w - angle)

void main()
{
    lowp vec4 tex = texture2D(texture_sampler, var_texcoord0.xy);

    // Calculate the distance from the stripe center
    mediump float dist_from_stripe = abs(var_texcoord0.x - stripe_data.x);

    // Compute the stripe intensity with sharpness
    mediump float stripe = 1.0 - smoothstep(
        stripe_data.y * (1.0 - stripe_data.z), // Start of transition
        stripe_data.y, // End of transition
        dist_from_stripe
    );

    // Create the stripe effect as a highlight
    lowp vec4 highlight = vec4(1.0) * stripe;

    // Add stripe highlight to non-transparent pixels
    gl_FragColor = tex * var_color + highlight * tex.w;
}

```

Adding rotation complicates it a bit, but all you need is `rotated_coords` addition:

```glsl
    // Rotate texture coordinates
    mediump float cos_angle = cos(stripe_data.w);
    mediump float sin_angle = sin(stripe_data.w);
    mediump vec2 rotated_coords = vec2(
        var_texcoord0.x * cos_angle - var_texcoord0.y * sin_angle,
        var_texcoord0.x * sin_angle + var_texcoord0.y * cos_angle
    );

```

And use `rotated_coords` in `dist_from_stripe` instead.

You can animate it with `gui.set()` in a .gui\_script:

```lua
function init(self)
	self.box_node = gui.get_node("box")
	self.position_x = 0
end

function update(self, dt)
	self.position_x = self.position_x + 0.01
	if self.position_x > 1.5 then self.position_x = -0.5 end
	gui.set(self.box_node, "stripe_data", vmath.vector4(self.position_x, 0.2, 0.2, 0))
end

```

Effect:

Project (let it be also my entry to Defold Community Challenge 😃 ):

> **[GitHub - paweljarosz/defold\_gui\_shine\_effect: A very simple example of a GUI shader for Defold -...](https://github.com/paweljarosz/defold_gui_shine_effect)**
>
> A very simple example of a GUI shader for Defold - a shining stripe effect

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [January 14, 2025, 5:56pm UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/6 "2025-01-14T17:56:28Z")

</div>

> [@Ape](#):
>
> I could probably reverse the movement by animating the logo’s position.x too but that looks overcomplicated to me. Is there an easy why to achieve that?

And I think I made a more complicated solution actually 😅

But answering your question - yes, animating the position simultaneously in the other direction is simpler - it’s just one additional line of code in the end! 😃

---

<div class="post-metadata">

**Author:** ![Ape](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ape/32/26976_2.png) [@Ape](https://forum.defold.com/u/Ape)\
**Post date:** [January 15, 2025, 9:24am UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/7 "2025-01-15T09:24:01Z")

</div>

Well, thank you. That’s awesome.

Could I reuse this approach to add that highlight effect to fonts or are fonts handled differently?

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [January 15, 2025, 10:29am UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/8 "2025-01-15T10:29:36Z")

</div>

I think so, fonts can take custom material too 😃

---

<div class="post-metadata">

**Author:** ![Ape](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ape/32/26976_2.png) [@Ape](https://forum.defold.com/u/Ape)\
**Post date:** [January 18, 2025, 11:47am UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/9 "2025-01-18T11:47:59Z")

</div>

I just tested your code and received the following warning:

`WARNING:GAMESYS: Material /assets/shiny_material/shiny_gui.materialc has specified a fragment constant named 'tint', but it does not exist or isn't used in any of the shaders.`

You probably forgot to add the part where you can manipulate the color of the stripe 😉

Additionally it might make sense to switch to the [modern pipeline](https://defold.com/manuals/shader/#writing-modern-glsl-shaders).

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [January 19, 2025, 4:09pm UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/10 "2025-01-19T16:09:29Z")

</div>

> [@Ape](#):
>
> add the part where you can manipulate the color of the stripe

Yes, you can add this, or remove the tint constant at all if not needed 😉

> [@Ape](#):
>
> Additionally it might make sense to switch to the [modern pipeline](https://defold.com/manuals/shader/#writing-modern-glsl-shaders).

And yes, this is a better approach now 😉

---

<div class="post-metadata">

**Author:** ![Ape](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ape/32/26976_2.png) [@Ape](https://forum.defold.com/u/Ape)\
**Post date:** [January 20, 2025, 11:50am UTC](https://forum.defold.com/t/gui-animated-light-effect-on-logo/79420/11 "2025-01-20T11:50:49Z")

</div>

May I ask you to add the part where the tint can be manipulated?

As I’m unfamiliar with shaders this would probably save me some hours…and it would help all people with similar issues 😉
