Page 1 of 1
[SOLVED] Distortion Shader Doesn't Work on Android Version
Posted: Sat Oct 15, 2022 10:54 am
by PotatoDude
Hello, this's my first post.
Ok, so the problem is:
I try so render a picture with distortion shader. It worked perfectly fine in the desktop version, but not in the android one. Any clue?
Re: Distortion Shader Doesn't Work on Android Version
Posted: Sat Oct 15, 2022 12:37 pm
by ReFreezed
Looks like the u coordinate is always 0 in the shader for some reason. Try returning the uv coordinates.
Code: Select all
vec4 effect(vec4 color, Image TEXTURE, vec2 uv, vec2 pc) {
return vec4(uv, 0.0, 1.0);
}
Maybe try with a different image, possibly with power-of-two dimensions.
Re: Distortion Shader Doesn't Work on Android Version
Posted: Sun Oct 16, 2022 2:53 am
by PotatoDude
Hey! Sorry for the late reply.
ReFreezed wrote: ↑Sat Oct 15, 2022 12:37 pm
Looks like the u coordinate is always 0 in the shader for some reason. Try returning the uv coordinates.
Code: Select all
vec4 effect(vec4 color, Image TEXTURE, vec2 uv, vec2 pc) {
return vec4(uv, 0.0, 1.0);
}
Yea, I just realized that in android version, it render the most left pixel only (I tried to use an image with a red dot on the mid left).
- distort desktop version
- desktop_version.jpg (40.93 KiB) Viewed 2374 times
- distort android version
- android_version.jpg (55.51 KiB) Viewed 2374 times
Unfortunately it's not the uv's problem; it's works just normal when I returning the uv coords.
- uv test android version
- android_uv.jpg (74.59 KiB) Viewed 2374 times
ReFreezed wrote: ↑Sat Oct 15, 2022 12:37 pm
Maybe try with a different image, possibly with power-of-two dimensions.
Ok, I've changed the image to 256x256 res
Re: Distortion Shader Doesn't Work on Android Version
Posted: Sun Oct 16, 2022 2:56 am
by PotatoDude
And this's the .love file. Idk but I can't add more than 3 attachments in a single post.
Re: Distortion Shader Doesn't Work on Android Version
Posted: Sun Oct 16, 2022 1:35 pm
by PotatoDude
I solved it!
The problem is rather simple tho
Based on the wiki:
On mobile devices, variables in pixel shaders use mediump (16 bit float) precision by default instead of 32 bit float, for performance reasons. This may cause numeric instability or visual artifacts for larger numbers. Use the highp qualifier when declaring a variable (for example highp float pos;) to make it use always 32 bit float precision. Furthermore, highp precision is not supported on all devices, particularly GLES2 devices. Use love.graphics.getSupported to check!
Basically in mobile device the float precision is set to mediump by default. And it's a problem since the noise generator function needs a highp precision.
https://github.com/ashima/webgl-noise/wiki
You do not need a super fast GPU to use these functions. They are useful even on low end hardware, old hardware and embedded OpenGL ES hardware with low performance. However, they require support for "highp" precision.
For ones whose facing the same problem, here's the solution:
Code: Select all
precision highp float; //on top of the file
mediump vec4 effect(mediump vec4 color, Image TEXTURE, mediump vec2 uv, mediump vec2 pc) {
// your main code here
}
The
precision highp float sets the precision to highp, but leave it alone will returns error at the love2d vec4 effect function. Set it and its arguments to mediump will solve it!
Re: [SOLVED] Distortion Shader Doesn't Work on Android Version
Posted: Sun Oct 16, 2022 2:40 pm
by ReFreezed
I feel silly now. I'm using the same noise generator code from that very repo in my current project and I remember reading about the precision requirement. D'oh.
Re: [SOLVED] Distortion Shader Doesn't Work on Android Version
Posted: Mon Oct 17, 2022 12:16 am
by PotatoDude