Wierd scroll shader behaviour on Android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dr_TwiSteD
:warning: Old Version Published before Godot 3 was released.

I am quite new to shaders and experiencing a strange behaviour of a simple shader wich scrolls one texture over another.

Here’s the code:

uniform float scroll_speed;
uniform texture overlay;
uniform float overlay_mix = 0.8;
uniform float overlay_texture_width = 610;

vec4 base_texture = tex(TEXTURE, UV);
vec4 overlay_texture = tex(overlay, UV + (vec2(-scroll_speed, 0) * TIME));

if (overlay_texture.a > 0) {
	overlay_texture.a *= overlay_mix;
	COLOR.rgb = mix(overlay_texture.rgb, base_texture.rgb, (1.0 - overlay_texture.a));
} else {
	COLOR.rgb = base_texture.rgb;
}

COLOR.a = base_texture.a;

On Linux desktop/laptop everything is fine, but on android the overlay image is getting pixelated over time. I suspect something is wrong with UV interpretation, because when the TIME var is being reset according to project settings, the resolution of the overlay image restores to normal and the loop starts over.

Please take a look at the video

Is this some kind of a bug or maybe something I’m not taking to account about shaders on android?

I’ve noticed the same behaviour when trying to emplement it with overlaying sprite and a region_rect using the offset. But the other thing that occured to me is that, apperantly androids float or whatever type is used to store floating point values has less precision or somthing, that over time the fault in value is increasing causing the scrolling to stutter and jump forward, meaning the built-in TIME is super platform-dependent, which is super bad.

Dr_TwiSteD | 2017-07-21 11:29

Yes, you are right. On Android (Mobile device in general ?) shaders have less precision than on other (desktop-) platforms and thus you can’t rely on the TIME variable. Another approach would be injecting a custom parameter (uniform) to the shader and modify it via a script.

timoschwarzer | 2017-07-21 12:56

You can use AnimationPlayer or Tween on an uniform that acts as a timer to get a similar output on every target.

eons | 2017-07-21 14:33

Yeah, I’ll give it a try.

Dr_TwiSteD | 2017-07-21 16:34

Tnanks guys for the replies.

Dr_TwiSteD | 2017-07-21 16:35