OpenGL ES 3.0 and newer on android


#1

Hi all,

I’ve been working on adding support for OpenGL ES 3.0, GLSL 300 and newer to jme3. Nowadays it includes the following:

  • Initialize the proper opengl context (2.0, 3.0, 3.1…)
  • Added Caps for all of the new supported features
  • Added Instancing as core feature of GLES30 and newer
  • Properly adding versioning to shaders (#version xxx es) to shaders
  • Fixed some issues with shadow rendering in GLES 3.0 or better (strict type checking, OpenGL ES specific extensions and percision definition)
  • Added GLSL320 and GLSL300 to Unshaded and Lighting materials to be able to try all functionality
  • Added depth24 texture usage if hardware supports it
  • Enabled Geometry shaders and tessellation (3.2 core feature and 3.1 as extension)
  • Enabled glBlitFramebuffer
  • Added GLSL300 to filters not able to work with GLSL100.
  • Fixed ssao compilation issues on GLSL320 (SSAO works but has glitches in some devices)
  • Fixed precision type missmatch from vertex to fragment shader

You can find it in branch android-gl3 at my fork: https://github.com/joliver82/jmonkeyengine/tree/android-gl3

Please feel free to try it and give me feedback :wink:

I’m not creating a PR still as I don’t think it’s mature enough but at least nowadays it’s stable

I hope you like it :wink:


Shadows and post processor filters issues and proposals
#2

im not android developer, but i think a lot of them should be happy :slight_smile: i heard a lot issues related to shaders on phones.


#3

Good job, thanks :slightly_smiling_face:


#4

Thank you greatly @joliver82 for your hard work and contribution to the android side of jME.
I am a huge Android fan and have a few apps out on the play store.

I however have one question to you, what is your development cycle for android apps?
In other words how do you develop? Do you use jMonkeyPlatform, gradle or android studio?

Any feedback would be appreciated.
Thanks


#5

@joliver82 have you also tried PBRLighting in android?


#6

Sadly my development cycle for jme3 based android apps is unconfortable as hell. :confused:

As I started with really old versions of jme3 (alpha2) and my project was not defined only for android, I’m using jmonkey sdk + a slightly modified android studio project from https://github.com/noncom/jme-android-example

I have NBandroid installed and enabled android build so the mobile path is created. I used that as base for the project I linked (adding symbolic links for libraries, code, assets and so).

The cycle is like:

  • Work on the game itself in jmonkey
  • Make a full build, so although android compilation fails it generates all libs, assets and so in the destination folder used by the android studio project
  • Add android specific functionality in android studio and generate the apk

Probably there are plenty of better options, like just using the linked project or any other similar as starting point for your development but if using android studio or any other IDE you’ll loose the functionality jmonkey SDK has…

If anyone knows a better approach I’ll be happy to hear from you :wink:


#7

Not still. I’m adding stuff day by day and now I’m focused on getting shadows working 100% which is taking me more time than expected. It’s a complex topic for me :sweat_smile:


#8

Not an android developer, but hopefully this might be helpful, I was able to create my ever first android hello world app in JME easily using this Gradle template.

Edit:

After build it generates two apks, one inside debug directory an one in the release directory. The debug one can be easily installed on smartphone, but I guess the release one needs to be signed with Java Keystore which unfortunately I couldn’t figure it how.


#9

Thanks @joliver82 for sharing.

Well my approach is a bit different.
I am also using the jMonkeyEngine SDK except the difference is I actually build android using the old sdk ant build as documented in the wiki.

I have to make my own build of the SDK because in order for the NBAndroid plugin to work in the jME sdk you need version 8.1 of netbeans.

After that I also need an old version of Android SDK manager but I install the latest versions of android platform tools and sdk tools.
I use this version: https://dl.google.com/android/installer_r24.4.1-windows.exe?hl=id

Then it is a matter of setting up my custom jME SDK to point to that android sdk.

So far this works for me very good and has been for years now.

Hope it helps a bit if you want to go into that route.


#10

I can’t wait to see the shadow work you are doing.
If you want I can also test the code by creating some sample test projects for the test cases.


#11

I could have used the gradle scripts from the android studio project I used as reference instead of fully install android studio but I think for my use case it’s better to have it, specially if you develop other android apps not jme based and/or to be able to debug android apps more or less easily.

I miss the good old times when eclipse was de default IDE for android… :stuck_out_tongue:

On the other hand, it’s a good manual :wink: I would have loved to have it when I started trying to compile my app for android with multidex (that’s the reason I moved to android-studio and gradle)


#12

It’s a good aproach. I didn’t realize the issue with nbandroid was that newest jmonkey sdk is based on a newer netbeans release. Anyway, I would prefer to have NBandroid updated but it seems that the developer stoped mantaining it :frowning:

There’s a project called nbandroid-v2 (https://github.com/NBANDROIDTEAM/NBANDROID-V2) that I’ve not tried still but seems to be less stable / finished than original nbandroid was in its time. Have any of you had time to check it?


#13

Hi, hopefully you can help me with this…

I’m calling some methods of the GLES31 class (https://developer.android.com/reference/android/opengl/GLES31) but I cannot get it to compile:

       GLES31.glGetMultisamplefv(pname, index, val);
       ^
 symbol:   variable GLES31
 location: class AndroidGL

The build.gradle is the default of jme3:

if (!hasProperty('mainClass')) {
ext.mainClass = ''
}

dependencies {
    compile project(':jme3-core')
    compile project(':jme3-plugins')
    compileOnly 'android:android'
}

The "compileOnly ‘android:android’ is supposed to get the android dependencies but it’s failing for this class.

This class was included in API level 21, so maybe I should add something to the gradle file that I’m not aware of…

Thanks :wink:


#14

There are quite a few more gradle settings to configure. Not sure if you’re aware since you didn’t specify them in your post.

There’s a target and min version, etc.


#15

Thanks for your comment @jayfella but it’s the whole build.gradle file. What I’m trying to compile is the jme3-android library, not an application, so all other settings related to android are not accesible :

  • What went wrong:
    A problem occurred evaluating project ‘:jme3-android’.
    > Could not find method android() for arguments [build_akah3vddwdy7zw5ofwuoggqvr$_run_closure1@a96f79e] on project ‘:jme3-android’ of type org.gradle.api.Project.

I could try to change it from regular java to android library (apply plugin: ‘com.android.library’) and setting all stuff there but I think there should be other method.


#16

OK, I found out… it’s the library at /jmonkeyengine/lib/android.jar the one having the android classes. Just updating it to a newer version including GLES31 and GLES32 will suffice


#17

Sorry, I missed the part of your comment about properly signing the apk. I use a small shell script as follows:

cp android-studio-project/app/release/app-release.apk app.apk 
zip -d app.apk META-INF/*.RSA META-INF/*.SF META-INF/MANIFEST.MF
jarsigner -verbose -keystore ./keystore_file -storepass store_password -keypass key_password -sigalg SHA1withRSA -digestalg SHA1 app.apk key_name
rm app-align.apk
zipalign 4 app.apk app-align.apk

basically it’s removing bad signature information, sign it again and align the zip :wink:


#18

Hi there!

I’m working trying to get shadows to android gles3 but I’m facing a weird issue, depending on the device I’m getting the shadows rendered or just overriding the scene in grey:

Screenshot_20190608-015306

And I don’t understand why. The depth map is properly generated in all devices tested and I’ve simplified the rendering by creating a new material based on the unshaded.j3md but instead of using the default PostShadow.frag I’m using a simplified version that’s just rendering depth over the scene:

#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/Shadows.glsllib"

varying vec4 projCoord0;
varying vec4 projCoord1;
varying vec4 projCoord2;
varying vec4 projCoord3;
#ifndef BACKFACE_SHADOWS
    varying float nDotL;
#endif

#ifdef POINTLIGHT
    varying vec4 projCoord4;
    varying vec4 projCoord5;
    uniform vec3 m_LightPos;
    varying vec4 worldPos;
#else
    #ifndef PSSM        
        varying float lightDot;
    #endif
#endif

void main(){   

    #ifndef BACKFACE_SHADOWS
        if(nDotL > 0.0){
            discard;
        }
    #endif

            shadow = 1.0f;
            shadow = texture(m_ShadowMap0, projCoord0.xyz/projCoord0.w);

    shadow = shadow * m_ShadowIntensity + (1.0 - m_ShadowIntensity);
    gl_FragColor = vec4(shadow, shadow, shadow, 1.0);

}

Everything is defined to use GLSL300 ( #version 300 es) added to the header dynamically to the shader by new jme code I added.

I hope there’s any shader expert over here to help with this :wink:


#19

It’s been one week focused on shadows and finally I got them working rendering on both GLES2.0 and GLES3.0:

IMG_20190612_001514

I’ve tested it on all my devices with good results. It would be nice if you have time to test it and give me some feedback :wink:

Now I’m into PBR ligthing which at least the shaders compile properly now (but don’t render any effect)


#20

Great job @joliver82

I hope you have success with PBR too. :slightly_smiling_face:

btw, it is recommended to use https://imgur.com/ to upload your screenshots, then you won’t have a limit on image size.