Light passes wall

Problem is that light passes wall. I do something wrong or is this bug of JME?



http://i.imgur.com/K8fkl.jpg



This is code example. For run need include jme3-test-data.jar.



[java]

package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.bounding.BoundingBox;

import com.jme3.light.AmbientLight;

import com.jme3.light.SpotLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Spatial;

import com.jme3.scene.control.LightControl;

import com.jme3.scene.shape.Box;

import com.jme3.terrain.geomipmap.TerrainLodControl;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;



public class Example extends SimpleApplication {



private TerrainQuad gameLevel;



public static void main(String[] args) {

Example app = new Example();

app.start();

}



@Override

public void simpleInitApp() {



flyCam.setMoveSpeed(200);

Material mat = assetManager.loadMaterial(“Textures/BumpMapTest/Tangent.j3m”);



gameLevel = new TerrainQuad(“terrain”, 65, 513, null);

TerrainLodControl control = new TerrainLodControl(gameLevel, cam);

control.setLodCalculator(new DistanceLodCalculator(65, 2.7f) );

gameLevel.addControl(control);

gameLevel.setMaterial(mat);

gameLevel.setModelBound(new BoundingBox());

gameLevel.updateModelBound();

gameLevel.setLocalTranslation(0, -100, 0);

gameLevel.setLocalScale(1f, 1f, 1f);

rootNode.attachChild(gameLevel);





Box box = new Box(Vector3f.ZERO, 30, 6.5f , 1);

Spatial wall = new Geometry(“Wall”, box);

wall.setMaterial(mat);

wall.setLocalTranslation(0, 2.5f, 0);

gameLevel.attachChild(wall);





Spatial light = new Geometry(“Light”, new Box(1, 1, 1));

light.setMaterial(assetManager.loadMaterial(“Common/Materials/RedColor.j3m”));

light.setLocalTranslation(10, 5, 10);

gameLevel.attachChild(light);



SpotLight myLight = new SpotLight();

myLight.setSpotRange(400);

myLight.setDirection(new Vector3f(0, -1, 0));

myLight.setPosition(light.getLocalTranslation().add(0, -100, 0));

myLight.setSpotOuterAngle(80 * FastMath.DEG_TO_RAD);

myLight.setSpotInnerAngle(75 * FastMath.DEG_TO_RAD);

myLight.setColor(ColorRGBA.Blue);

rootNode.addLight(myLight);

LightControl lightControl = new LightControl(myLight);

light.addControl(lightControl);





AmbientLight ambLight = new AmbientLight();

ambLight.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 0.2f));

rootNode.addLight(ambLight);

}

}

[/java]

This is the way 3D rendering works, it’s not a bug.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:light_and_shadow

What he said. You just put the stuff on the other side of the wall in a different node, that should work (for now, this per-node-lighting behavior in the engine might change).

This works fine when SpotLight not moving. I will use the SpotLight like player’s flashlight and I need illuminate objects from different nodes but not all objects from these nodes.

Essentially in 3d graphics light and shadow are two different things and are handled separately…

I maybe have a solution. When update method is called, get all objects which are to be lighted and add SpotLight into their nodes.

More to the point.



Organise your “rooms” so that all the objects inside one room is attached to the same node. Then attach the light to that node.



Then the light will only go through those objects but not objects attached to the other room nodes.



Then you just need something to cope with room transitions (maybe need two lights once the light gets close to a node boundary?). I dunno what people normally do for that situation?

Back in the days of Quake 1/2/3/4/etc when you mapped you would sometimes get that sort of result. One of the workaround was to make thicker walls. Even in Source you sometimes get that and the workaround was the same. I doubt this would be effective here, but it might be worth a shot.

Is a option to solve this problem? I cannot split the wall and light just one half because this is not useful in my case.



http://i.imgur.com/rZ0gK.jpg

what might work, use two or more smaller lights attached directly to the wall. (so taht only the wall is rendered multiple times, as many lights can be extensive)

@agrach said:
Is a option to solve this problem? I cannot split the wall and light just one half because this is not useful in my case.

lol, you will have to decide whats more useful, splitting the wall or having the light "shine through".

I use the SpotLight like player’s flashlight. In singleplayer is no problem but in multiplayer, player can see light from other player behind wall and this is problem. For static lamp I split walls.

Sounds like your best option at the moment is light mapping. Are these lights static?