Failed to link lighting shaders on Android

I’m experimenting a weird issue with shaders on Android. Whenever I try to add a model to the scene that rely on lighting shaders the app crashes with the following exception:

07-31 13:59:32.159 8534-8553/mygame E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab043d50
07-31 13:59:32.159 8534-8553/mygame E/com.jme3.app.AndroidHarnessFragment: SEVERE Exception thrown in Thread[GLThread 155,5,main]
    com.jme3.renderer.RendererException: Shader failed to link, shader:Shader[numSources=2, numUniforms=15, shaderSources=[ShaderSource[name=Common/MatDefs/Light/Lighting.frag, defines, type=Fragment, language=GLSL100], ShaderSource[name=Common/MatDefs/Light/Lighting.vert, defines, type=Vertex, language=GLSL100]]]
    Error: uniform m_Shininess specified with different precision in different shaders.

        at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1279)
        at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1291)
        at com.jme3.material.logic.MultiPassLightingLogic.render(MultiPassLightingLogic.java:164)
        at com.jme3.material.Technique.render(Technique.java:166)
        at com.jme3.material.Material.render(Material.java:968)
        at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:616)
        at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
        at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
        at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:870)
        at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:781)
        at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1097)
        at com.jme3.renderer.RenderManager.render(RenderManager.java:1153)
        at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
        at com.jme3.app.AndroidHarnessFragment.update(AndroidHarnessFragment.java:577)
        at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:336)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1535)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

I don’t have any clue where the problem might be. If I use unshaded shaders it works just fine and with lighting ones it the application works fine on PC but not on Android. So, to resume, the app:

  • Works on PC and Android with unshaded.
  • Works on PC but not on Android with lighting.

Thanks for your help.

Mhh, I’ll look into it. Please bump this thread if I didn’t answer in a couple of days.

Actually, it seems to be an issue with emulators. Just tried it on a real device and it is working fine.

I seem to have the same issue, however it’s not really possible for me to work on a real device all the time. I kind of need emulators to test compatibility.

Using the lighting material at all causes the issue, even if you don’t set any additional parameters.

 terrainMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
terrainMaterial.setColor("Diffuse", new ColorRGBA(96f / 255, 128f / 255, 56f / 255, 1.0f));
terrainMaterial.setBoolean("UseMaterialColors", true);

results in the following output:


01/18 10:39:16: Launching app
$ adb install-multiple -r -t -p com.jayfella.motorunner D:\Programming\games\MotoRunner\app\build\outputs\apk\debug\app-debug.apk 
Split APKs installed
$ adb shell am start -n "com.jayfella.motorunner/com.jayfella.motorunner.JmeHarness" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.jayfella.motorunner | com.jayfella.motorunner.test
Waiting for application to come online: com.jayfella.motorunner | com.jayfella.motorunner.test
Connecting to com.jayfella.motorunner
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.jayfella.motorunner is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/zygote: Debugger is active
Connected to the target VM, address: 'localhost:8639', transport: 'socket'
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/chatty: uid=10079(com.jayfella.motorunner) identical 4 lines
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1414)
I/InstantRun: starting instant run server: is main process
D/AndroidHarness: Resolution from Window, width:2560, height: 1504
I/zygote: Do partial code cache collection, code=29KB, data=18KB
I/zygote: After code cache collection, code=20KB, data=15KB
I/zygote: Increasing code cache capacity to 128KB
I/com.jme3.system.JmeSystem: INFO Running on jMonkeyEngine 3.2-stable
                              * Branch: HEAD
                              * Git Hash: 95d33e6
                              * Build Date: 2018-01-05
I/com.jme3.system.android.OGLESContext: INFO Android Build Version: 27
I/zygote: Do partial code cache collection, code=60KB, data=36KB
I/zygote: After code cache collection, code=56KB, data=35KB
I/zygote: Increasing code cache capacity to 256KB
D/OpenGLRenderer: HWUI GL Pipeline

                  [ 01-18 10:39:19.930 11251:11270 D/         ]
                  HostConnection::get() New Host Connection established 0xa967ef40, tid 11270
