i tried to add torches to my dungeon, but i need a LOT more than 8 lights.
at first, i need one magic light to light everything up a little but so there are no completely dark places. then, i want every torch to be a lightsource which affects a small area. i can split up the dungeon so that the areas affected by the torches to not share any triangles and avoid the “8 lights at once”-limit.
my problem is: it doesn’t work. :’(
at first, in my dungeon root, i disabled the world roots sunlight:
setLightCombineMode(LightState.COMBINE_RECENT_ENABLED);
final LightState l_lightState = Core.getInstance().getDisplay().getRenderer().createLightState();
l_lightState.setEnabled(false);
this seems to work.
but adding lights leads to some walls being totally bright and some being black.
final LightState l_lightState = Core.getInstance().getDisplay().getRenderer().createLightState();
final PointLight l_pointLight = new PointLight();
l_pointLight.setLocation(l_center);
l_pointLight.setEnabled(true);
l_pointLight.setAttenuate(true);
l_pointLight.setQuadratic(1.5F);
l_pointLight.setDiffuse(ColorRGBA.white);
l_pointLight.setAmbient(ColorRGBA.white);
l_pointLight.setSpecular(ColorRGBA.white);
l_pointLight.setShadowCaster(true);
l_lightState.attach(l_pointLight);
l_spatial.setRenderState(l_lightState);
this might be the result of me having no idea what these lines do:
l_pointLight.setAttenuate(true);
l_pointLight.setQuadratic(1.5F);
l_pointLight.setDiffuse(ColorRGBA.white);
l_pointLight.setAmbient(ColorRGBA.white);
l_pointLight.setSpecular(ColorRGBA.white);
i had a look at testlights, but it didn't give me any information.
In a real world, the light intensity should decrease in inverse proportion to the distance.
In OpenGl, we also can defines the light attenuation with the distance.
OpenGl calculates an attenuation factor (between 0 and 1) that is multiplied to the ambient, diffuse and specular color. By default, they are no attenuation (attenuation factor is 1) so you have to defines your own attenuation.
The attenuation formula is (defult attenuation factor is 1) :
attenuation factor = 1/(GL_CONSTANT_ATTENUATION + GL_LINEAR_ATTENUATION*d + GL_QUADRATIC_ATTENUATION*d
Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
labelTable.put(new Integer(0), new JLabel(""+min));
labelTable.put(new Integer(iMin), new JLabel(""+min));
labelTable.put(new Integer(iMax/2), new JLabel(""+(max/2)));
labelTable.put(new Integer(iMax), new JLabel(""+max));
sld.setLabelTable(labelTable);
That sounds a LOT like one of Nate Stevens example programs. If you could extend it to be able to change the type of light and specular, diffuse, and ambient values that could be a GREAT tool to be put into jME itself. (Maybe also have material values)
about that 8 light limit… does it mean 8 lights per node, or 8 lights at all per frame?
in my dungeon there are up to ~100 lights visible, but only 2 per node - and yet, not all of them are working. if i turn around, some switch on and some switch off.
The limit is 8 lights per lighting equation, which basically means 8 lights per mesh.
Mr Coder is doing some refactoring in the light area, particularly in sorting and using the best lights. You may be able to see that in the coming weeks, but perhaps he could comment on his findings here when he has the time.
i "solved" my problem by disabling the occlusion mapping from testfragmentprogramstate and using just a simple texture. it seems the vertex/fragment program ignores the attenuation
and here, some buggy torches and wornd positioned lights:
but you can see where it’s going at.
is there a way to set a light to the future center of a bounding box? when i’m building the dungeon and position the torches, i only have the relative position inside the zone, but i need the absolute position for the light. in this screen, i made a good guess where the torch is, but using it’s actual bouning box center would be better.
what i've done so far is removing the limit on number of lights per lightstate, and added in functionality in core for sorting by distance/prioritizing the lights of which the first 8 is used(if you have that many). so you won't have to mess with adding every spatial to a lightcontrollermanager (and giving all those spatials their own lightstate which was required), and you can choose to sort lights on whatever level you want(root or only the spatial moved etc)…