DUMB QUETION, but I can't delete it.. I have solved the problem, I'm an idiot... :D
I have Libgdx scene2d stage with actors. I need to render the Box2D Lights (v. 1.4) between the actors, so the structure would look like this:
Actor, Actor, Light, Light, Actor
My stage render:
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
super.render();
stage.act();
stage.draw();
My Box2D code:
rayHandler = new RayHandler(world);
rayHandler.setShadows(false);
Box2D update (I have a debug matrix because the physics world is being rendered in world coordinates(meters) and then I scale it to pixels):
public void updateWorld(float deltaTime) {
world.step(deltaTime, 7, 7);
// i know that this is not optimized to be called on every frame
debugMatrix = new Matrix4(stage.getCamera().combined.cpy());
debugMatrix.scale(ratio, ratio, 1);
rayHandler.setCombinedMatrix(debugMatrix);
rayHandler.updateAndRender();
}
And the light:
new PointLight(rayHandler, 128, null, 10, 0, 3);
Ok, now here is what I do: I have a Group that have some actors. I have another Group that holds the UI, drawn on top of the first group. I call updateWorld() right after the drawing of the first group is finished, so the lights will be on top of the first group and behind the second. Here is a quick illustration:
Start the drawing of the stage
Actors Group
Actor
Actor
Actor
Box2D render is called (we display the lights here)
UI Group
UI Actor panel
UI Actor panel
UI Actor panel
End the drawing of the stage
Here is the result (very ugly):
Now here is how it looks if I call updateWorld() after the stage has finished drawing (not between the actors):
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
super.render();
stage.act();
stage.draw();
updateWorld(deltaTime);
It looks the way it should look, but it covers the stage and the UI.
Now, we go back to the starting point - again call the updateWorld() after the actors group, while the stage is rendering. We modify the projection matrix of the batch of the stage:
debugMatrix = new Matrix4(stage.getCamera().combined.cpy());
debugMatrix.scale(ratio, ratio, 1);
// this line was added
stage.getBatch().setProjectionMatrix(debugMatrix.cpy());
rayHandler.setCombinedMatrix(debugMatrix);
rayHandler.updateAndRender();
The result (light is still cool, but the scene2d is broken - all the actors from the UI are gone):
I have tested many many things (I've been trying to find a solution for 3 days):
I changed the projection and the transform matrix;
Change the matrix, draw the lights and restore the previous matrix;
Tested with different cameras and vieports for the stage and the lights;
And many other stuff with the drawing of the stage, lights batch and matrix
I think that LibGDX is changing the OpenGL drawing in some way while the stage is being drawn. I don't know what to do, I am not fully sure how OpenGL works. How I can make the light look ok (like on screenshot 2 and 3)?
Update: I know that I can make 2 separate stages and draw the lights between them - that will be ok, but my structure is far more complex (I just made it simple to explain it)... so I can't to that (or I will need 4-5 different stages, which is a terrible solution)
And please, don't propose solutions that are not solutions to the problem. I can't use shaders for lights, multiple stages, exported images of light objects and so on... I need a solution to this problem :)


