mgsx-dev / gdx-gltf Goto Github PK
View Code? Open in Web Editor NEWGLTF 2.0 3D format support and PBR shader implementation for LibGDX
License: Apache License 2.0
GLTF 2.0 3D format support and PBR shader implementation for LibGDX
License: Apache License 2.0
for now, users have to generate their own IBL cubemaps or use provided one from demo module.
That's not convenient for new users to have something working out of the box.
There are several ways to address it :
I don't know why GLSL does this, but it doesn't define atan2() in GLSL ES (see Shaderific for reference), and instead just uses atan(). This causes IBL Composer to fail on some machines, it seems; Discord user Jaaf showed this shader compilation error which seems directly related to atan2().
You can also just look at the syntax highlighting for asin()
vs. atan2()
in https://github.com/mgsx-dev/gdx-gltf/blob/master/ibl-composer/src/net/mgsx/gltf/shaders/cubemap-make.fs.glsl#L26 ; atan2 isn't highlighted but asin is. Some vendors may define atan2() in addition to atan() with two arguments, but I don't think it's ever standard.
Not a big deal, but in the latest version of gdx-gltf, SceneManager does not provide ShaderProvider-only constructor:
new SceneManager(new DefaultShaderProvider());
GLTF exporter plugin interface changed a lot, documentation should be updated.
When opening a file that is not supported, the Composer app will crash.
We had this case on Discord where someone wanted to open an EXR file from hdri haven.
While this generally is only a minor point it can confuse beginners. The app should tell the user "hey the file you want to open is not supported, only .hdr files are", something like that.
Good afternoon, I get the following error:
com.badlogic.gdx.utils.GdxRuntimeException: Shader compilation failed:
--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 net.mgsx.gltf.scene3d.shaders.PBRShaderProvider.createShader(PBRShaderProvider.java:295)
at com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider.getShader(BaseShaderProvider.java:34)
at com.badlogic.gdx.graphics.g3d.ModelBatch.render(ModelBatch.java:262)
at net.mgsx.gltf.scene3d.scene.SceneManager.renderColors(SceneManager.java:149)
at net.mgsx.gltf.scene3d.scene.SceneManager.render(SceneManager.java:116)
at com.proof.gltf.GLTFLoader.render(GLTFLoader.java:352)
at com.badlogic.gdx.backends.android.AndroidGraphicsLiveWallpaper.onDrawFrame(AndroidGraphicsLiveWallpaper.java:220)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
The UI scale is too small on HiDPI screens.
If I'm not missing something there's no manual way to change it, so it would be nice to have it scale automatically based on the systems scale setting or at least being able to set it manually.
(Windows)
Others have solved it if you want to take a look (Not the best solutions but easy to implement):
HI,
Facing issue in both (.glb) and (gltf) file.
2019-02-28 15:33:44.156 31927-32093/net.mgsx.gltf.demo E/AndroidRuntime: FATAL EXCEPTION: GLThread 102412
Process: net.mgsx.gltf.demo, PID: 31927
com.badlogic.gdx.utils.GdxRuntimeException: Fragment shader:
WARNING: 0:3: extension 'GL_EXT_shader_texture_lod' is not supported
ERROR: 0:313: 'textureCubeLodEXT' : no matching overloaded function found
ERROR: 0:313: 'SRGBtoLINEAR' : no matching overloaded function found
ERROR: 0:313: 'rgb' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:313: '=' : cannot convert from 'const float' to '3-component vector of float'
ERROR: 4 compilation errors. No code generated.
at com.badlogic.gdx.graphics.g3d.shaders.BaseShader.init(BaseShader.java:167)
at net.mgsx.gltf.scene3d.shaders.PBRShader.init(PBRShader.java:265)
at com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.init(DefaultShader.java:595)
at com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider.getShader(BaseShaderProvider.java:35)
at com.badlogic.gdx.graphics.g3d.ModelBatch.render(ModelBatch.java:263)
at net.mgsx.gltf.scene3d.scene.SceneManager.render(SceneManager.java:85)
at net.mgsx.gltf.demo.GLTFDemo.render(GLTFDemo.java:530)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:495)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1571)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
2019-02-28 15:33:48.205 31927-31927/net.mgsx.gltf.demo E/AndroidGraphics: waiting for pause synchronization took too long; assuming deadlock and killing
not an issue with the library itself, it handles all sampler configurations including mipmaps and then auto mipmap generation.
The issue come from blender and blender GLTF exporter which don't have options for mipmaps.
For these use cases, it could be nice to allow user code to force/override it at loading time.
It could be a loader option which would be global for all models loaded with this loader. This way, users could load some models with or without this option in order to have fine grain control.
Error running Web demo in chrome android :
Uncaught Error: java.lang.RuntimeException: com.badlogic.gdx.utils.GdxRuntimeException:
Fragment shader:
WARNING: 0:33: 'GL_OES_standard_derivatives' : extension is not supported
ERROR: 0:44: 'highp' : precision is not supported in fragment shader
[.WebGL-0x62001db8]GL ERROR :GL_INVALID_ENUM : glGetIntegerv: pname was GL_MAX_SAMPLES_ANGLE
[.WebGL-0x62001db8]GL ERROR :GL_INVALID_ENUM : glTexParameterf: pname was GL_TEXTURE_MAG_FILTER
Hello everyone.
I've heard on Discord there is a export feature in the works, just wish to be sure about what is this about.
So, can I use this library to export gltf files made from inside LibGDX?
Thanks in advance for any help.
Bye, Ivano.
Current PBR shader is a bit greedy, the idea is to provide alternatives for lower quality requirements / lowend devices.
This way, users could still use GLTF workflow and features with some options for rendering quality.
Also, i could be nice to document how to let users provide their own shaders.
Options:
About SpecularGlossiness, GLTF has an extension for that but it's not supported by Blender GLTF exporter. So for now it's required to add this kind of textures at runtime (adding material attributes).
Specular texture attribute should be supported in all 3 shader alternatives.
I've struggled with getting a procedural model to render correctly. I am building a simple heightmap which displays correctly in the default pipeline; however, after modifying the materials when adding it to a scene it renders black.
I have several models in the same scene rendering on the same SceneManager render call with the same lights. Is there a particular texture that must be present for lighting to work correctly? I just want to make sure I am not spinning my wheels in the wrong area.
Hi,
Going through the library I have used the GLTFQuickStartExample class as a example to load a simple gltf model. But running the app results in a crash with error
2021-01-16 16:14:13.402 30170-30205/com.example.maxst3demo E/AndroidRuntime: FATAL EXCEPTION: GLThread 3491 Process: com.example.maxst3demo, PID: 30170 java.lang.NullPointerException: Attempt to invoke interface method 'com.badlogic.gdx.files.FileHandle com.badlogic.gdx.Files.internal(java.lang.String)' on a null object reference at com.example.maxst3demo.imageTracker.GLTFQuickStartExample.create(GLTFQuickStartExample.java:48) at com.example.maxst3demo.imageTracker.ImageTrackerRenderer.addGM(ImageTrackerRenderer.java:107) at com.example.maxst3demo.imageTracker.ImageTrackerActivity.load3DModel(ImageTrackerActivity.java:97) at com.example.maxst3demo.imageTracker.ImageTrackerActivity.lambda$cZoV0UmnlP2C_Kv2pF17Z95xcBc(Unknown Source:0) at com.example.maxst3demo.imageTracker.-$$Lambda$ImageTrackerActivity$cZoV0UmnlP2C_Kv2pF17Z95xcBc.run(Unknown Source:2) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1502) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)
Do i have to call some type of init method before calling the sceneAsset=gltfLoader.load(Gdx.files.internal("models/BoomBox/glTF/BoomBox.gltf"));
load method ?
There seems to be an issue with managed textures that are shared between different models.
Let's say model A and B do share a texture, now when model A is disposed, the shared texture is also disposed as if it's reference count is 0 where it should be 1. Textures of models should be ref counted, right? So I consider this a bug.
I'm not too sure if this is a bug in gdx-gltf or libgdx though but since you're a libgdx contributor it's probably better to start here and go down to libgdx if necessary.
I've tried to understand the ManagedTextureResolver and it's interaction with the asset manager and failed gloriously.
Nevertheless, here's a runnable demonstration: https://github.com/Hangman/texture-resolver-test
Warning: gradle 7 is used, not ancient 2.1 :P If you run into any problems due to this... deleting the gradle cache worked for me.
SceneManager currently seems to render everything - it would be great if it checked which objects are in the frustum (for shadows too).
it was added in this commit but it doesn't cover all cases: GLES doesn't provide this option, some version doesn't have seamless cubemap at all (GLES 2 and WebGL 1) and others have it always enabled (GLES 3 and webGL2). So this option should be turned on only for desktop OpenGL.
Steps to reproduce:
It could show a message that the size is unsupported or even better disable the options to choose those resolutions.
This also happens when setting the irradience map to 8k but not when setting the radience map to 8k.
I got no stack trace for it though.
And just to make it a little more challenging for you:
The crash won't occur with this hdri map https://hdrihaven.com/hdri/?c=nature&h=gamrig in 8k and setting the environment map size to 16k. At least it doesn't crash for me.
Render emissive only is a common use case when using bloom effects and such.
For now, user code need to implement a modified version of the default PBR shader.
It would be nice to provide something out of the box :
Hey, first of all - this project looks amazing ❤️ I'm pretty sure that most of ppl using G3D format might be interested in this solution, they just probably don't know it even exists 😢
More to the point, how stable and active is it? There is a couple of issues and the last commit was 3 months ago, I'm just curious about the future.
Hi there, I find this library very insteresting so I decided to give it a shot.
But when I load a gltf file from Blender it doesn't show up. So to make sure I wasn't making any mistake I copy pasted the quickstart example and imported a simple mesh made from a cube and it still didn't show up.
But when I downloaded the demo gltf and related files it worked, can you provide any help ?
The readme ( https://github.com/mgsx-dev/gdx-gltf/blob/master/demo/README.md ) says to run gdx-gltf-demo.jar. I tried gradlew assembleRelease
and gradlew jar
and couldn't find gdx-gltf-demo.jar
. I haven't worked with multi-module gradle setups much, but I tried going to demo/desktop and running gradle tasks
(yes, with gradle 2.14.1 🤦), and it failed with a nondescript NPE:
:demo:desktop:tasks FAILED
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.NullPointerException (no error message)
Hi,
I've tried more rigged models, but the model rendering is not complete. Tried with 1.0.0 and master branch, but the results are same.
Here is the rendered object: https://imgur.com/a/UGdtqcU
Here is the code: https://pastebin.com/MXf7Kr7r
And here is the used model: https://www.cgtrader.com/free-3d-models/character/sci-fi/low-poly-military-robot
Best regards,
Dgzt
I download the model from sketchfab,the model's texture incomplete when camera move faraway, but it's ok when camera close to the model. I'm not writing any code, just using the release jar.
Some classes names are a bit misleading for libgdx users
we have :
by default it's "textureX.png" which conflicts when exporting several models to the same folder.
prefixing by GLTF filename would be better and have lot less conflicts.
if i load scene, where include one spot light, light not work, console message "[PBRShader] too many spot lights detected: 1/0"
Hello @mgsx-dev, I am trying to run a project using gdx-gltf in the browser using gwt but I am getting this error on the console:
GwtApplication: exception: load pixmap from bytes not supported for WebGL
The exception is thrown by PixmapBinaryLoaderHack.java
Edit: Originally I thought the limitation was on gdx-gltf but I found that the GWT Pixmap has no construtor using array of bytes. This is a limitation of libGDX I am doing some research.
You can see the issue in the Demo / viewer : a materials with only a red baseColor will be rendered as grey.
the workaround is to convert baseColor attributes to diffuse attributes for all materials when loading your models.
Could be fixed like this :
Or, fix that in the gouraud shader directly by using the right attribute.
Hey, as a test I'm trying to port this scene: crypt location, preview:
As you can see it contains such a high glowing elements, but it's not really noticeable using standard values:
I've found that glTF supports emissions and you've even have it in the pbr fragment shader:
The model has properly marked elements with emission, I can see it in emission preview:
So my question is - is there any way to increase the glowing effect? I think that some kind of extra multiplication factor for emission could solve this issue.
java.lang.NoSuchMethodError: No virtual method position(I)Ljava/nio/ByteBuffer; in class Ljava/nio/ByteBuffer; or its super classes (declaration of 'java.nio.ByteBuffer' appears in /system/framework/core-libart.jar)
at net.mgsx.gltf.loaders.shared.data.DataResolver.getBufferByte(DataResolver.java:84)
at net.mgsx.gltf.loaders.shared.data.DataResolver.getBufferShort(DataResolver.java:78)
at net.mgsx.gltf.loaders.shared.geometry.MeshLoader.loadIndices(MeshLoader.java:353)
at net.mgsx.gltf.loaders.shared.geometry.MeshLoader.load(MeshLoader.java:54)
at net.mgsx.gltf.loaders.shared.GLTFLoaderBase.getNode(GLTFLoaderBase.java:277)
at net.mgsx.gltf.loaders.shared.GLTFLoaderBase.loadScene(GLTFLoaderBase.java:199)
at net.mgsx.gltf.loaders.shared.GLTFLoaderBase.loadScenes(GLTFLoaderBase.java:178)
at net.mgsx.gltf.loaders.shared.GLTFLoaderBase.load(GLTFLoaderBase.java:126)
at net.mgsx.gltf.loaders.gltf.GLTFLoader.load(GLTFLoader.java:16)
at net.mgsx.gltf.loaders.gltf.GLTFLoader.load(GLTFLoader.java:11)
at net.mgsx.gltf.examples.GLTFQuickStartExample.create(GLTFQuickStartExample.java:41)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:278)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
Just some warnings for now but it'd be better to have both GLSL 120 and 130 code.
Maybe using macro.
Vertex info
-----------
0(14) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(28) : warning C7555: 'attribute' is deprecated, use 'in/out' instead
0(71) : warning C7555: 'attribute' is deprecated, use 'in/out' instead
0(74) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(81) : warning C7555: 'attribute' is deprecated, use 'in/out' instead
0(86) : warning C7555: 'attribute' is deprecated, use 'in/out' instead
0(87) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(182) : warning C7555: 'varying' is deprecated, use 'in/out' instead
Fragment info
-------------
0(38) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(61) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(126) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(227) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(319) : warning C7533: global function textureCube is deprecated after version 120
0(555) : warning C7533: global variable gl_FragColor is deprecated after version 120
implements point light (and indirectly spot light) shadows.
maybe by using libgdx/libgdx#5018
Is there a way to load player characters and control them independently?
I spawn models (currently converted from fbx-conv... not good) and i want to use gltf (as i do for the scene/map)
However having each actor/player in a separate scene is not very easy to manage and how bad is it for performance?
now we have range for point lights and spot lights. We can then implement some frustum culling.
This may be an optional feature on SceneManager.
Discovered I can't load certain gltf models
model: https://cdn.glitch.com/832401c3-8cbf-42db-acce-98209736affc%2Fscene%20(1).glb?v=1584936939510
Is it possible somewhere to implement a check, the visible object through the camera? If the world is large, then the render is called for all objects, regardless of whether they are in the field of view or not.
For convenience, I divided the map into parts of 100 * 100 units, and I export it in separate files. Next, I check where the character is and load the part that is needed. So that the seam is not visible, I need to keep nine parts, and everything that is there is called by the render.
Lighting is not correct on some Android device : maybe due to some GLES2 limitations (mipmap filtering ? highp ?)
I've managed loaded a simple animation in a test. I'm pretty sure the animation nodes, channels are built correctly.
But when I debugged into com.badlogic.gdx.graphics.g3d.utils.AnimationController#update(float), it's current AnimationDesc member is null.
Does this means it's not started playing? How can I have AnimationController update the loaded animation?
FYI. the test code and assets
public class AnimationLoaderTest extends Game {
public static void main(String[] args) {
new LwjglApplication(new AnimationLoaderTest());
}
private Scene scene;
private SceneManager sceneManager;
private PerspectiveCamera camera;
private SceneAsset sceneAsset;
@Override
public void create() {
sceneAsset = new GLTFLoader().load(Gdx.files.classpath("gltftutorials/khronosgroup/github/simple.gltf"));
scene = new Scene(sceneAsset.scene);
sceneManager = new SceneManager();
sceneManager.addScene(scene);
// setup camera
camera = new PerspectiveCamera(60f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.near = 0.01f;
camera.far = 4000f;
camera.position.set(0, 0, 3);
camera.lookAt(Vector3.Zero);
sceneManager.setCamera(camera);
}
@Override
public void render() {
float deltaTime = Gdx.graphics.getDeltaTime();
camera.update();
// render
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
sceneManager.update(deltaTime);
sceneManager.render();
}
}
Hello, I think I've made an improvement to the creation of the ByteBuffer by using libgdx's StreamUtils:
byte[] arr = StreamUtils.copyStreamToByteArray(stream);
ByteBuffer bufferData = ByteBuffer.allocate(chunkLen);
bufferData.order(ByteOrder.LITTLE_ENDIAN);
bufferData.put(arr);
bufferData.flip();
bufferMap.put(bufferMap.size, bufferData);
Old version: 47 seconds
New version: 43 milliseconds
Great job with gdx-gltf by the way!
Blender_color_vertex_attribute_error_test_model.zip
I need my models with vertex colors. How do I fix this?
(At least) on Windows 10 the Swing open file dialog is hidden behind the Composer app window.
The dialog also doesn't show up in the task bar so users might think the app freezed. If the app window is additionally maximized you can't minimize it anymore (don't know why) after clicking on open hdr file, so the only way to get to the dialog is alt+tabbing.
Simplest and imo best solution is to minimize the app window so the dialog pops in peoples faces. After opening a file the app window should automatically get back to it's prior state.
Is there any plan to support more points ?
@mgsx-dev I know that the limitations of the number of vertices/indexes comes from libGDX. I also know that is always possible to break the mesh using a 3D software.
But let's say for the sake of convenience it needs to be handled via code. What do you think would be the best approach?
The way I can think of is (when loading a mesh): to load a mesh into an intermediate structure that would handle indexes as integers
and the whole mesh as a list of edges. Then create multiple planes(or boxes) to slice the mesh (for each sliced edge, it would become two smaller edges).
And after slicing "enough" each chunk (defined by planes) would become a new mesh node (with less indexes than the original mesh).
Do you think that approach would work? Can you think of a simpler way to do it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.