Lighting glitches

This is bugging (me) for a very long time now, have tried anything I could come up with, and now I have no idea how to fix it.



The below video occurs with the light source at a certain angle.

http://www.youtube.com/watch?v=-_JaMtMgjwE

(how do i embed these youtube videos?) — just paste a youtube link to the post :wink: - normen







The next video with just the light source angle changed.

http://www.youtube.com/watch?v=Gcb13r8OKno







[java]public class LightingTest2 extends SimpleApplication {

public static void main(String[] args) {

LightingTest2 app = new LightingTest2();

AppSettings settings = new AppSettings(true);

settings.setTitle(“Test”);

settings.setRenderer(AppSettings.LWJGL_OPENGL2);

settings.setWidth(1024);

settings.setHeight(768);

app.setShowSettings(false);

app.setSettings(settings);

app.start();

}



@Override

public void simpleInitApp() {

Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

mat.setTexture(“m_DiffuseMap”, assetManager.loadTexture(“Textures/Terrain/Pond/Pond.png”));

mat.setTexture(“m_NormalMap”, assetManager.loadTexture(“Textures/Terrain/Pond/Pond_normal.png”));

mat.setFloat(“m_Shininess”, 15f); // [0,128]

mat.setActiveTechnique(null);

// trimeshes visible both sides

mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);



Box b = new Box(5,5,5);

Geometry g = new Geometry(“box”,b);

g.setMaterial(mat);

rootNode.attachChild(g);



Box b2 = new Box(5,5,5);

Geometry g2 = new Geometry(“box2”,b2);

g2.setMaterial(mat);

g2.setLocalTranslation(14, 0, 0);

rootNode.attachChild(g2);



Quad q = new Quad(10,10);

Geometry g3 = new Geometry(“quad”,q);

g3.setMaterial(mat);

g3.setLocalTranslation(-5, 7, 0);

rootNode.attachChild(g3);



// top-right: Quad - will change lighting if looking up or to the left

Quad q2 = new Quad(10,10);

Geometry g4 = new Geometry(“quad2”,q2);

g4.setMaterial(mat.clone());

g4.setLocalTranslation(9, 7, 0);

rootNode.attachChild(g4);





// light & cam

DirectionalLight light = new DirectionalLight();

// light.setDirection(new Vector3f(-2,0,-20)); // Enable to see Case A - Flickering

light.setDirection(new Vector3f(-1,-1,-1)); // Enable to see Case B - Brightness flipping

rootNode.addLight(light);



cam.setLocation(new Vector3f(65,25,65));

cam.lookAt(new Vector3f(50,15,50), Vector3f.UNIT_Y);

flyCam.setMoveSpeed(10);

}



}

[/java]



This also occurs in more complex scenes.



Any help as to what’s causing this, and more importantly how to fix this?

Many thanks

Well you use normal mapping on primitives that doesn’t have tangents and binormals.

Try to use the TangentBinormalGenerator on all the boxes/quads, it should be fine.

Your light directions are not unit vectors.

Well you use normal mapping on primitives that doesn’t have tangents and binormals.
Try to use the TangentBinormalGenerator on all the boxes/quads, it should be fine.

Well, I have tried that in the past, and what happened is that the surfaces loose brightness - They become as dark as the darker objects in the videos.

So perhaps that's normal and the light surfaces in the video are actually too bright. Is that the case?



Your light directions are not unit vectors.

Yeah. I had normalise()-ed them once, but that didn't (and still doesn't) seem to do anything.
How bad is that?
durandal said:
Well, I have tried that in the past, and what happened is that the surfaces loose brightness - They become as dark as the darker objects in the videos.

So perhaps that's normal and the light surfaces in the video are actually too bright. Is that the case?

I guess so, normal mapping just can't work without generating the tangents, so the changes in brightness is due to that for sure.
about the brightness, you can tweak the ambient color, and the shininess of the material to have good results.

I think i tested your issue before, the video reminds me of something....i'll check tonight

Yeah might have. I have posted similar a month or two back, with no solutions (and no videos), but that might be understandable if the darker shade is how it’s supposed to be in the first place.

Thanks



Speaking of the above videos - they now turned from links into embedded videos. How did that work?

Edit: i found your answer above, Normen. Thank you