sortLight() issue

Hi guys! I have a little issue with sortLight() method! Following "TestManyLights" code, I've tried to put over than 8 lights in my scene. The problem is that I'm still stuck on 8 lights (only the first eight lights that I add works!). The only difference between my code and test's code is that I don't use SimpleLightNode because I don't need to move the lights.  For the rest everything is almost equal. Any ideas?

can you make a little test which shows the problem ? maybe alter TestManyLights or similar.

OpenGL only supports 8 lights in hardware, and thus so does JME.

The sortLight is a workaround for this that works out the best 8 lights to keep based on maths I don't really understand at a quick glance :D, but it seems to compare how much illumination each light would contribute to the scene at the current time (a mix of light type, brightness, attenuation etc etc) and keep the brightest ones (?).




I've tried to make some test, but the problem is that they work!!! Well, I'll try to post some of the real code.

First of all, just to let you know I'm extending BaseGame class.



In the InitGame I create the LightState and attach it to the root node. I also load my model.


model = (Node)ModelLoader.load3ds(path,null);
model.setModelBound(new OrientedBoundingBox());
model.updateModelBound();
model.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
       
rootNode.attachChild(model);
rootNode.updateGeometricState(0.0f, true);

rootNodeLightState = display.getRenderer().createLightState();
rootNodeLightState.setEnabled(true);
rootNode.setRenderState(rootNodeLightState);
rootNode.updateRenderState();



After that I create all the lights through an own made class (something like a light manager)


//luci is the istance of my lights manager

luci.addLight("LUCE_1", LightType.POINT, new Vector3f(2,8,-2));
luci.getLight("LUCE_1").setDiffuse(ColorRGBA.orange);
luci.getLight("LUCE_1").getLight().setAttenuate(true);
luci.getLight("LUCE_1").getLight().setConstant(0.0f);
luci.getLight("LUCE_1").getLight().setLinear(1f);
luci.getLight("LUCE_1").getLight().setQuadratic(0.0f);

//I do this several times (obviously I change each time the position of the light that I'm going to add)



Then in the update method I call an update on my lights manager that do this:


public void update(LightState ls){
   ls.detachAll();
   for(int i=0;i<lights.size();i++){
      ls.attach(lights.elementAt(i).getLight());
   }
}



And then always in the update I call rootNode.sortLights();

I hope to be clear! My English is not very good!!

when do you make the public void update(LightState ls) {} call ? only once after all lights have been created i guess ?


At each jME update I detach all the lights, attach them again and than I call update(LightState ls).

Hmm, i don't think thats needed.

Just add all lights to the lightstate.



Then all you have to do is call sortLights() once in the update method.

I detach and attach lights each update because they can change on run (the user can dynamically add and remove lights), so to avoid an if/else chain to find which lights have to be removed and which not, I simply detach them all and then attach only those that interest me. Do you think is because of this that sortLights() doesn't works?

hmm i guess it should work.

Maybe you can use the SceneMonitor to see which states/lights are active/inactive.