Light flickering

Hi  i have some weird lighting problem on my Quad when i move the camera around. The problem seems to be in the location of the light




import java.net.URL;
import loading.Loaders;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.light.SpotLight;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;

public class LightTest extends SimpleGame
{
   private static final URL   floorURL   = LightTest.class
                                       .getClassLoader()
                                       .getResource(
                                             "jmetest/data/texture/wall.jpg");
   private static final URL   modelUrl   = LightTest.class
                                       .getClassLoader()
                                       .getResource(
                                             "jmetest/data/model/Character.3DS");

   private Node            dude;

   private Quad            floor;
   private Node            terrainNode;

   @Override
   protected void simpleInitGame()
   {
      buildDude();
      buildFloor();
      buildLight();
      rootNode.updateGeometricState(0, true);

   }

   private void buildFloor()
   {
      // texture
      TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      ts.setTexture(TextureManager.loadTexture(floorURL, Texture.MM_LINEAR,
            Texture.FM_LINEAR));

      ts.getTexture().setWrap(Texture.WM_MIRRORED_S_MIRRORED_T);
      ts.getTexture().setScale(new Vector3f(1.5f, 1.5f, 1.5f));

      // vloer
      terrainNode = new Node();
      floor = new Quad("floor", 500, 500);
      Quaternion turn = new Quaternion();
      turn.fromAngles(-90 * FastMath.DEG_TO_RAD, 0, 0);
      floor.setLocalRotation(turn);
      floor.setLocalTranslation(0, 0, 0);
      floor.setModelBound(new BoundingBox());
      floor.updateModelBound();

      terrainNode.attachChild(floor);
      terrainNode.setRenderState(ts);
      terrainNode.updateRenderState();

      rootNode.attachChild(terrainNode);
      rootNode.updateWorldBound();

   }

   private void buildDude()
   {
      dude = new Node("dude");
      dude.setModelBound(new BoundingSphere());

      dude.attachChild(Loaders.load3dsModel(modelUrl));

      dude.setLocalScale(.5f);

      dude.setLocalTranslation(0, 0, 0);
      dude.updateModelBound();

      dude.updateGeometricState(0, true);
      dude.updateWorldBound();
      rootNode.attachChild(dude);
      rootNode.updateWorldBound();
   }

   private void buildLight()
   {

      SpotLight sp1 = new SpotLight();
      sp1.setLocation(new Vector3f(0, 50, 0));
      sp1.setDiffuse(ColorRGBA.blue);
      sp1.setAmbient(new ColorRGBA(0.50f, 0.50f, 1.0f, 1.0f));
      sp1.setEnabled(true);
      sp1.setDirection(new Vector3f(-300, 0, 300));
      sp1.setAngle(90);

      SpotLight sp2 = new SpotLight();
      sp2.setDiffuse(ColorRGBA.red);
      sp2.setAmbient(new ColorRGBA(1.0f, 0.50f, 0.50f, 1.0f));
      sp2.setDirection(new Vector3f(300, 0, -300));
      sp2.setLocation(new Vector3f(200, 50, -200));
      sp2.setAngle(90);
      sp2.setEnabled(true);

      LightState ls = display.getRenderer().createLightState();
      ls.detachAll();
      ls.attach(sp1);
      ls.attach(sp2);
      rootNode.setRenderState(ls);
      rootNode.updateRenderState();
   }

   /**
    *
    *
    * @param args
    */
   public static void main(String[] args)
   {
      LightTest app = new LightTest();
      app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
      app.start();
   }

}



Only the quad is affected by this flickering not the model that is in the center. When i change the location of sp1 to say new Vector3f(-1,50,1) 
the flickering stops  when the location is 1,50,1 the flickering back again, Why is this ?

i would be grateful if someone could shed some light on this
Hellmaster said:

i would be grateful if someone could shed some light on this

no pun intended?  :)

Seriously though, when I run this code (altering to do my own 3ds loading) I don't see any flickering, even changing around the light position as you mention.  Do you see it with the camera at the start position, or is it evident no matter where you move the camera to?

It is only visible when the camera is moving but it doesent matter where i move to.

i tryed to create a screenshot from it but its not visible on them.



PS. Oh yeah completely forgot about that loader.

It's not specular lighting is it?  (it can make quads appear all white sometimes)



Try setting that to light value to 0.5 and seeing if it helps, maybe also try playing with the lights (remove one, change type, etc).



Currently, you are setting your ambient to where I would like diffuse to be and diffuse is set where I would like specular to be, maybe thats it also.

(actually your ambient is currently HIGHER than your diffuse lighting)


It's not specular lighting is it?  (it can make quads appear all white sometimes)

no the quad does not appear white, infact its more like black and looks like a bad case of no double buffering and i can see what looks like the individual triangles form the quad it also looked a bit like tearing but turning on Vsync did not help.
I played around with the light settings (specular,ambient,diffuse) but this did not solve the flickering a bit more and it only seems to happen when the light is a SpotLight, i also added some boxes to the area where the light was shining and they show no flickering only the quad flickers.

I then moved the quad around a bit setting it to a location of -10,0,10 which also solved the flickering.
:? :?

I wonder if the spotlight uses the lookAt method, it has some issues.  This is just pure speculation though…