Local light howto


I would like add support for local lights (like lanterns, fireballs, lava, …) to our game bloxel …

currently I have one light … a sunlight … but in a cave its should be dark … but there is light everywhere :slight_smile:

some information about lights would be nice!



Use a control to move the light with the spatial, I think theres a premade one already.

if you use unshaded.j3md, they will be visible with/without a light. You need to use lighting.j3md if you don’t want things to show up without a light source.

An ambient light gives global lighting equally to everything, no direction no location

A directional light has no position, only a direction. It is considered “infinitely” far away and sends out parallel beams of light.

A point light has a location and shines from there in all directions as far as its radius reaches, like a lamp


ahoehma said:
... but in a cave its should be dark ... but there is light everywhere :)

If there is a good way to determine if player is totally enclosed in cave I would deactivate/remove the "sunlight" once the player is inside the cave. Otherwise the general solution is discussed in:http://hub.jmonkeyengine.org/groups/general-2/forum/topic/light-goes-through-wallsmodels/

Thanks for the info.

But what I’m searching for is a “best practice” for jme to define lights for “box world engines”. Let me explain …

When I’m using a directional light then boxes in caves or underground are also visible … I won’t that … such boxes should become visible

if a) “enough” sunlight reach the boxes or b) if a additional light source will be added in the near area around the boxes or c) the player use a flash light. I’m interested in more information how “lighting.j3md” calculate the light for a specific vertex in a scene.

You know what I’m searching? :slight_smile:



phate666 said:
For every empty block you save a light value, and when generating the mesh, you save this light value in every adjacent face to the empty block.

How can I do that in JME?

And what's with moving lights ... the sun or the moon will moving on the sky ... should I update each block after such a "move"?

I tough jme have a "build in light system" is this wrong?

Others have it right. JME is not a block world engine but a more general engine. Sandbox block worlds have features that make everything a little different. Sometimes easier (for example, world collision detection is trivial in a block world) and sometimes harder (lighting).

Baking lighting into the geometry is the only real way to handle the scale needed to deal with the explosive amount of lights that are possible.

As stated by others, that’s what all of the block worlds I know of do… even Mythruna.

How can I store the light information in the mesh? I can’t find a buffer for that?

Do you mean the “LightMap” attribute of the lighting material?

I tried the following (currently without success)

1.) define a lightmap


2.) load the material with lightmap


final Texture texture = theAssetManager.loadTexture(“Textures/Bloxels/minecraft.png”);

final Texture lightMap = theAssetManager.loadTexture(“Textures/Bloxels/lightmap.png”);

bloxelMaterial = new Material(theAssetManager, “Common/MatDefs/Light/Lighting.j3md”);

bloxelMaterial.setTexture(“DiffuseMap”, texture);

bloxelMaterial.setTexture(“LightMap”, lightMap);

bloxelMaterial.setBoolean(“SeparateTexCoord”, true);


3.) for the mesh set the TexCoord2 buffer:


chunkMesh.setBuffer(Type.TexCoord2, 2,

BufferUtils.createFloatBuffer(lightCoord.get(bloxelType).toArray(new Vector2f[lightCoord.size()])));


I calculate these lightmap-texture-coordinates like the “normal” texture coordinates (uv-map) … currently I set the top face with light-value (10) and the other faces with light-value (0) … so I expect that all top faces are visible and all other faces are black.

4.) I don’t add any light to the scene

result: a black screen :wink:

any ideas?

You are still using Lighting.j3md… that will require lights of some kind.

There are numerous ways to bake lighting into your geometry. The approach you are using requires that you us Unshaded.j3md. I’m not sure of the light map setup for that material but it does support light maps… it may be like you have it.

I tried Unshaded.j3md but all faces are 100% visible and the performance is very bad (lighting-material > 60fps, unshaded 4 fps!).

Maybe I must create my own material based on lighting :slight_smile:

I think Unshaded should be faster than lighting… something is very strange.

Generally games like minecraft and mythruna just bake the lighting into each block in the scene. A color buffer is used for that.

The custom meshes tutorial in the wiki shows how to use color buffers.

It works! Was my fault (again) … wrong uv-map-coordinates :-]

I can use light map with lighting or unshaded material. Lighting requires at least one light (I tried a ambient light) and it works as I expect it.

Now its time to implements a good light-value-calculation algorithm.

Thanks guys