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

**URL:** <https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398>\
**Category:** Questions\
**Created:** [March 23, 2024, 5:04pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398 "2024-03-23T17:04:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karol\_Wolonciej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/karol_wolonciej/32/35519_2.png) [@Karol\_Wolonciej](https://forum.defold.com/u/Karol_Wolonciej)\
**Post date:** [March 23, 2024, 5:04pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/1 "2024-03-23T17:04:44Z")

</div>

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

```lua
#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

---

<div class="post-metadata">

**Author:** ![Karol\_Wolonciej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/karol_wolonciej/32/35519_2.png) [@Karol\_Wolonciej](https://forum.defold.com/u/Karol_Wolonciej)\
**Post date:** [March 23, 2024, 5:06pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/2 "2024-03-23T17:06:13Z")

</div>

minimalistic version of my project  
[Mobile game minimal error.zip](https://forum.defold.com/uploads/short-url/j4Ut68B5DG8Pv6LPRuO2KAXrjB5.zip) (656.9 KB)

---

<div class="post-metadata">

**Author:** ![Karol\_Wolonciej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/karol_wolonciej/32/35519_2.png) [@Karol\_Wolonciej](https://forum.defold.com/u/Karol_Wolonciej)\
**Post date:** [March 23, 2024, 5:11pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/3 "2024-03-23T17:11:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [March 23, 2024, 8:51pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/4 "2024-03-23T20:51:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Karol\_Wolonciej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/karol_wolonciej/32/35519_2.png) [@Karol\_Wolonciej](https://forum.defold.com/u/Karol_Wolonciej)\
**Post date:** [March 23, 2024, 9:17pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/5 "2024-03-23T21:17:16Z")

</div>

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.

> **[Mobile game.zip](https://drive.google.com/file/d/1B_WbdpBoptQ-uf2WNgFg8N2Nty39qiGI/view?usp=sharing)**
>
> Google Drive file.

```
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.

```

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [March 23, 2024, 9:22pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/6 "2024-03-23T21:22:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [March 23, 2024, 9:50pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/7 "2024-03-23T21:50:06Z")

</div>

Hi @Karol_Wolonciej 😉

> [@Karol\_Wolonciej](#):
>
> I have fragment shader code like this

First of all, just to clarify, it’s a vertex program 😉 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:

> [@Shadertoy - uniform variables needs explanation (SOLVED)](https://forum.defold.com/t/shadertoy-uniform-variables-needs-explanation-solved/25559):
>
> Hi, So I’ve tried with Defold Shadertoy tutorial and it’s ok, everything is clear here for me, more or less. But when it goes to implement different shader for example [Raindrops](https://www.shadertoy.com/view/XslcWn) it’s a bit harder. I’ve managed to change resolution and time for Defold but what about other uniform variables like iChannel0? Could you please help me with this one and maybe explain more about how you deal with them in other cases? Following that, I think I will be able to overcome these warnings and understand what…

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](https://forum-defold.b-cdn.net/uploads/default/original/3X/9/5/95842390a420a59f4d8f01ca7360dbdb2261649d.png)

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

> **[Defold materials manual](https://defold.com/manuals/material/)**
>
> This manual explains how to work with materials, shader constants and samplers.

and maybe my tutorial:

> **[Shaders for Beginners](https://defold.com/2020/10/19/Shaders-for-beginners/)**
>
> In this guest post we invited Pawel Jarosz, developer of Witchcrafter - Empire Legends, to share his experience learning shader programming.

P.S.  
I’m also working on updating [Defluid](https://github.com/paweljarosz/defluid/tree/master/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 ☹ 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 😉

---

<div class="post-metadata">

**Author:** ![Karol\_Wolonciej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/karol_wolonciej/32/35519_2.png) [@Karol\_Wolonciej](https://forum.defold.com/u/Karol_Wolonciej)\
**Post date:** [March 23, 2024, 10:58pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/8 "2024-03-23T22:58:29Z")

</div>

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](https://forum-defold.b-cdn.net/uploads/default/original/3X/3/b/3b3a6e096f9762b8a99dd9e553fd1df87b27ecf4.png)

 ![Screenshot from 2024-03-23 23-46-19](https://forum-defold.b-cdn.net/uploads/default/original/3X/1/f/1f446112f003b5cf63df776b9b5daa111d2cc065.png)

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

> **[Mobile game.zip](https://drive.google.com/file/d/1iK_wA4bKo34cdtHwiaMKAS9jx9M0ODYA/view?usp=drive_link)**
>
> Google Drive file.

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.

---

<div class="post-metadata">

**Author:** ![Karol\_Wolonciej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/karol_wolonciej/32/35519_2.png) [@Karol\_Wolonciej](https://forum.defold.com/u/Karol_Wolonciej)\
**Post date:** [March 24, 2024, 1:34pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/9 "2024-03-24T13:34:01Z")

</div>

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));`

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [March 24, 2024, 8:21pm UTC](https://forum.defold.com/t/solved-using-custom-fragment-program-work-on-computer-but-give-black-screen-on-android/76398/10 "2024-03-24T20:21:10Z")

</div>

> [@Karol\_Wolonciej](#):
>
> Its subtle and was difficult to find but quite easy to fix.

Glad you managed to find it!

> [@Karol\_Wolonciej](#):
>
> In your fragment program (vertex program probably also) can’t use integer constants when float is needed

Yeah, I came across same thing some time ago 😅
