Normal map lighting issue

Hey,



I am using code similar to that found in the TestNormalMap class to implement normal maps on some of my in game objects, however when I apply a rotation on that object, the light seems to rotate with it.



For example, I’ll have a cube that spins slowly on it’s axis.  one side of the cube will turn to face the camera and it will be lit up as expected, but when the next face turns to face the camera, it isn’t lit up the same way



I assume the shader code isn’t taking the node’s rotation into account.  Is there a way to account for this?



EDIT: Here is a picture of what I am talking about.  The one on the left is the cube at the beginning, the one on the right is the cube turned 90 degrees.  The camera hasn’t moved, yet there is no highlight like the previous picture, so the light must have ‘moved’



ah hmm well i noticed that too, but i thought its just because the perspective varies a bit

If you think about it, unless each face has some different slant or something, when a face on the cube is facing the camera, it should be lit the same way as any other.  No change in lighting or perspective is taking place.  if you take two CDs and hold them together with the shiny side facing out and turn it, each side will glint at around the same orientation.  if you turn to look at the other CD's shiny side with the same orientation, you expect to see that glint.  We're not seeing that behavior here.



For an even better example of this issue, try replacing the collada model with a prefab sphere.  as it spins, you can watch the shine 'move' along the sphere, as if the light is moving.  since it's a sphere, the shine should never move (like on the collada model), but it does.

That looks like the Specular Lithning in the NormalMap shader. In my oppinion your screenshot look realy cool  :mrgreen:



Try to animate your light or your box like in the testcase, then you see the normaleffect.

the specular you can also deactivate, if you dont like it

If we can see your code, we can better help.

You should be able to easily replicate the issue by rotating the model in the TestNormalMap code.  I used the following code to rotate the node containing the sphere:



Quaternion rotQ = new Quaternion();
rotQ.fromAngleAxis(0.005f, Vector3f.UNIT_Z);
/* ... */
model.getLocalRotation().multLocal(rotQ);



That should replicate my issue.  Basically, when I am just rotating the model, I don't want the light to be effected.  the actual light object itself is not moving, I believe this must be an issue with the normal map shader code.

I'm assuming there is something I must apply to the light vector in the shader code so that it is oriented correctly, even if the object is rotated.

EDIT: to clarify my issue-- when I rotate the shaded object, the way the object is shaded changes, as if the light shining on it is changing.

i can't reproduce anything like that in TestNormalMap.



In the test i removed the altering of the light direction and set the direction to (-1, 0, 0),



The slowly rotating sphere looks nice and shiny with the light coming from the right.

You are right, it works great with the collada model loaded.  Try putting one of JMonkey's prefab boxes in its place, however, and you will see what I mean.



Just comment out the collada loader code and replace it with this:



        model = new Node();
        model.attachChild(new Box("box", new Vector3f(-5, -5, -5), new Vector3f(5,5,5)));



Make sure to keep the light in one place so that you can see the change in lighting better.

hmm this looks ok to me.

http://de.youtube.com/watch?v=xQXj2BctNKE



is it that what you mean ?

If the light were to stay in the same place, doesn't it make sense that the highlight should appear on each face?  My results are worse then yours, it doesn't even light up some sides properly, but the highlight is a good example.  if this were a real object it 'would' shine each time a face reflected the light directly from the cube to the camera.  It only happens one forth of the time here.