Android Shader - w/ cube and normal maps

Anything libgdx related goes here!

Android Shader - w/ cube and normal maps

Postby snovak » Fri Jul 03, 2015 7:59 pm

Anybody have a libGDX shader for Android that renders cube maps and normal maps, along with the usual texture maps, specular maps? The test shader in libGDX source comes close, but doesn't run on Android. I guess OpenGL ES doesn't like it.
snovak
 
Posts: 32
Joined: Mon Apr 13, 2015 7:08 pm

Re: Android Shader - w/ cube and normal maps

Postby xoppa » Fri Jul 03, 2015 9:01 pm

xoppa
 
Posts: 680
Joined: Thu Aug 23, 2012 11:27 pm

Re: Android Shader - w/ cube and normal maps

Postby snovak » Sat Jul 04, 2015 12:52 pm

Hi Xoppa,

Thanks for that shader. But, sadly, it doesn't compile on android.

I get errors from my Note 4:

07-04 08:23:32.520: E/getShader(26035): Could not create shader, reverted to default shader.
07-04 08:23:32.520: E/getShader(26035): com.badlogic.gdx.utils.GdxRuntimeException: ERROR: 0:458: '(' : Syntax error: syntax error
07-04 08:23:32.520: E/getShader(26035): ERROR: 1 compilation errors. No code generated.
07-04 08:23:32.520: E/getShader(26035): ERROR: 0:215: '(' : Syntax error: syntax error
07-04 08:23:32.520: E/getShader(26035): ERROR: 1 compilation errors. No code generated.
07-04 08:23:32.520: E/getShader(26035): at com.badlogic.gdx.graphics.g3d.shaders.BaseShader.init(BaseShader.java:167)
07-04 08:23:32.520: E/getShader(26035): at com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.init(DefaultShader.java:564)
07-04 08:23:32.520: E/getShader(26035): at com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider.getShader(BaseShaderProvider.java:35)
07-04 08:23:32.520: E/getShader(26035): at us.novak.UM3DLWP.UM3DLWP$TestShaderProvider.getShader(UM3DLWP.java:247)
07-04 08:23:32.520: E/getShader(26035): at com.badlogic.gdx.graphics.g3d.ModelBatch.render(ModelBatch.java:269)
07-04 08:23:32.520: E/getShader(26035): at com.badlogic.gdx.graphics.g3d.ModelBatch.render(ModelBatch.java:280)
07-04 08:23:32.520: E/getShader(26035): at us.novak.UM3DLWP.UM3DLWP.render(UM3DLWP.java:821)
07-04 08:23:32.520: E/getShader(26035): at us.novak.UM3DLWP.android.LiveWallpaper$MyLiveWallpaperListener.render(LiveWallpaper.java:90)
07-04 08:23:32.520: E/getShader(26035): at com.badlogic.gdx.backends.android.AndroidGraphicsLiveWallpaper.onDrawFrame(AndroidGraphicsLiveWallpaper.java:221)
07-04 08:23:32.520: E/getShader(26035): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
07-04 08:23:32.520: E/getShader(26035): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

It compiles and runs fine on Desktop. But, Android is my target. I'm not sure where to start debugging GLSL on Android.

I posted about this a while ago, seems we're in the same spot: viewtopic.php?t=19197
So much for the easy way out ;-)
snovak
 
Posts: 32
Joined: Mon Apr 13, 2015 7:08 pm

Re: Android Shader - w/ cube and normal maps

Postby xoppa » Sat Jul 04, 2015 10:37 pm

Last time I checked, it worked fine for me on my Android device. But keep in mind that it's not an fully tested and supported shader. It's just a test shader I made a while ago.

If you want to fix the issue then:
Make sure that everything that uses that shader actually need that shader (e.g. dont use it for things without lights or "normal" vertex attributes etc.). If the issue still occurs then find the renderable (the smallest part of the model) that is causing the issue.

