Box2dLights - dynamic 2d lights out of the box.

Source:
http://code.google.com/p/box2dlights/
Applet:
http://dl.dropbox.com/u/10960490/Uusi%20kansio/index.html

http://dl.dropbox.com/u/10960490/box2dlightsdownsampled.png

I writed library for dynamic 2d soft lighting. Its use box2d geometry and raycasting and create light meshes from collision data.
Library work with gles 1.1 or gles 2.0 automatically depending on context.

Rendering flow go something like this.


normal rendering/spriteBatch etc

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

ui stuff


Nothing special is needed it just works.

When creating a Rayhandler user just need to give box2d World


rayHandler = new RayHandler(world);

Lights can be created easily like this:

new PointLight(rayHandler, RAYS_NUM, new Color(1,1,1,1), lightDistance, x, y);

After light is created rayHandler manage, update and render it so nothing special is needed from user.

Source is licensed with apache 2.0 so its compatible with libgdx.

Public method are all java docced and at google code wiki there are more information.

[quote]FEATURES:

Gaussian blurred light maps
Point light
Cone Light
Directional Light
Shadows
Dynamic/static/xray light
Culling
Handler class to do all the work.

[/quote]
On android 8 dynamic lights and two gaussian blur pass and shadows take about 5ms total.

I have used my library for Boxtrix, Lonely miner and one yet not published project with success and there are several developers currently using library for their games. Intergration for any box2d based game should take about 5minutes at most.

Wow that demo looks amazing! It is a bit too bright so I can’t see where some of the beads are but beautiful nonetheless. :slight_smile:

Almoust everything is adjustable. Demo is bit over to top but just for underlining the idea.

Hmm Gaussian blurred light maps, Cone light and PointLight can be very useful for me. This will great after I learn a bit of libgdx basic.

Hi can you post a full working HelloWorld project? I can’t set any up :frowning:

Will do.

There you go. Standalone test project.
http://code.google.com/p/box2dlights/downloads/list
Read wiki entries too.

Woohoo thanks! :slight_smile:

Congrats to your lighting stuff !

In the last view days I started to add a second renderer module besides Java2D to my game, and with very little knowledge of LibGdx and OpenGL I got it basically working and the lighting is quite impressive and easy to set up.

Now I wonder about the following:
I have a top-down tile based game and want to show the current field-of-view of the player’s sprite (with Java2D I only darken whole tiles which are out of sight).
That works with a dynamic point light. Now, when I render the light after the sprite, the sprite gets too bright, so I do it vice versa. That’s ok.
But now the enemy sprites are naturally effected by lighting and thus the optical impression is quite different compared to the player’s sprite.

As I know too little about OpenGL, my question is: is there any way imaginable to adjust the appearance ?
Maybe only rendering the box shadows but not lighten the rest ? Or modify the light fall off, so it starts darker but keeps it brightness longer ?

You can modify light color and range. Try usin colo like r =0.4, g =0.4, b =0.4 That make the visual not so bright but you keep the darkening. Darkness value can be changed with ambientLight value.

If you are using gl es2.0 then you can set Gamma correction and also test with diffuse lighting.

For softening lights a bit you might want to add small and not so bright x-ray point light top of character.

Thanks, I didn’t see the diffuse switch - that did the trick. :slight_smile: