Lighting vanishes on large objects?


“oh noez not yet another lighting topic…!”

Since I don’t think this is related to the previous lighting stuff I posted I made a new topic. Maybe it’s just something I did not consider or forgot some code; the issue is following: I experienced that when I use large boxes, or imported models and scaled them larger => the light does not work correctly anymore. This may be a mistakenly wrong interpretation from my side because I guess it’s some kind of “shading mode” in JME:

In detail:

There is a small box on the left side and a very large box on the right side. Both boxes are in equal distance from the light source.

Picture 1: You can hardly see the large box on the right, but you see the nice red light on the small box.

Picture 2: Just to show that there really is a large box on the right. Again - only the small box is lighted.

Picture 3: Now that’s what I would have expected as a result.

Any explaination :?

import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;

public class HelloWorld extends SimpleGame{
    public static void main(String[] args) {
        HelloWorld app=new HelloWorld();    // Create Object
        app.start();    // Start the program
    protected void simpleInitGame() {
        Box b=new Box("My box",new Vector3f(0,0,0),new Vector3f(2,40,40));    // Make a box
        b.setModelBound(new BoundingBox());
        rootNode.attachChild(b);    // Put it in the scene graph
        Box b2=new Box("My box",new Vector3f(0,0,0),new Vector3f(1,1,1));    // Make a box
        b2.setModelBound(new BoundingBox());
        rootNode.attachChild(b2);    // Put it in the scene graph
        Sphere LightSphere = new Sphere("lp", 10, 10, .25f);
        LightSphere.setModelBound(new BoundingSphere());
        PointLight pl = new PointLight();

Since I couldn’t get it solved I made another scene: a large box, many small boxes, and a large sphere. The light on the sphere shows correct. All lights on the small boxes together show how strong the light should be on this place of the large box. But if you look in between the small boxes you see that the large box is still very very dark (not black, but still dark: as if the light is stretched on the whole surface).

Now let’s say I want to create a simple house in a game and put a lantern in front of the house => the wall would be dark  :frowning:

I am not specialist about that, but I think it's because lightning is on vertex. It mean that vertices are enlightened and then surface is colored using a gradiant between each vertex. With your big box, vertices are in the dark so interpolation is dark to dark.

I think you can solve it using more subdivisions on your surface.

Ah that makes sense. So for large flat surfaces It is recommended to subdivide into more faces. Now that you say it, I've found some mores topics with the same issue.

Thanks for the hint, I guess can get along with that :slight_smile:

I wish jme had a per-pixel or "phong shading" option for rendering.  I think this would solve the problem and not require subdivision since lighting is calculated at pixel rather than vertex level.  Maybe jme 2.0 will or has this? 

Thats done with a shader and there are many examples of them freely available throughout the internet. It would be nice to have a general one packaged up with jME though!

How are you drawing those axes and grids?

I just used the grid code from and added the Axes based on that. It’s added as an independent Node from the actual scene so I can switch it on and off without influence. If you use it, don’t forget to set the LightCombineMode.Off for this node

edit: I deleted the code, because you are better off with the cleaner solution of Niggle. I just experienced it myself. Thanks for that contribution btw. :slight_smile:

I add, that you should add the colored x,y,z Axis at last (so that they are visible) and add ModelBounds to each line, if you are working with ModelBouns; otherwise you will receive errors like that: => grid inherits bounds of first object with modelbounds => grid disappears whenever this object gets out of camera view