I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0

                  [ 01-18 10:39:19.940 11251:11269 D/         ]
                  HostConnection::get() New Host Connection established 0xa96753c0, tid 11269
D/EGL_emulation: eglCreateContext: 0xa9905540: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xa9905540: ver 2 0 (tinfo 0xa99030c0)
D/EGL_emulation: eglCreateContext: 0x99d8e0e0: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0x99d8e0e0: ver 2 0 (tinfo 0xb153b380)
D/EGL_emulation: eglMakeCurrent: 0xa9905540: ver 2 0 (tinfo 0xa99030c0)
E/emuglGLESv2_enc: device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetIntegerv:749 GL error 0x500
I/com.jme3.renderer.opengl.GLRenderer: INFO OpenGL Renderer Information
                                        * Vendor: Google (ATI Technologies Inc.)
                                        * Renderer: Android Emulator OpenGL ES Translator (AMD Radeon HD 7900 Series)
                                        * OpenGL Version: OpenGL ES 2.0 (4.5.13506 Core Profile Context 23.20.15007.1005)
                                        * GLSL Version: OpenGL ES GLSL ES 1.0.17
                                        * Profile: Compatibility
W/com.jme3.asset.AssetConfig: WARNING Cannot find loader com.jme3.cursors.plugins.CursorLoader
W/com.jme3.asset.AssetConfig: WARNING Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
I/com.jme3.input.android.AndroidJoyInput: INFO loading joysticks for com.jme3.input.android.AndroidJoyInput14
I/com.jme3.input.android.AndroidJoystickJoyInput14: INFO loading Joystick devices


                                                    [ 01-18 10:39:20.263 11251:11269 D/         ]
                                                    PlayerBase::PlayerBase()

                                                    [ 01-18 10:39:20.263 11251:11269 D/         ]
                                                    TrackPlayerBase::TrackPlayerBase()
I/libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied, rates do not match 44100 Hz, require 48000 Hz
D/AudioTrack: Client defaulted notificationFrames to 708 for frameCount 2124
I/com.jme3.audio.openal.ALAudioRenderer: INFO Audio Renderer Information
                                          * Device: OpenAL Soft
                                          * Vendor: OpenAL Community
                                          * Renderer: OpenAL Soft
                                          * Version: 1.1 ALSOFT 1.16.0
                                          * Supported channels: 64
                                          * ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFTX_device_clock ALC_SOFTX_HRTF ALC_SOFT_loopback ALC_SOFTX_midi_interface ALC_SOFT_pause_device
                                          * AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_block_alignment AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length
I/com.jme3.audio.openal.ALAudioRenderer: INFO Audio effect extension version: 1.0
I/com.jme3.audio.openal.ALAudioRenderer: INFO Audio max auxiliary sends: 4
W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
W/System.err: SLF4J: Defaulting to no-operation (NOP) logger implementation
W/System.err: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
I/zygote: Do full code cache collection, code=111KB, data=77KB
I/zygote: After code cache collection, code=87KB, data=55KB
E/AndroidRuntime: FATAL EXCEPTION: GLThread 905
                  Process: com.jayfella.motorunner, PID: 11251
                  com.jme3.renderer.RendererException: Shader failed to link, shader:Shader[numSources=2, numUniforms=14, shaderSources=[ShaderSource[name=Common/MatDefs/Light/Lighting.frag, defines, type=Fragment, language=GLSL100], ShaderSource[name=Common/MatDefs/Light/Lighting.vert, defines, type=Vertex, language=GLSL100]]]
                  Error: uniform m_Shininess specified with different precision in different shaders.

                      at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1348)
                      at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1360)
                      at com.jme3.material.logic.MultiPassLightingLogic.render(MultiPassLightingLogic.java:166)
                      at com.jme3.material.Technique.render(Technique.java:166)
                      at com.jme3.material.Material.render(Material.java:974)
                      at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:614)
                      at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
                      at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
                      at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:877)
                      at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:779)
                      at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1108)
                      at com.jme3.renderer.RenderManager.render(RenderManager.java:1158)
                      at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
                      at com.jme3.app.AndroidHarness.update(AndroidHarness.java:497)
                      at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:342)
                      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1571)
                      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
