[BUG] Symmetrical Blender Model with TangentGenerator and NormalMap

Hi! I found this bug in blender model since jme alpha 2(before @kaelthas started working on the blender loader). I think the problem could be in model’s tangents/normals/binormals.



There is just a blender geometry, normal map, j3m material, light source, tangent generator. When model is symmetrical so and TangentGenerator is true, so there is a seam appears on the model. But if TangentGenerator is switched off, so the seam disappears.



I did a simple test for *.obj and *.blend models.



Here you can get it:



Screenshot: http://dl.dropbox.com/u/26887202/123/jme_blender/normalmap_bug/seam_blend_model.png

Code: http://pastebin.com/xizbkEC5

Models with NormalMap Texture: http://dl.dropbox.com/u/26887202/123/jme_blender/normalmap_bug/Models.zip



Entire JMP project: http://dl.dropbox.com/u/26887202/123/jme_blender/normalmap_bug/NormalMapTest.zip

It seems the problem looks like it is described here: http://www.gamedev.net/topic/587770-inverted-tangent-normal-map/

I suppose it is in the Blender Loader.

Core Devs, can you tell anything about this issue? Is it possible to fix symmetrical blender models with normal map? Otherwise, I have to use obj and ogre files instead of blend files.

Just stitch the model together in blender…

there are no stitches and modifiers in blender model. obj model was exported from blender. it’s ok with obj.

This is really a bug blender models and symmetry like here http://www.gamedev.net/topic/587770-inverted-tangent-normal-map/.

As I mentioned above, stitches appear when I switch TangentGenerator on in my code. Otherwise, there are no any stitches on the blender model. So, the problem is with TangentGenerator and symmetrical blender models.

can be due to the fact that blender and jme does not use the same normal maps

have you try to invert red and green channels?

I tried invert channels (rgb) of normal map. Stitches appear anyway.



It caused by TangentGenerator. Possibly, TangentGenerator recalculate normals/tangents/binormals of a blender symmetrical model in different way.



But if I switch TangentGenerator off the stitches disappear.

The problem also can be in BlenderLoader instead of TangentGenerator. When BlenderLoader loads meshes.

But if I switch TangentGenerator off the stitches disappear.

mhhhh.... @Kaelthas do you import blender's tangents when loading a mesh?

No I didn’t implement tangents loading.

But as I see I probably should.

Kaelthas, I sent you a message, but you were faster. :slight_smile:

I updated today JMP. The problem still exists.

Kaelthas said:
No I didn't implement tangents loading.
But as I see I probably should.

well...shouldn't be necessary. Because the tangentGenerator should work fine
But you'll have issues with normal maps generated in blender, because you have to invert the red and green channel in order to render them properly with the lighting material

The issue here is with the tangent generator i guess....

I think the issue is that the TangentBinormalGenerator writes binormals but the lighting material does not use them, it only uses the tangents. Because the mirror modifier also mirrors the UVs, it can cause the computed binormal in the lighting material to be inverted which causes the issue.



To fix it, the TangentBinormalGenerator must write the tangent sign into the W coordinate of the tangent buffer and discard binormals. The lighting material already has existing code to handle that W coordinate.

Ok I commited a fix to SVN. Even though it fixes the seam it still doesn’t fix the triangle lighting issues … Not sure why it happens actually

Thanks for fixing! Stitches disappeared, but triangles are seen.



http://dl.dropbox.com/u/26887202/123/jme_blender/normalmap_bug/seam_blend_model_fix1.jpg

Yeah I don’t know why that happens. I think it happens with regular lighting as well so its not related to normal mapping

@Momoko_Fan , you are right in some way. Triangles are seen without normal map. But I think the problem is still in the tangentGenerator or possibly in BlenderLoader. I post images below:



http://dl.dropbox.com/u/26887202/123/jme_blender/normalmap_bug/with_normal.jpg



http://dl.dropbox.com/u/26887202/123/jme_blender/normalmap_bug/without_normal.jpg