Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX: No Box2DLights shadows on scene2d Stage Actors  (Read 1893 times)
0 Members and 1 Guest are viewing this topic.
Offline dermetfan

Senior Member


Medals: 11



« Posted 2013-05-15 21:43:49 »

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!

Offline davedes
« Reply #1 - Posted 2013-05-15 21:52:01 »

Draw the sprite on top of the shadow?

Offline dermetfan

Senior Member


Medals: 11



« Reply #2 - Posted 2013-05-15 21:57:19 »

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:

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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pitbuller
Q
« Reply #3 - Posted 2013-05-15 22:56:52 »

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.
Offline dermetfan

Senior Member


Medals: 11



« Reply #4 - Posted 2013-05-16 01:14:45 »

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

Offline dermetfan

Senior Member


Medals: 11



« Reply #5 - Posted 2013-05-16 20:22:59 »

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...

Offline pitbuller
« Reply #6 - Posted 2013-05-17 13:57:21 »

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.
Offline dermetfan

Senior Member


Medals: 11



« Reply #7 - Posted 2013-05-17 21:53:00 »

Thanks, I guess I'll just stick with soft shadows then, doesn't look so bad Grin

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (15 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (10 views)
2014-07-29 10:59:34

E.R. Fleming (28 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!