E/com.jme3.app.AndroidHarness: SEVERE Exception thrown in Thread[GLThread 905,5,main]
                               com.jme3.renderer.RendererException: Shader failed to link, shader:Shader[numSources=2, numUniforms=14, shaderSources=[ShaderSource[name=Common/MatDefs/Light/Lighting.frag, defines, type=Fragment, language=GLSL100], ShaderSource[name=Common/MatDefs/Light/Lighting.vert, defines, type=Vertex, language=GLSL100]]]
                               Error: uniform m_Shininess specified with different precision in different shaders.

                                   at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1348)
                                   at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1360)
                                   at com.jme3.material.logic.MultiPassLightingLogic.render(MultiPassLightingLogic.java:166)
                                   at com.jme3.material.Technique.render(Technique.java:166)
                                   at com.jme3.material.Material.render(Material.java:974)
                                   at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:614)
                                   at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
                                   at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
                                   at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:877)
                                   at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:779)
                                   at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1108)
                                   at com.jme3.renderer.RenderManager.render(RenderManager.java:1158)
                                   at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
                                   at com.jme3.app.AndroidHarness.update(AndroidHarness.java:497)
                                   at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:342)
                                   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1571)
                                   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
W/StaticLayout: maxLineHeight should not be -1.  maxLines:2 lineCount:2
I/chatty: uid=10079(com.jayfella.motorunner) identical 3 lines
W/StaticLayout: maxLineHeight should not be -1.  maxLines:2 lineCount:2
W/StaticLayout: maxLineHeight should not be -1.  maxLines:2 lineCount:2
I/chatty: uid=10079(com.jayfella.motorunner) identical 4 lines
W/StaticLayout: maxLineHeight should not be -1.  maxLines:2 lineCount:2
D/EGL_emulation: eglMakeCurrent: 0xa9905540: ver 2 0 (tinfo 0xa99030c0)
I/chatty: uid=10079(com.jayfella.motorunner) RenderThread identical 1 line
D/EGL_emulation: eglMakeCurrent: 0xa9905540: ver 2 0 (tinfo 0xa99030c0)

Is there anything I can do to help solve this? Or maybe a short explanation of why its happening so I can do some investigating? I would really like to move on from unshaded objects.

Well, I’m not sure if you are asking me or the whole community (or maybe just to @nehon ), by my part I don’t have a clue about the subject, sorry.

I just got back to android development again after an age of idleness. I also have issues with the lighting shader but a different one (still “Shader failed to link”:
Error: uniform variables in vertex shader do not fit in 256 vectors.
I’m going to see if I can find out what is causing it.

Using the lighting shader is possible, though. I used it for the asteroids in AsteroidBeltTravelVR. That has Shininess 0.0 though.

do you use hardware skinning?

3 Likes

Yes, I should have remembered that causes issues on android (but to be honest I had forgotten it was on).

1 Like

Any progress on this issue? Or you someone explain what is the reason of the problem.

If I remember, it has something to do with detecting the capabilities incorrectly on emulators. I can’t remember how I bypassed it. I think I just changed the hardware requirements in the j3md file.

VertexShader GLSL100 GLSL150

to

VertexShader GLSL110

on both the vert and frag lines. or something like that.

Same thing happens also on real device, not on all but some. This is stack trace from one.

02-13 22:37:22.463 2667-2699/com.tech.gladiators E/com.jme3.app.AndroidHarness: SEVERE Exception thrown in Thread[GLThread 1438,5,main]
    com.jme3.renderer.RendererException: Shader failed to link, shader:Shader[numSources=2, numUniforms=22, shaderSources=[ShaderSource[name=Common/MatDefs/Light/Lighting.frag, defines, type=Fragment, language=GLSL100], ShaderSource[name=Common/MatDefs/Light/Lighting.vert, defines, type=Vertex, language=GLSL100]]]
    --From Vertex Shader:
    Error: uniform variables in vertex shader do not fit in 256 vectors.
    --From Fragment Shader:
    Error: uniform variables in vertex shader do not fit in 256 vectors.
    
        at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1348)
        at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1360)
        at com.jme3.material.logic.MultiPassLightingLogic.render(MultiPassLightingLogic.java:166)
        at com.jme3.material.Technique.render(Technique.java:166)
        at com.jme3.material.Material.render(Material.java:974)
        at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:614)
        at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
        at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
        at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:877)
        at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:779)
        at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1108)
        at com.jme3.renderer.RenderManager.render(RenderManager.java:1158)
        at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
        at com.jme3.app.AndroidHarness.update(AndroidHarness.java:497)
        at com.tech.gladiators.MainActivity.update(MainActivity.java:442)
        at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:342)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)

