Android 2D Shader not working on some phones

Godot Version

4.3 but I also tested my shader on a new project with Godot 3.6 and GLES2 and it still has the same issue.

Question

I’m developing a small app for Android and I added a transition effect using a shader.

The shader takes an image, sets it as transparent and then using some float values interpolates the animation which consists of diamonds turning transparent or not. It’s difficult to explain so see this image, the racket and the balls are the image that makes the transition, this image is on top of everything to make the transition.

The shader is this one (i took it from the internet)

shader_type canvas_item;

uniform highp float progress_forth : hint_range(0.0, 1.0) = 0.0;
uniform highp float progress_back : hint_range(0.0, 1.0) = 0.0;
uniform highp float diamond_pixel_size = 10.0;

void fragment() {
	highp float x_fraction = fract(FRAGCOORD.x / diamond_pixel_size);
	highp float y_fraction = fract(FRAGCOORD.y / diamond_pixel_size);
	
	highp float x_distance = abs(x_fraction - 0.5);
	highp float y_distance = abs(y_fraction - 0.5);
	
	if (progress_forth < 1.0) {
		if (x_distance + y_distance + UV.x + UV.y > progress_forth * 4.0) {
			discard;
		}
	} else {
		if (x_distance + y_distance + UV.x + UV.y < progress_back * 4.0) {
			discard;
		}
	}
	
}

The game starts with this image fully transparent and i make it opaque with the progress_forth value. Once is fully opaque i make it transparent with the progress_back value.

This works perfectly on desktop and a some android phones, however, in some other android phones (in my testing all the phones with issues were using Adreno GPUs), the image is fully opaque, no transparency no matter what, so I assume the shader is not working at all or at least the transparency is not working.

Why is this happening? Can I fix it? Is there any workarounds? Is there a way that I can detect that a certain device doesn’t have the capabilities to process this shader so I can make a workaround or something?

I swear I’ve been smashing my head against the wall for 2 days with this before making the post, but after posting this and re-reading it I questioned the discard keyword and replaced it with COLOR.a = 0.0 and it seems to be working perfectly fine on the Android device I have for testing that was previously failing to render correctly.

I’ll confirm this as the solution after further testing on more devices.

Why does rubber duck debugging work so well lmao.

EDIT: I can confirm this works lmao

EDIT2: I also have a Godot Plushie that i use now for debugging xd

1 Like

Good to hear you got it fixed, just wanted to say that my rubber ducky was recently replaced with the godot plush. not the same

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.