Bigger Geometry -> weaker light

Hi (merry Christmas 'n stuff), I’m confronted with some weird behaviour of a SpotLight.
The SpotLight is pointing at a box and doing its job just fine - until I scale the box and make if a lot bigger.
When that happens, the SpotLight gets extremely weak until it seems to vanish.

Here a simple test-case:
[java]
public class Main extends SimpleApplication
{

private Geometry boxGeometry = new Geometry("asdf", new Box(10, 10, .01f));
private SpotLight sLight = new SpotLight();
private float addedScale = .005f;
public static void main(String[] args)
{
    Main app = new Main();
    app.start();
}

@Override
public void simpleInitApp()
{
    cam.setLocation(new Vector3f(0, 0, 30f));
    boxGeometry.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"));
    rootNode.attachChild(boxGeometry);
    sLight.setSpotRange(100);
    rootNode.addLight(new AmbientLight());
    rootNode.addLight(sLight);
}

@Override
public void simpleUpdate(float tpf)
{
    sLight.setPosition(cam.getLocation());
    sLight.setDirection(cam.getDirection());
    boxGeometry.setLocalScale(boxGeometry.getLocalScale().add(addedScale, addedScale, 0));
}

}[/java]

Now, I searched a little and found this pretty old thread:

uhm, sorry, postet this accidently… now continuing:
old thread
Now, one helpfull member advices to use a fake spotLight (via texture which is a nice idea but I can not use it because the SpotLight is set dynamicly) or creating a pixel-shader.
I haven’t been into shaders at all yet (gonna do … one day) but is there any other way apart from just not using huge boxes?
If not, I’ll have to stick with the shader-stuff I guess, but that Thread is really old, so it might be outdated I thought. I hope.

@benkibitzer said: uhm, sorry, postet this accidently... now continuing: old thread Now, one helpfull member advices to use a fake spotLight (via texture which is a nice idea but I can not use it because the SpotLight is set dynamicly) or creating a pixel-shader. I haven't been into shaders at all yet (gonna do ... one day) but is there any other way apart from just not using huge boxes? If not, I'll have to stick with the shader-stuff I guess, but that Thread is really old, so it might be outdated I thought. I hope.

Do you have vertex lighting enabled? If so, perhaps try disabling this and see if you have the same issue. Point lighting does something funky across large quads… and attenuation for points and spots are similar. Per-pixel lighting should eliminate this problem, buuuut… can’t say from personal experience.

Some lighting values are interpolated from vertex to vertex and so will show these issues when the triangles are very large. You will need to increase the number of triangles in your box.

…the easiest way might be to use Lemur’s MBox which allows you to specify a number of “splits” but otherwise takes the same parameters as JME’s Box class.
http://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/Lemur/src/com/simsilica/lemur/geom/MBox.java

For example:
new MBox(10, 10, 0.1f, 9, 9, 1)

…would create a box the same size (20 x 20 x 0.2) but split into 10 sections along x and y, ie: a box made up of 2x2 meter quads on those sides.

This would give the lighting interpolation something better to chomp on.

2 Likes

Thank you guys.

@t0neg0d said: Do you have vertex lighting enabled? If so, perhaps try disabling this and see if you have the same issue. Point lighting does something funky across large quads... and attenuation for points and spots are similar. Per-pixel lighting should eliminate this problem, buuuut... can't say from personal experience.
No, didn't have Vertex Lighting enabled. Tried that (because why not) but that made the light disappear.
@pspeed said: Some lighting values are interpolated from vertex to vertex and so will show these issues when the triangles are very large. You will need to increase the number of triangles in your box.

…the easiest way might be to use Lemur’s MBox which allows you to specify a number of “splits” but otherwise takes the same parameters as JME’s Box class.
http://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/Lemur/src/com/simsilica/lemur/geom/MBox.java

For example:
new MBox(10, 10, 0.1f, 9, 9, 1)

…would create a box the same size (20 x 20 x 0.2) but split into 10 sections along x and y, ie: a box made up of 2x2 meter quads on those sides.

This would give the lighting interpolation something better to chomp on.


Very neat, working perfectly thanks!