I m not using any material definition (well i guess not directly if engine is doing something ), just loading spatial from j3o file.

you will need to find the geometries in your model and tell them to use the material definition you modified, else they won’t use it.

Im not sure what this means, either, tbh. I’ve never seen that error before.

It means he’s using hardware skinning with too many bones, I guess. As already discussed higher up in this thread.

I have a solution to the original problem posted here. Well, a solution to the symptom…
Plus a speculative reason for the cause.

The solution is the add this to your material definition:
mat.setBoolean(“VertexLighting”, true);

Without this line, all the JME test examples using Lighting shaders that I tried crashed on Android.
mat.setBoolean(“VertexLighting”, false); //Guarantees a crash on android.

Speculative reason:
There is a series of #ifdef VERTEX_LIGHTING and #ifndef VERTEX_LIGHTING blocks of code in both Lighting.frag and Lighting.vert.
Having suffered many years of chasing ‘C’ program header bugs, the sight of complicated #ifdefs make my underpants shake. If anyone wants to debug the case when VERTEX_LIGHTING is false please do.

Speculation based on info I found on internet conversations is that Lighting.frag and Lighting.vert shader programs can choose precisions for variables based on the hardware they are running on. You would think they would choose the same precision, but maybe not?

There is the possibility of setting a hard coded precision in the shaders but that might defeat the possibility of harware optimisation. Maybe.

Anyway, I knew nothing about shaders yesterday, but now I know a little. Not enough fix the problem, just enough to cure the symptom.

I managed to get the more complicated test “jme3test.animation.TestJaime” working on my Android tablet using the above technique. (After comenting out all shadowing, which is not supported on my tablet). However it runs as a random scattering of brown triangles on the Android emulator. Not good.

To get at the material embedded in the jaime model I did this:
Geometry jaimeGeometry = (Geometry) jaime.getChild(0);
Material jaimeMaterial = jaimeGeometry.getMaterial();
jaimeMaterial.setBoolean(“VertexLighting”, true);

getChild(0) is a bit hacky, should really be a named child…
Cheers,
Tom.

Turn off hardware skinning.

1 Like

Yes, thanks, I disabled hardware skinning of jaime (below) and jaime works on my tablet.
//disable hardware skinning
SkeletonControl sc = jaime.getControl(SkeletonControl.class);
sc.setHardwareSkinningPreferred(false);

However I get the same ‘different precision’ crash in the android emulator.
Now if I do both (disable skinning AND VertexLighting=true) jaime works in the emulator!
It’s good fun this :slight_smile:

BTW. Is there any way to get shadows working on Android?
Even with hardware skinning disabled PostShadow.frag fails to compile (not supported)
Can a shadow shader be emulated? Or at some point do you have to have hardware support?
[Point me at some good reading material if I’m getting annoying]

1 Like

The Android PostShadow issue sounds like it might be this one, which is fixed in JME’s master branch but not yet in any release:

Shadows and post processor filters issues and proposals

Sorry to report I am running the master branch. I ran in debugger.
After for Lighting frag and vert seemed to work OK,

source= ShaderSource[name=Common/MatDefs/Shadow/PostShadow.frag, defines, type=Fragment, language=GLSL100]

Line 1350 was hit: insertPrecision = true;
But at line 1384 compiledOK returned false
then later,
RendererException: compile error in: ShaderSource[name=Common/MatDefs/Shadow/PostShadow.frag WARNING: 0:8: ‘GL_ARB_gpu_shader5’ : extension is not supported…

1 Like