[LibGDX] Decals and Models

Okay, I’m kind of new to Java and LibGDX, but I decided to start out big and try doing 3d (Don’t worry, I’ve had a few years of experience with GM, and my brother knows quite a bit about Java and LibGDX). The style of 3D I decided to go for was Paper Mario style.

To do that, I set up a a ModelBatch for the level and a DecalBatch for the entities. This works sort of, but the decals all render on top of the level. Does anyone know of a way to get the decals to be able to be obscured by the models, or am I going have to use a different method?

No offense, but you’re going in the wrong direction. First of all, you shouldn’t try 3d first if you’re new to libgdx, and especially if you’re new to Java - if you’re new to Java you shouldn’t even be making games. Second, libGDX’s 3d architecture is still quite underdeveloped, so for that I would recommend using LWJGL (if you can handle it) or something high-level like libgdx but intended for 3d (Ardor3d, JMonkeyEngine, etc). And finally, Game Maker experience is not going to help you at all, except possibly ideas about gameplay. Game Maker is way too high level, and even with the embedded C code, it’s still too different from Java and libGDX.

Jimmt - it makes no sense to suggest LWJGL for a 3D game over LibGDX’s 3D API. The whole point LibGDX is developing a 3D API is so that you don’t need to build your own 3D scene graph, model loaders, animation system, material handlers, etc.

Also; the LibGDX 3D API is not really “underdeveloped.” It’s getting to be quite stable.

While I haven’t used anything extensively besides GameMaker, I have started many times with C++, C#, and Java, so I understand how to use them in their basic form. And, like I said, my brother has worked with Java for a while so it’s easy for me to ask questions about how to use it when the need arises.

Back to the point at hand, I don’t think I’m going to switch engines. I’m not doing anything that complicated with 3D. So far I have only used the 3D part to render the level. My only question is with Decal’s and Models, and if it’s possible to have them both be in the same depth buffer (Does this make any sense to anybody? Or should I make a picture of what I mean?).

You need to render the decals at a different Z than the models. Also make sure your near/far range is OK and your depth buffer is enabled.

Keep in mind there is only one depth buffer.
http://tomdalling.com/blog/modern-opengl/03-matrices-depth-buffering-animation/
http://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm

True, I don’t know why I suggested LWJGL, but it’s going to be a while before the (2d-based) libgdx develops a 3d api better than other, 3d-only, engines/libraries (believe me I would love to have 3d with libgdx).

The only 3D method I know for decals is using projective texture mapping. The end result mimics the way a projector would display an image in real life. The process however is a bit different.

It’s hard to explain it in a brief description, but you basically use a biased matrix to convert a texture to the proper UV coordinates of a model. This is combined with a “look at” matrix. I should note any predefined UV coordinates for a model are not used nor needed for this. When I first started learning projective texture mapping, I often got tripped up thinking I needed to use the baked in UV coordinates of a model.

It’s a technique often used in conjunction with shadow mapping to project the shadows on to objects, so you may find some useful information in tutorials which talk about shadow mapping.

Here are some further explanations about projective texture mapping.
http://blog.wolfire.com/2009/06/how-to-project-decals/
www.arcsynthesis.org/gltut/Texturing/Tut17 Projective Texture.html

Unfortunately, I found the most accurate and best explanation to come from a book: OpenGL 4.0 Shading Language Cookbook.
http://www.packtpub.com/opengl-4-0-shading-language-cookbook/book

But before you go through all that, I would check through LibGDX to see if they’ve already got something to create the projective matrix for you. Maybe you’ll get really lucky and find they’ve got something set up for projecting. If not, you’re going to need to code your own shader.

Also Note: If you’re maintaining an orthogonal view, then using a depth buffer as DaveDes alluded to, may be easier to understand instead of applying a full 3D solution.

I don’t think we’re talking about the same decals here. In LibGDX, Decals are 2D sprites in 3D space. Essentially you have a flat plane with a texture on it. What I’m trying to do is make it so that these ‘Decals’ are able to go behind models. I think the problem has something to do with the Models and Decals not rendering in the same batch.

https://dl.dropboxusercontent.com/u/155046815/screenshotBelow.png

It might not be clear from this screenshot, but the guy is actually inside of the block. I don’t want that to happen.

I probably should have posted this earlier. Also, here’s most the code that has to do with rendering in case that helps (probably will): http://pastebin.java-gaming.org/a12e3368f67

I don’t know much about libGDX’s 3D API but some things were strange about your code.

  • First you don’t use your decalBatch anywhere in your render method, or are you using it elsewhere?
  • Why are you ordering the Models you would like to draw?
  • What are you doing with the renderingOrder object?

Maybe i just need more context to fully understand what you’re doing, but you can also take a look at this (If you have not allready done that):

Using the libgdx 3D API

Edit: I think i found something. Your depthBuffer is maybe not correctly initialised. You should use values between -1 and 1, als specified here: http://www.opengl.org/sdk/docs/man/xhtml/glDepthRange.xml. Most of the time you can set the depthBuffer like that:


Gdx.gl.glDepthRangef(0f, 1.0f); //0 beeing the near plane and 1 beeing the far plane

@sirkarpfen: To render with a decal batch you simply add a Decal, and then call DecalBatch.flush(), and it will render.

Also, decals are not automatically depth buffered, so he ordered them, not models.