Render SpriteBatch + ParticleEffect in 3D space in libgdx?

I am using libgdx version 0.9.9. I want to visualize the effect of fire using ParticleEffect in 3D space along with other 3D models.

Logical flow of my code:

  • ModelBatch Start
  • Display all 3D models in Bullet World with ModelBatch
  • ModelBatch End
  • Start of SpriteBatch
  • Render a Fire Effect with ParticleEffect (effect.draw) with SpriteBatch
  • SpriteBatch End
  • Draw a HUD with Stage

Problem: The fire effect handles perfectly at a point in 3D space. But when I rotate the camera so that the three-dimensional model is between the camera and the fire effect, the fire effect affects the three-dimensional model instead of hiding behind the 3D model.

Things I tried:

  • I tried to transfer SpriteBatch first, and then 3D models: in this case, the fire effect is not displayed. I assume that the 3D models (layer) render by the effect (layer) of the fire, and therefore the effect is not visible.
  • I tried passing SpriteBatch between steps 1 and 3, i.e. rendering a SpriteBatch between modelbatch.begin and modelbatch.end. In this case, the effect of fire is not displayed at all.
  • I tried to show the effect of Particles as an actor (added to the HUD Stage). As expected, the fire effect is displayed as part of the top layer of the HUD, and the same problem remains.
  • I tried to examine the labels, but found that the particle effect does not work with DebcalBatch. I did not want to display the animated .gif fire over Decal and therefore did not try.

Has anyone encountered a similar problem? Any proposed way to bypass ParticleEffect behaves as part of a 3D world, so that it hides when blocked by other 3D models? I saw a video posted by Xoppa on youtube about 3D particles in libgdx, but there are no steps / solutions mentioned. Any help would be greatly appreciated.

+6
source share
2 answers

The reason that SpriteBatch did not appear in the following rendering order:

  • Particle Rendering Effect with SpriteBatch
  • Render 3D models

it was that the 3D models consisted of a Skydome that overlapped SpriteBatch, thereby completely hiding it. I pulled Skydome from the set of 3D models presented in step 2 above and am doing it before the particle effect.

The following rendering order works fine for me:

  • Render Skydome with ModelBatch
  • Particle Rendering Effect with SpriteBatch
  • Give up the rest of the models with ModelBatch

With this, the particle effect is in front of the sky, but behind the 3d models.

0
source

First you need to display spritebatch if you want the fire to appear from behind rather than from above. The problem is that the screen clears when it displays 3D. Here are a few ways you could get close to this.

You can try to make sure that only the first process clears the screen.

This is the code:

Gdx.graphics.getGL20().glClearColor( 1, 0, 0, 1 ); Gdx.graphics.getGL20().glClear( GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT ); 

Unfortunately, if your 3D rendering causes this internally, and you have no control over it, then you are a bit attached. (I'm not sure how much library code or your own code you use)

I would suggest rendering for both frame buffer objects, and then you can simply render images from two frame buffer objects onto the screen in the form of 2D textures. You can then use blending between them if you want, or you can set alpha or turn off blending so that one is on top of the other, just make sure you render them in any order.

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/FrameBuffer.html

0
source

All Articles