LibGDX: No Box2DLights shadows on scene2d Stage Actors

Hello everyone,
I made my own Entity class that extends a scene2d Actor to get the advantages of scene2d and Box2D (it has a Body field in it). I use the Box2DLights RayHandler to… well, add lights.
The Player (subclass of Entity) is added to the stage with stage.addActor(player).

Everything works fine, except that the player is completely coverd by its own shadow… The big Sprite in the upper right is just drawn manually (not added to the stage) and works:

If I draw the RayHandler before drawing the stage, the player is not affected by the shadow:

If I think about it, it makes sense that the player is covered by its own shadow; after all, there is a Box2D Body at the same position, which makes the shadow appear there.
But there has to be a way to draw the player over its shadow without it being completely visible in the dark. My whole game is not playable if you can see things in the dark.

You can look at the source at http://bitbucket.org/dermetfan/somelibgdxtests. It’s all happening in net.dermetfan.someLibgdxTests.screens.TestScreen3.

Any advice will be highly appreciated!

Draw the sprite on top of the shadow?

The second image shows the result when I do that (RayHandler = shadow, Stage = Sprite):

[quote]If I draw the RayHandler before drawing the stage, the player is not affected by the shadow:


[/quote]
The point is that you can see the player’s Sprite where no light is.

[quote]But there has to be a way to draw the player over its shadow without it being completely visible in the dark.
[/quote]

You have plenty choices here. These three come to my mind first.

  1. Soften lights so player get some light.
  2. Filter player body completely. This has side effect that player then won’t cast any shadows.
  3. Draw player body top of shadows if player bounding box corners are in light. You have query method for pointAtLight or pointAtShadow. Also light have point contain that can be used for more spesific queries per light. Point tests are really fast.

Adding small ambient light can also solve this.

Hope you find some way to solve this.

The filter is the best choice for me in this case. Works, thank you!

Ok actually the soft lights are the best option, but that doesn’t matter now.

I thought about modding Box2DLights so that the shadows are not rendered over the Body.
I don’t really understand the code, probably because I only know ridiculously small parts of OpenGL, but I thought I don’t need this much OpenGL to do the kind of change that I want:

It looks like the shadows are drawn from the first collision of a light ray with a Box2D Body into infinity. I’d like to change this to the second collision, so it’s the collision of the light ray with the other side of the Body. This way, the shadow would begin on the farer away side of the Body (seen from the light position) and not be drawn over it. Hopefully I made my idea clear enough.

Instead of replacing the current way it’s done, wouldn’t it be possible to add Light#setShadowBehindBody(boolean shadowBehindBody) or something similar?
I don’t want to put extra work on you, but is this as simple as it seems to me in theory? I don’t even find the place where the collisions of rays and Bodies are calculated…

Just to test second collision wont work with non convex bodies. This would make raycastin rather complex. But if you wan’t to modify source then just continue raycast until box2d body change or raycast end and use last collision point.

Thanks, I guess I’ll just stick with soft shadows then, doesn’t look so bad ;D