LightState issue

Hi,



I have a scene graph with the default light state disabled.



For one of the spatial nodes (which is a nicely colored TriMesh) into my graph, I do need some light behavior, so I create a DirectionalLight, add it to a new LightState object and set this object as a render state for my TriMesh.



The problem is that whatever the light direction is, the TriMesh has a gray color. I would expect it to have the nice colors that it originally has, but with some darker or lighter shapes, depending on how the light falls on it.



Does anyone know what I do wrong?



Thanks,



Dan

In OpenGL, if you have lighting, you must use a material to dictate color.  You can have that material pull the colors from the mesh though.



try:


        MaterialState ms = display.getRenderer().createMaterialState();
        ms.setColorMaterial(MaterialState.ColorMaterial.AmbientAndDiffuse);
        ms.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        model.setRenderState(ts);

Thanks for the reply.

The color of the TriMesh is correct now, but I still cannot see any darker or lighter parts. It is like the light would come from all the directions.



Dan

You might need to set the ambient value to something closer to black?  Or your lighting is not properly setup.

The code below is what I do.



Can you see ways to improve it? Should I use a PointLight instead of the DirectionalLight to for a sun light?

Is there a right direction for a sun light?



    TriMesh horizon2 = new TriMesh("Shaded " + _g2d.getDisplayName() + "  " + _g2dp.getDisplayName());
    horizon2.reconstruct(BufferUtils.createFloatBuffer(vertices2.toArray(new Vector3f[0])), BufferUtils
        .createFloatBuffer(normals2.toArray(new Vector3f[0])), BufferUtils.createFloatBuffer(colors2
        .toArray(new ColorRGBA[0])), BufferUtils.createFloatBuffer(textureCoords2.toArray(new Vector2f[0])),
        BufferUtils.createIntBuffer(indexesV));
    horizon2.setModelBound(new OrientedBoundingBox());
    horizon2.updateModelBound();

    LightState lightState = _renderer.createLightState();
    lightState.detachAll();
    DirectionalLight dr = new DirectionalLight();
    dr.setDiffuse(ColorRGBA.white);
    dr.setAmbient(ColorRGBA.darkGray);

    dr.setDirection(_lightDir);//new Vector3f(0.5f, -0.5f, -0.5f));
    dr.setEnabled(true);
    lightState.attach(dr);

    MaterialState ms = _renderer.createMaterialState();
    ms.setColorMaterial(MaterialState.CM_AMBIENT_AND_DIFFUSE);
    ms.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));

    horizon2.setRenderState(lightState);
    horizon2.setRenderState(ms);
    getParentNode().attachChild(horizon2);
    lightState.setEnabled(true);
    getParentNode().updateRenderState();



Thanks a lot,

Dan