(SOLVED) Using custom fragment program work on computer but give black screen on android

Hello Defold community it’s my first questions. I am developing mobile logic game for android and everything was fine until I tried custom render pipeline and new shaders for some effects. Unfortunately I was unable to debug even with help of chatgpt4 so I have to ask for help. I have fragment shader code like this

#version 100

// positions are in world space
attribute vec4 position;
attribute vec2 texcoord0;

uniform mat4 mtx_view;
uniform mat4 mtx_proj;

varying vec4 var_position;
varying vec2 var_texcoord0;

varying vec2 vPosition;

void main()
{
    vec4 p = mtx_view * vec4(position.xyz, 1.0);
    var_position = p;
    var_texcoord0 = texcoord0;
    vPosition = position.xy;
    gl_Position = mtx_proj * p;
}

and I get following errors when I click build (defold version 1.7.0)

INFO:GRAPHICS: Installed graphics device 'ADAPTER_FAMILY_OPENGL'
INFO:ENGINE: Defold Engine 1.7.0 (bf4dc66)
INFO:DLIB: Initialized Remotery (ws://127.0.0.1:17815/rmt)
INFO:ENGINE: Loading data from: build/default
INFO:ENGINE: Initialised sound device 'default'
ERROR:GRAPHICS: Unable to compile fragment shader.
ERROR:GRAPHICS: 0:13(1): error: `out' qualifier in declaration of `_DMENGINE_GENERATED_gl_FragColor_0' only valid for function parameters in GLSL ES 1.00
0:13(1): error: No precision specified in this scope for type `vec4'
0:18(1): error: `in' qualifier in declaration of `var_texcoord0' only valid for function parameters in GLSL ES 1.00
0:27(39): error: no function with name 'texture'
0:27(39): error: operands to arithmetic operators must be numeric

WARNING:RESOURCE: Unable to create resource: /_generated_a9c6254a.fpc: FORMAT_ERROR
WARNING:RESOURCE: Unable to create resource: /assets/advancedEffects/defluid/defluid/metaball.materialc: FORMAT_ERROR
WARNING:RESOURCE: Unable to create resource: /_generated_cd621834.spritec: FORMAT_ERROR
WARNING:RESOURCE: Unable to create resource: /assets/advancedEffects/defluid/defluid/particle.goc: FORMAT_ERROR
double free or corruption (fasttop)
INFO:CRASH: Successfully wrote Crashdump to file: /home/karol/.Defold/_crash
ERROR:CRASH: CALL STACK:

ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x6c7305]
ERROR:CRASH: /lib/x86_64-linux-gnu/libpthread.so.0(+0x14420) [0x7f7dc8d78420]
ERROR:CRASH: /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcb) [0x7f7dc851b00b]
ERROR:CRASH: /lib/x86_64-linux-gnu/libc.so.6(abort+0x12b) [0x7f7dc84fa859]
ERROR:CRASH: /lib/x86_64-linux-gnu/libc.so.6(+0x8d26e) [0x7f7dc856526e]
ERROR:CRASH: /lib/x86_64-linux-gnu/libc.so.6(+0x952fc) [0x7f7dc856d2fc]
ERROR:CRASH: /lib/x86_64-linux-gnu/libc.so.6(+0x96c65) [0x7f7dc856ec65]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x471079]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x443d03]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x4442f8]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x436922]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x436598]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x443d03]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x4442f8]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x435c2a]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x435800]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x443d03]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x4442f8]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x4551eb]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x426de1]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x638566]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x42786b]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x425d41]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x417d5b]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x418dd3]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x415111]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x415085]
ERROR:CRASH: /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f7dc84fc083]
ERROR:CRASH: /home/karol/.Defold/unpack/9ad2d7834a6adfaedcd902a8e6f9997ed5cbb507/x86_64-linux/bin/dmengine() [0x414ece]
ERROR:CRASH: 

It started when I added #version 100 at the top. Before it was working fine on linux ubuntu LTS 20 fine but unfortunately got black screen on android redmi 9 so I triend made shader proper for android device (I do it first time and this line was hinted by chat gpt4)

