Shader doesn't work on Android devise.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rat_vv

Hi there. I wrote a shader for my game. It works great on pc, but when i export the project to Android it stops working.

Here is my code:

shader_type canvas_item;

float rand(vec2 co) {
    return fract(sin(mod(dot(co, vec2(12.9898, 78.233)), 3.14)) * 43758.5453);
}

float rand_range(vec2 co, float _min, float _max){
	return rand(co) * (_max - _min) + _min;
}

void fragment() {
	vec2 pos = FRAGCOORD.xy / 2.;
	float v = step(0.995, rand(floor(pos)));
	float koef = sin((TIME + pos.x + pos.y) * rand_range(pos, 0, 5.)) / 2. + 0.5;
	vec3 starcolor = vec3(v, v, v*rand_range(pos, 0.7, 0.9)) * koef;
	vec3 bgcolor = vec3(vec3(0.));
	
	vec3 color = starcolor + bgcolor;
	COLOR = vec4(color, 1);
}

adb doesn’t show eny errors.
Using godot 3.4.4, opengl 2

:bust_in_silhouette: Reply From: Calinou

For performance reasons, shader precision on mobile platforms is much lower by default compared to desktop platforms.

You’ll probably want to set the Time Rollover Secs project setting to 30 when targeting mobile devices. You can also try enabling Enable High Float.android, but this has a significant performance cost and shouldn’t be done when targeting low-end devices.

Thanks! It’s really because of small float size I guess.
I rewrite random function to use smaller values. It’s look better, thanks!

rat_vv | 2022-07-31 09:13