Question on lightNodes etc

Can anyone tell me the difference between:

this code that is launched from the main class (that extends SimpleGame) and in the 'for' I refer to classes that are instantiated inside the main class

for (int i=0;i<r.rooms.size();i++){
          for (int j=0;j<r.rooms.get(i).objects.objects.size();j++){
             for (int k=0;k<r.rooms.get(i).objects.objects.get(j).lightNode.getQuantity();k++){


this 'works' meaning I have a normal light system that shows what I expect. But that's ugly coding and I'd like to have the 'lightState.attach( ... )' done inside the r.rooms.updateGeometry() function.

when I do the following, I have no light at all (or the problem that makes the whole world as if all the meshes were lit by a max power light source)

In this class, I launch the following code from my RoomManager (instantiated from the SimpleGame class):

                public LightState lightState;


      lightState = com.jme.system.DisplaySystem.getDisplaySystem()

and then the same light initializing

public void updateGeometry(){
      for (int i=0;i<objects.size();i++){
         for (int j=0;i<objects.get(i).lightNode.getQuantity();i++){

and also later, I run a


Thanks a lot for any help, I've been spending a few evenings on that now ...


By the way, I couldn't find any tutorial on advanced lighting, which may be the cause for my problems. I mean except attaching directly one or a few lights to the main lightState, I'm not exactly sure how one should proceed to organize lights in a more complex program,

I also checked the TestManyLights example, could you tell me if my understanding is correct:

Each light should be attached to a LightNode (contains only a single light) and the same light should also be added to the rendering queue of a LightState (must be enabled true of course) (not necessarily just one, and what exactly does the 8 lights limit per LightState mean ? does it mean that after 8 lights, we must create another LightState ? how to deal with the case where we'd have more than 8 lights around the same place, should we then use several LightState ?).  The Light Node allows you to play on the position of the light.

You attach all the LightNodes to a main Node (but is there a limit on the number of LightNodes you should attach to a single Node ?). Let's say then that you attach the Node to the rootNode (the Node may also contain regular Spatial elements). You must then apply (setRenderState) the LightState(s) to the rootNode (or the Node that contains the LightNodes ??)

then not forget the updateRenderState to the Node …

and at that point this does not even have anything to do with shadows …


I finally solved the problem (but it always helps to expose exactly the situation to s.o. else !)

I just needed to realize that the LightState needed to be part of a top class (at least just below the SimpleGame) for you need to attach ALL the lights to it.

Last question I still cannot really answer, can you have several LightState rendering different nodes ???



shagros said:

...can you have several LightState rendering different nodes ???

Yes. It will only effect the children of the node the lightstate is added to.

did you do a updateRenderState() aftter setRenderState()?

yep, inside the roommanager, roomNode.updaterenderState() and also at the end of the whole world update, rootNode.updateRenderState()

shagros said:

what exactly does the 8 lights limit per LightState mean ? does it mean that after 8 lights, we must create another LightState ?

The 8 light limit is a opengl limitation:
The number of lights depends on
  the implementation, but at least eight lights are

In jME the Spatial class has the sortLight() Method, which sorts the lights of a LightState if it has more then 8 lights. (based on distance for point lights)
But i didn't see yet what the sorting is good for, or where exactly the lights are used when rendering :)

Also the javadoc of LightState.attach() is outdated and misleading. (the behaviour changed with rev. 3831)

Maybe someone with a solid understanding of the light stuff could correct the javadoc.