I added in total two custom fp and two vs. I upload more minimalistic version of my project you can find scripts related to shaders in assets/advancedEffects/defluid/defluid/ which are files like render_target.vp/fp and metaball.vp/fb and their materials. My need is to make shaders work on android smartphones. Thank you in advance

1 Like

minimalistic version of my project
Mobile game minimal error.zip (656.9 KB)

I can’t delete and create it again so I will post here a bit more information. After adding #version 100 I triend make rest of the shader script valid for this version. I can’t see in any of my new shader scripts in or out qualifiers. I also don’t think I am using texture() instead of texture2D() yet compiler is interpreting this in this manner

You should remove the version string, the shader pipeline will (should) do all the work for you.

1 Like

unfortunately this works currently on linux in editor but give black screen on android redmi 9. I tried logcat but I am only getting this. It was working fine before on computer but never on smartphone android and thats why I tried to put this version string line. I upload current state of project just in case. Thank you for help.

adb logcat | grep defold
03-23 22:09:15.070  7258  7336 E defold.sound: App is missing the READ_PHONE_STATE permission. Audio will continue while phone call is active.
03-23 22:09:51.470  7966  7991 E defold.sound: App is missing the READ_PHONE_STATE permission. Audio will continue while phone call is active.

Yeah I think you will have to look into logcat around that timestamp to see if there are any other error strings or crashes, it’s a bit hard to say what could be wrong. Perhaps start commenting out bits of the code until it works?

Hi @Karol_Wolonciej :wink:

First of all, just to clarify, it’s a vertex program :wink: And there isn’t much issue in here, it’s the rest of the project. There are several issues in the repro. It is not building on Windows.

One issue is regarding not existing functions, like texture() - there is texture2D(), you might want to use. And not existing/defined uniforms, e.g. texture(iChannel0, reflect_direction) - this is common, when using code from Shadertoy, because it defines different names, check out my issues here:

In rest of the materials, many times materials have incorrectly defined constants or samplers, like for example empty string used for sampler name here:

image

Check out the manual first: (sadly, it’s the one I didn’t translate to Polish yet :frowning: )

and maybe my tutorial:

P.S.
I’m also working on updating Defluid example slowly, sadly very slowly, so if you want to rely on me here, you have to be patient, as I have really tight schedule already :frowning: It can be done way better now with all the new features in Defold, especially custom vertex attributes.

Explain to me or us here the final effect you want to achieve and we’ll try to help :wink:

2 Likes

ok, so here is working effect in editor (image). Everything is working without errors on linux (windows dont build because icons are not set, I tried set some fast but wasnt enough to fix). I have read tutorial on shaders and shader toy and did a few working shaders (on laptop). Here on image you can see simple water drops that act like magnifying glass distorting parts of image. I am not using undeclared variables in fp or vp. (I added texture_sample to metaball.material only). I understand what is happening in render pipeline (I have custom script to manage many tags and shaders). So its work fine on computer and I couldtn find ary error in android logs. The only problem is on both my android smartphones samsung and redmi 9 my application have black screen. Here is screen of setup with model with material which vp and fp combine every texture together. The problem may be very subtle making final texture not visible on phone. Maybe there is something wrong with the model (on screen) because it is use to draw combined (I have multiple render targets in render script) textures.

Screenshot from 2024-03-23 23-56-04

here is working project in editor (windows dont build because couldt set icons fast, I use linux)

I started with defluid project and his shader scripts and modify but the project itself dont render water on phone android but everething else is visible.

2 Likes

I finally found a solution. Its subtle and was difficult to find but quite easy to fix.
In your fragment program (vertex program probably also) can’t use integer constants when float is needed for example:
you can’t do this
float grid_size = 20;
you have to change to
float grid_size = 20.0;

also can’t do this
vec2 mouse_uv = vec2(uv0.x + (metaball.r/255), uv0.y + (metaball.g/255));
you have to change to
vec2 mouse_uv = vec2(uv0.x + (metaball.r/255.0), uv0.y + (metaball.g/255.0));

1 Like

Glad you managed to find it!

Yeah, I came across same thing some time ago :sweat_smile:

1 Like