Is world-space repeating overlay texture possible on tilemaps in Defold?

Hello! I need some help.

I recently came across a technique in Godot where a repeated overlay texture is applied on tilemaps using a shader (based on world position). I’m trying to achieve something similar in Defold.

Is it possible to do this using a tilemap material in Defold?

Here’s the shader I’m referencing:

shader_type canvas_item;

uniform sampler2D overlay_tex: repeat_enable, filter_nearest;
uniform float scale = 0.006944444; // calculated by 1/texture size e.g. 1/144
varying vec2 world_position;

void vertex(){
    // calculate the world position for use in the fragment shader
    world_position = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
}

void fragment() {
    // only apply overlay_tex on the fully red parts of the original tiles
    float mix_amount = floor(COLOR.r);
    
    // sample the overlay_tex using world position
    vec4 overlay_color = texture(overlay_tex, world_position * scale);
    
    // combine original color and overlay color together
    COLOR = mix(COLOR, overlay_color, mix_amount);
}

Specifically, I want:

  • A repeating overlay texture across the whole tilemap (not per-tile UVs)

  • Sampling based on world position

  • Masking using tile color (like the red channel in this example)

Is this achievable in Defold’s tilemap system, or would I need a different approach?

Thanks!

tilemap.zip (603.6 KB)

I think you mean something like this with a repeating texture on a tilemap. Its a bit hacky using half the tilesource for the tiles and the other half for the repeating texture. attached an example.

4 Likes

Thank you so much! This actually became the foundation for my multi-texture blending. I used your material code and modified it to use grayscale on the top half, where the black–white intensity controls transparency. This let me achieve a very performant tilemap.

I’m using 8 textures on the bottom and 8 grayscale maps on top. Each grayscale corresponds to the texture below it—the first grayscale uses the first texture, the second uses the second, and so on up to eight.

I’ll be sharing this soon once I finish it, Inshallah, in ‘The Defoldmine’ :blush:

1 Like

tilemap.zip (883.0 KB)

I thought it was a bit hacky not being able to specify a repeating texture and having to set extrude borders to 0 so I had another go. I think this is better. All the best.

5 Likes