Shaders [Solved] Shaders behaving differently on Android

C

Cone

Guest
Hello! I made a basic shader that creates a ripple effect, and while it looks really nice on Windows, when I test things out on Android, the shader goes out the window. It works similarly, but it looks as if the shader pauses every few frames, and the effect looks a lot choppier.

I'm guessing it might be to do with the way Android converts screen coordinates and that the shader might be working off of scaled up screen coordinates, or that float precision on Android is a lot lower.

In fact, if I add a floor() function around the (rip.y * 1440.0) and (time * 0.06) in the code below, the pausing and choppiness can be replicated on Windows. Either way, I really don't want to resort to the old draw_sprite_part_ext in a for loop method, as that's horribly slower and just nastier. Is there anyone that can help me figure out a way to get this working correctly? I would appreciate it!

Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float time; // Incremented by 1 every frame;

void main()
{
  vec2 rip= v_vTexcoord;
  rip.x = rip.x + (sin((rip.y * 1440.0) + (time * 0.06)) * 0.0005);
  // rip.x = rip.x + (sin(floor(rip.y * 1440.0) + floor(time * 0.06)) * 0.0005); //It looks like this on Android!!

  gl_FragColor = texture2D(gm_BaseTexture, rip);
}
 
C

Cone

Guest
Should I have posted this in the Community Tech Support forum...?
 
I

icuurd12b42

Guest
shaders have never worked right on android, neither has 3d
 
M

Multimagyar

Guest
Reminds me of a case I had with one of my friend when I tried to use an image in the vertex shader to have a height map. It actually worked on android (or used to...) but not on PC (opengl ES,HLSL9) then Mike said the functionality is not in it and should not be necessary. I was scratching my head for weeks after that... You might have to find your own work around I guess. All I could really ask if the image you use is power of 2 but I'm not even sure if that matters in this case.
 
You could try setting the precision higher for rip.
Code:
highp vec2 rip= v_vTexcoord;
Also depending on if the texture you are drawing is scaled, android might handle that differently than Windows.
 
C

Cone

Guest
Thanks for the tip about the powers @Multimagyar - I'll make sure to consider that for any future problems. But it looks like the image size was not the problem.

@Strawbry_jam, your answer is the solution!! I was a bit skeptical at first, because there is no syntax highlighting in the shader for "highp" or anything in the manual about it... but it actually worked! And it was such a simple fix as well. This should reeeeaaaally be somewhere in the manual. Anyway, thank you very much, you saved me a lot of trouble! :D

Edit: On closer inspection, it would seem the ripple effect starts to get choppier as time goes on (the higher my time value becomes). I guess I'll have to figure out a maximum limit before resetting my time value to 0 without it interupting the animation.
 
Top