[SOLVED] Distortion Shader Doesn't Work on Android Version

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
PotatoDude
Prole
Posts: 7
Joined: Wed May 04, 2022 8:01 am

[SOLVED] Distortion Shader Doesn't Work on Android Version

Post 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?
Attachments
distort.love
(23.64 KiB) Downloaded 90 times
android version
android version
distort_android.jpg (135.84 KiB) Viewed 2432 times
desktop version
desktop version
distort_desktop.jpg (135.3 KiB) Viewed 2432 times
Last edited by PotatoDude on Sun Oct 16, 2022 1:36 pm, edited 1 time in total.
nvm
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Distortion Shader Doesn't Work on Android Version

Post 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.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
PotatoDude
Prole
Posts: 7
Joined: Wed May 04, 2022 8:01 am

Re: Distortion Shader Doesn't Work on Android Version

Post 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
distort desktop version
desktop_version.jpg (40.93 KiB) Viewed 2373 times
distort android version
distort android version
android_version.jpg (55.51 KiB) Viewed 2373 times
Unfortunately it's not the uv's problem; it's works just normal when I returning the uv coords.
uv test android version
uv test android version
android_uv.jpg (74.59 KiB) Viewed 2373 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
nvm
PotatoDude
Prole
Posts: 7
Joined: Wed May 04, 2022 8:01 am

Re: Distortion Shader Doesn't Work on Android Version

Post by PotatoDude »

And this's the .love file. Idk but I can't add more than 3 attachments in a single post.
Attachments
distort2.love
(29.47 KiB) Downloaded 93 times
nvm
PotatoDude
Prole
Posts: 7
Joined: Wed May 04, 2022 8:01 am

Re: Distortion Shader Doesn't Work on Android Version

Post by PotatoDude »

I solved it!

The problem is rather simple tho :cry: :cry:
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!
nvm
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: [SOLVED] Distortion Shader Doesn't Work on Android Version

Post 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.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
PotatoDude
Prole
Posts: 7
Joined: Wed May 04, 2022 8:01 am

Re: [SOLVED] Distortion Shader Doesn't Work on Android Version

Post by PotatoDude »

:rofl: :rofl:
nvm
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests