Search code examples
javalibgdxpost-processing

Using post processing effects with box2dlights in libgdx


I'm using libgdx-contribs/postprocessing to add a bloom effect to shapes in my libgdx application.

And box2dlights for some lights and shadows.

My goal is to render the box2d world and apply the lights and shadows, then render all the shapes again using the bloom effect.

But when I run the code below, I only see the shapes with bloom effect. There are no box2d lights or shadows being cast.

Any ideas why?

@Override
public void render(float delta) {

    // render box2d lights/shadows
    for (Body body : bodies) {
        ((Shape) body.getUserData()).draw(
                shapeRenderer,
                body.getPosition());
    }

    rayHandler.setCombinedMatrix(camera);
    rayHandler.updateAndRender();

    // apply post processing effects (bloom)
    game.getPostProcessor().capture();
    for (Body body : bodies) {
        ((Shape) body.getUserData()).draw(
                shapeRenderer,
                body.getPosition());
    }
    game.getPostProcessor().render();
}

Solution

  • Try with:

    game.getPostProcessor().enableBlending();
    

    In your render method. Apparently here they have the same problem pointing to this example.