Next, call `Gdx.app.log("", DefaultShader.createPrefix(renderable, config));` with the renderable and config it is causing the issue on. Copy paste the text (a bunch of #define lines) at the top of *both* the vertex and fragment shader. Then copy those shaders into the shader debugger (it's just a simple shader profiler, you dont have to connect your phone or something) of your mobile GPU (e.g. i used adreno profiler). Ofcourse you dont have to use the debugger of your GPU vendor, but doing so will make sure that you can actually reproduce the issue in the profiler. This should allow you to conveniently find the issue and fix it.

If you found and fix it, please let me know so I can update the gist.
xoppa
 
Posts: 680
Joined: Thu Aug 23, 2012 11:27 pm

Re: Android Shader - w/ cube and normal maps

Postby snovak » Sat Jul 11, 2015 10:50 am

Hello again. I'm back on this problem today. So, I've taken your advice and installed the adreno profiler. In addition, I implemented the code from ShaderCollectionTest.java that does what you've suggegsted above. Namely:
Code: Select all

String prefix = DefaultShader.createPrefix(renderable, config);
Gdx.files.absolute(tempFolder).child(name + ".vertex.glsl").writeString(prefix + config.vertexShader, false);
Gdx.files.absolute(tempFolder).child(name + ".fragment.glsl").writeString(prefix + config.fragmentShader, false);



I installed the Adreno profiler, but I'm stuck again. I'm not exactly sure how to go about compiling the code once the vertex and fragment shaders are opened up in the profiler. Whenever I click to save snapshot I get "A shader that didn't compile correctly can't be used to compare among others."
Screen-Shot-2015-07-11-at-6.jpg
Screen-Shot-2015-07-11-at-6.jpg (8 KiB) Viewed 3769 times


Here are the files that the vertex/fragment shader code turned out....
http://pastebin.com/m0SBHaZj
http://pastebin.com/8Ns0GQM8
.... not sure if I'm missing something.
snovak
 
Posts: 32
Joined: Mon Apr 13, 2015 7:08 pm

Re: Android Shader - w/ cube and normal maps

Postby xoppa » Sat Jul 11, 2015 4:15 pm

Looks like they removed the shader editor from the profiler, that's unfortunate. I've ran it quickly through the powervr shader editor and found that it is having trouble parsing the preprocessor directives. I've slightly modified the gist (based on your pastes), to fix that compiler error. Haven't had the chance to test them though.
xoppa
 
Posts: 680
Joined: Thu Aug 23, 2012 11:27 pm

Re: Android Shader - w/ cube and normal maps

Postby snovak » Sat Jul 11, 2015 10:14 pm

We're getting errors in desktop now too. Might want to revert. I've tried Android as well just to see if there would be any difference.

Same error on both platforms:
com.badlogic.gdx.utils.GdxRuntimeException: ERROR: 0:259: '}' : syntax error: syntax error

at com.badlogic.gdx.graphics.g3d.shaders.BaseShader.init(BaseShader.java:167)
at com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.init(DefaultShader.java:564)
at com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider.getShader(BaseShaderProvider.java:35)

I'll download the tool you've suggested and take it around the block. See if I get anywhere.
snovak
 
Posts: 32
Joined: Mon Apr 13, 2015 7:08 pm

Re: Android Shader - w/ cube and normal maps

Postby snovak » Sun Jul 12, 2015 12:34 pm

I think I found a tool that might be of use. Since WebGL essentially uses OpenGL ES 2.0, we might be able to use this chrome plugin. https://chrome.google.com/webstore/deta ... bgdlbbbpob to debug. This tool was updated to work with libGDX HTML export in the latest version! https://github.com/spite/ShaderEditorExtension/issues/7

You can test with the libGDX demos. http://libgdx.badlogicgames.com/demos

I took a screenshot. It tints the highlighted program on the screen.. Pretty cool. Anyway, it enables farting around with the GLSL code interactively recompiling when you change the text. I'll try to use this to figure out the problem with the test shader. Wish me luck. :?
Screen-Shot-2015-07-12-at-8.jpg
Screen-Shot-2015-07-12-at-8.jpg (48.5 KiB) Viewed 3712 times
snovak
 
Posts: 32
Joined: Mon Apr 13, 2015 7:08 pm

Re: Android Shader - w/ cube and normal maps

Postby snovak » Fri Jul 24, 2015 11:43 am

I think I solved this.

I got my device working on the Adreno profiler so I could compile the code on the actual mobile GPU, in order to accurately reproduce the error.

And, I'm slowly realizing why the line numbers debugging GLSL mean absolutely squat. I think, for one, the compiler disregards all commented lines, and doesn't count them out when it throws the error. Secondly, the compiler doesn't backtrace the function calls. It only reports where in the main function the application fails. And last but not least, the problem in the test shader seems to stem from nested function calls, or function recursion of some sort. I'm referencing, https://www.opengl.org/discussion_board ... s-aborting!

If I replace (below) at the very end of the vertex shader
Code: Select all
pushColor();
pushTexCoord0();


with it's function contents....

Code: Select all
pushColorValue(g_color);
pushTexCoord0Value(g_texCoord0);


that "seems" to solve that portion of the problem..... Though, as that indicates, I still don't have a working shader because fixing one issue results in more errors throughout the fragment shader as well.

What I've started to do is modify the default shader, which is much less troublesome so far. I've got environment reflections working nicely.
Is there a reason env reflections aren't included in the default shader? Otherwise, I'd be happy to help put it there. Right now my code is in a single glsl file , not in the more modular code that is in source.
snovak
 
Posts: 32
Joined: Mon Apr 13, 2015 7:08 pm

Re: Android Shader - w/ cube and normal maps

Postby snovak » Thu Jul 30, 2015 5:07 pm

Okay. I'm back on the shader. I've been avoiding it... Can you tell?

I've got this working! The test shader now fully compiles and runs on Android.

But! (It seems like there's always a BUT) there is some unusual behavior that I'm hoping someone can steer me in the right direction.

This shader runs on some, but not all of my devices. Unusual as it might seem, it's the newest of the devices that is having the issue.

Renders as expected on:
    Samsung Note 8.0 (GPU: ARM Mali-400MP4 )
    HTC One (GPU: Qualcomm Adreno 320)

Render fails, black screen on:
    Samsung Note 4 (GPU: Adreno 420)

I suspect that the separation is GPU related. The NEWEST of all the devices renders a completely black screen. Hooking it up to the Adreno profiler app, I CAN SEE THE BUFFER AS IT SHOULD BE. But, on the device, it's not rendering, just a black screen. No error from program anywhere, just happily rendering a screen full of black pixels. Weird.

Just looking at specs on Wikipedia (https://en.wikipedia.org/wiki/Adreno)
The Adreno 320 (OpenGL ES 3.0) renders fine, when the Adreno 420 (OpenGL ES 3.1) does not. Furthermore, the Mali-400MP (OpenGL ES 2.0), also renders the scene.

I've tried to add the #version 100 specification, locking it in to OpenGL ES 2.0 (ref https://www.khronos.org/opengles/sdk/to ... -Compiler/)
BUT, I'm returned an error : GLSL line 16: Error: #version must occur before any other statement in the program
....which I suspect is because of the #define statements that are added to the program before getting compiled. I suppose, just to test, I could recompile and push the shader to the device with the profiler.

Anyway, I'll go ahead and provide the shader as I have it working now. calculateTangentVectors was offering a similar issue that I'll need to still work out. Though, seems to be shading correctly. Normal and cubemap reflections seems to be working.

Oh! that brings up something else. I think the normalmap calculations for reflections needs to be reversed somewhere. I'm SURE this is a bug, so maybe I'll take this one up on github.

Vertex Shader: http://pastebin.com/WdWXY64n
Fragment Shader: http://pastebin.com/h6e8X6eB
snovak
 
Posts: 32
Joined: Mon Apr 13, 2015 7:08 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 7 guests