Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Iftah |
I’m trying to draw a map using sprites simple map tiles | OpenGameArt.org
the background is a parchment image, and on top of it different sprites of hills, volcanos, mountains, etc… are drawn. The sprites are semi transparent (ie. pixels have fractional alpha values) in a way that makes it look like a drawing on the parchment.
My problem is that if I want to draw two sprites that overlap, eg. a small hill “in front” of a big volcano, because the hill is semi transparent, you can see the lines of the volcano behind it.
eg
I tried applying a shader to the sprites, where the shader returns the image as-is except using blend_disabled mode, but it made no difference - why?
is there another solution?
ie. the shader I applied to the sprites (didn’t fix the problem):
shader_type canvas_item;
render_mode blend_disabled;
void fragment() {
vec4 col = texture(TEXTURE, UV);
COLOR = col;
}
edit: while waiting for my question to be approved, I solved the problem myself
I still don’t know why “blend_disabled” isn’t disabling blend.
for those interested - this is my solution:
shader_type canvas_item;
void fragment() {
vec4 sprite = texture(TEXTURE, UV);
vec4 background = texture(SCREEN_TEXTURE, SCREEN_UV);
vec4 mixed = mix(background, sprite, sprite.a);
mixed.a = 1.0;
COLOR = mixed;
}