Lightning doesn't work at all

does anybody know why my two boxes source1 and source2 aren't green and orange? they are only black, grey and white :frowning:

im really desperated!! thx

package src;

import java.util.HashMap;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.ChaseCamera;

import com.jme.input.ThirdPersonHandler;
import com.jme.light.PointLight;
import com.jme.math.FastMath;
import com.jme.math.Ray;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.CullState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.util.TextureManager;

public class CP_Controller extends SimpleGame {
   private CP_Controller controller;
   private Node m_character;
   private ChaseCamera chaser;
   private PointLight light;
   private Node floorNode;
   private Node boxNode;
   public void init(CP_Controller controller) {
      this.controller = controller;

   protected void simpleInitGame() {
      ZBufferState buf = display.getRenderer().createZBufferState();
      light = new PointLight();
      light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
      light.setLocation(new Vector3f(0f,10f,15f));
      LightState ls = display.getRenderer().createLightState();
      boxNode = new Node("BoxNode");

   protected void simpleUpdate() {
      float camMinHeight = 2f;
        if (!Float.isInfinite(camMinHeight) && !Float.isNaN(camMinHeight)
                && cam.getLocation().y <= camMinHeight) {
            cam.getLocation().y = camMinHeight;

        float characterMinHeight = 2f;
        if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
            m_character.getLocalTranslation().y = characterMinHeight;

   private void setupInput() {
      HashMap<String, Object> handlerProps = new HashMap<String, Object>();
        handlerProps.put(ThirdPersonHandler.PROP_DOGRADUAL, "true");
        handlerProps.put(ThirdPersonHandler.PROP_TURNSPEED, ""+(1.0f * FastMath.PI));
        handlerProps.put(ThirdPersonHandler.PROP_LOCKBACKWARDS, "false");
        handlerProps.put(ThirdPersonHandler.PROP_CAMERAALIGNEDMOVE, "true");
        input = new ThirdPersonHandler(m_character, cam, handlerProps);

   private void setupChaseCamera() {
      Vector3f targetOffset = new Vector3f();
        targetOffset.y = (((BoundingBox) m_character.getWorldBound()).yExtent+10) * 1.5f;
        targetOffset.x = (((BoundingBox) m_character.getWorldBound()).xExtent+10) * 1.5f;
        targetOffset.z = (((BoundingBox) m_character.getWorldBound()).zExtent+10) * 1.5f;
        chaser = new ChaseCamera(cam, m_character);

   private void setupTerrain() {
      CullState cs = display.getRenderer().createCullState();
      URL monkeyLoc;
      monkeyLoc = CP_Controller.class.getClassLoader().getResource("data/Grid.png");
      TextureState ts = display.getRenderer().createTextureState();
      Texture t = TextureManager.loadTexture(monkeyLoc, Texture.MM_LINEAR, Texture.FM_LINEAR);
      for (int i = 1; i < 5; i++) {
         for (int j = 1; j < 5; j++) {
            Box box = new Box("box", new Vector3f(i*50, 0, j*50), 50f, 0.01f, 50f);
      Box y = new Box("y" ,new Vector3f(0,0,0), 0.1f, 100f, 0.1f);
      Box x = new Box("x", new Vector3f(0,0,0), 100f, 0.1f, 0.1f);
      Box z = new Box("z", new Vector3f(0,0,0), 0.1f, 0.1f, 100f);

   private void setupCharacter() {
      Box b = new Box("b", new Vector3f(), 0.01f,0.01f,0.01f);
      b.setModelBound(new BoundingBox());
      m_character = new Node("char Node");
   private void setupTestData() {
      Box source1 = new Box("source1", new Vector3f(10,15f,10f), 5f, 15f, 5f);
      Box source2 = new Box("source2", new Vector3f(40,30f,70f), 5f, 30f, 5f);

You need to color your objects with a MaterialState.

You can either set the ambient,diffuse and specular colors in the material state.

Or tell it to use the geometry colors for ambient and diffuse.

    private void setupTestData() {
        MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
//        ms.setDiffuse(;
//        ms.setAmbient(;
//        ms.setSpecular(ColorRGBA.white);
//        ms.setShininess(90);
        Box source1 = new Box("source1", new Vector3f(10,15f,10f), 5f, 15f, 5f);
        Box source2 = new Box("source2", new Vector3f(40,30f,70f), 5f, 30f, 5f);

thx a lot! its workin know!

know i have a new problem: i draw a line wich connects these boxes. the line should be plain white. but unfortunately in on corner, the line is grey and black:

is there any possibility to solve this? this is my code:

   MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
      PointLight light = new PointLight();
      LightState lightstate = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
         light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
       light.setLocation(new Vector3f(0,0,0));
      int length = boxes.size();
      Vector3f[] vertex = new Vector3f[length];
      ColorRGBA[] color = new ColorRGBA[length];
      Vector3f center = new Vector3f();
       * only use boxes which are of a specific author
      System.out.println("Checking for: " + author);
      for (int i = 0; i < boxes.size(); i++) {
         if (authors.elementAt(i).equals(author) == true) {
      for (int j = 0; j < boxes2draw.size(); j++) {
         center = boxes2draw.elementAt(j).getCenter();
         vertex[j] = new Vector3f(center.x, center.y + boxes2draw.elementAt(j).yExtent, center.z);
         color[j] = new ColorRGBA(1,1,1,1);
      Line connectingLine = new Line("Connecting Line", vertex, null, color, null);

That would be because you applied the same material you just created in order to allow lighting on your boxes to your line, which should not be affected by light.

hmm the materialstate for the boxes is created in another class i think. that cant be true?

then i should attach no materialstate to the lines?

further explanations would be great. i can't getting it to work

At the end of your initialization you call:


What is that "nodes" and how is it related to the scene graph?

Perhaps you are attaching your lines to a node that already has some lighting configuration.

node is a separate node which i created only for these purpose and afterwards it is added directly to the root node. there should be no alternative light configuration.

Use Nymon's Scene Monitor (search for it in the forums) and check what renderstates and lighting configuration it is being applied.

thx for the answer. do you mean this helper tool?

i tested it, and as far as i can see, lineNode and ConnectingLine are the only ones with Renderstate L

Line: Connecting Line
Transform: (-0.6571431, -0.49047637, 24.0)[0.0, 0.0, 0.0]{1.0}
LineBatch: null
Batches set: VCT0
Vertex: 322

19.10.2008 21:30:59 cleanup
INFO: Cleaning up resources.
19.10.2008 21:30:59 start
INFO: Application ending.

is L (for light) even the correct state? or should it be M for RenderState??

I can't remember whether you need a MaterialState for something to be lighted. Try adding a MaterialState to your lines but... the rest of the lines look good so I don't think that's a problem.

I was talking about this tool:

yes i already tried to add an materials tate but nothing changes. it's weird because its always the same line which is darker than the others, even if i draw 100 lines or so its always the lines which are near to (0,0,0).

thy for the link, i will test it tonight!

i really hope we can solve this odd problem :smiley:

The only thing I can think of is a missing updateRenderState call or something similar.

shouldn't be the case…

could it be a problem that im using chase camera and thirdperson handler in combination with a point light? should i use a lightnode or something similair?

i detected that if i move the camera, in some positions the line becomes grey instead of black. thats why i think it has something to do with the chasing camera and the light settings…

the problem is solved. thx @ all for the great help.

the problem was related to this one: