# \[Open Source\] Defold 1.12.3 CONSTANT\_TYPE\_TIME Example

**URL:** <https://forum.defold.com/t/open-source-defold-1-12-3-constant-type-time-example/82625>\
**Category:** Showcases\
**Created:** [April 9, 2026, 12:25am UTC](https://forum.defold.com/t/open-source-defold-1-12-3-constant-type-time-example/82625 "2026-04-09T00:25:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuLongZhiLu](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/julongzhilu/32/42720_2.png) [@JuLongZhiLu](https://forum.defold.com/u/JuLongZhiLu)\
**Post date:** [April 9, 2026, 12:25am UTC](https://forum.defold.com/t/open-source-defold-1-12-3-constant-type-time-example/82625/1 "2026-04-09T00:25:40Z")

</div>

> **[GitHub - JuLongZhiLu/wave\_background: Defold 1.12.3 CONSTANT\_TYPE\_TIME Example](https://github.com/JuLongZhiLu/wave_background/tree/master)**
>
> master

---

<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:** [April 9, 2026, 1:23am UTC](https://forum.defold.com/t/open-source-defold-1-12-3-constant-type-time-example/82625/2 "2026-04-09T01:23:16Z")

</div>

Great example! Here’s the translated comments in English.

```glsl
// Define the uniform block (note: the name must match the Name field in the material editor)
uniform mediump vec4 time_data; 

varying mediump vec2 var_texcoord0;

void main()
{
	// Get the time value automatically passed in by the engine
	// time_data.x is the total number of seconds since the engine started
	float t = time_data.x;

	// 1. Adjust coordinate scaling and tilt
	// Rotating or offsetting the UV coordinates can create a diagonal effect
	// We add time to both X and Y to create motion toward the lower-right corner
	mediump vec2 uv = var_texcoord0 * 8.0; 

	float speed = t * 2.0;

	// 2. Core wave algorithm
	// Use sin(x + y - t) to create a wave flowing diagonally
	// Adding sin(uv.x * 0.5) makes the wave feel distorted instead of like a rigid straight line
	float wave = sin(uv.x + uv.y - speed + sin(uv.x * 0.8 + speed * 0.5));

	// 3. Define the colors
	lowp vec3 color_bright = vec3(0.0, 0.6, 1.0); // Light blue
	lowp vec3 color_dark = vec3(0.0, 0.45, 0.9); // Dark blue

	// 4. Hard-edge split (choose the color based on whether the sin value is positive or negative)
	lowp float mask = step(0.0, wave);
	lowp vec3 final_color = mix(color_dark, color_bright, mask);

	gl_FragColor = vec4(final_color, 1.0);
}

```

Here’s a modified version with smoothing

```glsl
#version 140

uniform fs_uniforms
{
	vec4 time_data;
};

in vec2 var_texcoord0;

out vec4 color_out;

void main()
{
	// Get the time value automatically passed in by the engine
	// time_data.x is the total number of seconds since the engine started
	float t = time_data.x;

	// 1. Adjust coordinate scaling and tilt
	// Rotating or offsetting the UV coordinates can create a diagonal effect
	// We add time to both X and Y to create motion toward the lower-right corner
	vec2 uv = var_texcoord0 * 8.0; 

	float speed = t * 2.0;

	// 2. Core wave algorithm
	// Use sin(x + y - t) to create a wave flowing diagonally
	// Adding sin(uv.x * 0.5) makes the wave feel distorted instead of like a rigid straight line
	float wave = sin(uv.x + uv.y - speed + sin(uv.x * 0.8 + speed * 0.5));

	// 3. Define the colors
	vec3 color_bright = vec3(0.0, 0.6, 1.0); // Light blue
	vec3 color_dark = vec3(0.0, 0.45, 0.9); // Dark blue

	// 4. Anti-aliased color split
	// Clamp the smoothing width so the transition stays crisp while still hiding aliasing.
	float edge_width = clamp(fwidth(wave), 0.01, 0.04);
	float mask = smoothstep(-edge_width, edge_width, wave);
	vec3 final_color = mix(color_dark, color_bright, mask);

	color_out = vec4(final_color, 1.0);
}

```

---

<div class="post-metadata">

**Author:** ![JuLongZhiLu](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/julongzhilu/32/42720_2.png) [@JuLongZhiLu](https://forum.defold.com/u/JuLongZhiLu)\
**Post date:** [April 9, 2026, 2:05am UTC](https://forum.defold.com/t/open-source-defold-1-12-3-constant-type-time-example/82625/3 "2026-04-09T02:05:20Z")

</div>

> [@Pkeod](#):
>
> Here’s a modified version with smoothing

Thank you 😀 👍

---

<div class="post-metadata">

**Author:** ![JuLongZhiLu](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/julongzhilu/32/42720_2.png) [@JuLongZhiLu](https://forum.defold.com/u/JuLongZhiLu)\
**Post date:** [May 1, 2026, 1:37pm UTC](https://forum.defold.com/t/open-source-defold-1-12-3-constant-type-time-example/82625/4 "2026-05-01T13:37:11Z")

</div>

@Pkeod I added your name, but I don’t know if the name is correct.

> <https://github.com/defold/examples/pull/175>
