PointLight position wrong?

Hey everyone,



I just started programming with jme3 and i really enjoy it :slight_smile:



The last days I tryied to implement light in my scene but somethings seems to be wrong there.







      Vector3f lightpos = new Vector3f(21, 10, 21f);

      // Light
      PointLight pl = new PointLight();
      pl.setPosition(lightpos);
      pl.setColor(ColorRGBA.White);
      pl.setRadius(40f);
      rootNode.addLight(pl);

      Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
      lightMdl.setLocalTranslation(lightpos);
      lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
      rootNode.attachChild(lightMdl);



The enviroment is generated before the light is getting attached. (The walls and floor consists of Quads)

I added another big quad to test light, seems like on this quad the light is right.



Can somebody tell me whats wrong here? :)

hi,

it looks like a problem with the normals of your mesh.

In the last screenshot, faces pointing at the light are completely black, like if the normals were inverted

Did you import it from blender?

no, i create every field with quads which are getting rotated and translated.


package dungeon.map;

import com.jme3.math.Vector3f;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer.Type;

public class OwnQuad extends Mesh
{

   public static final float[]   texture_full   = new float[] {
                                    1f, 0,
                                    0, 0,
                                    0, 1f,
                                    1f, 1f
                                          };

   public static final float[]   texture_left   = new float[] {
                                    0.5f, 0,
                                    0, 0,
                                    0, 1f,
                                    0.5f, 1f
                                          };

   public static final float[]   texture_right   = new float[] {
                                    1, 0,
                                    0.5f, 0,
                                    0.5f, 1f,
                                    1, 1f
                                          };

   public static final float[]   texture_ul      = new float[] {
                                    0.5f, 0.5f,
                                    0, 0.5f,
                                    0, 1,
                                    0.5f, 1
                                          };

   public static final float[]   texture_ur      = new float[] {
                                    1, 0.5f,
                                    0.5f, 0.5f,
                                    0.5f, 1,
                                    1, 1
                                          };
   public static final float[]   texture_dl      = new float[] {
                                    0.5f, 0,
                                    0, 0,
                                    0, 0.5f,
                                    0.5f, 0.5f
                                          };

   public static final float[]   texture_dr      = new float[] {
                                    1f, 0,
                                    0.5f, 0,
                                    0.5f, 0.5f,
                                    1f, 0.5f
                                          };

   public OwnQuad(final Vector3f p1, final Vector3f p2, final Vector3f p3, final Vector3f p4, final float[] texturepos)
   {
      updateGeometry(p1, p2, p3, p4, texturepos);
   }

   public void updateGeometry(final Vector3f p1, final Vector3f p2, final Vector3f p3, final Vector3f p4, final float[] texturepos)
   {
      setBuffer(Type.Position, 3, new float[] {
            p1.x, p1.y, p1.z,
            p2.x, p2.y, p2.z,
            p3.x, p3.y, p3.z,
            p4.x, p4.y, p4.z
            });

      setBuffer(Type.TexCoord, 2, texturepos);

      setBuffer(Type.Normal, 3, new float[] { 0, 0, 1,
            0, 0, 1,
            0, 0, 1,
            0, 0, 1 });

      setBuffer(Type.Index, 3, new short[] { 0, 2, 1,
            0, 3, 2 });

      updateBound();
   }
}



I guess this is the problem:
setBuffer(Type.Normal, 3, new float[] { 0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1 });

right? :)

when I change it to
setBuffer(Type.Normal, 3, new float[] { 0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0 });

at least the floor looks okay, except the stange black shadow

For the black shadow, please update from SVN as two bugs related to this issue were recently fixed.

The normals should point toward 0, 1, 0 for the floor and the tops of the columns, while the walls should point to x, 0, z where x and z are any number from -1 to 1.

Okay I changed the normal directions and checked out the latest jme3 branch.

Now the light seems right, but the black shadow is even worse!



This issue really should be fixed… Try setting the m_Shininess value, as the bug was related to that.

For example:

material.setFloat("m_Shininess", 32.0f);

Okay after i adjusted the shininess the shadows are much smoother, the only problem i have now is that the dirty old dungeon walls looks like scrupulously cleaned by thousands of little imps :slight_smile:







Thank you very much for your help! And keep up the good work with jme3!



Edit:

material.setFloat(“m_Shininess”, Float.MAX_VALUE); solves the problem!