Blender3D generated Normal Map into Jme2


Basically I’ve generated a normal map in Blender, when rendering with Blender it looks as expected, and in JME it does not  :frowning:

The object on the left has the normal map applied, where the one on the right is the object without one.

The above part which is labeled with ‘Blender3D’ is well… you can probably worth that part out  :smiley:

In JME I’m using the shader from the TestNormalMap to render the normal map, which was generated in blender from a higher poly model (as per the technique in this tut).

Now I’ve spend about two days on this; looking into the various ways blender can generate the normal map, the GLSL & maths in the shader, and even altering the normal map image (in the vert) in case the problem was Blenders coordinates system - no success.

This has me absolutely stumped. So I could really do with some advice on direction to take, or what I’m missing here?

Did you have your binormals and tangents created?  They can be stored in OgreXML format and many other formats, but they're not exported by default from Blender.  Either use the OgreXMLConverter command line tool to create them or generate them at load time with the TangentBinormalGenerator, have a look at

    private void createShader(int numLights, TriMesh geometry) {
        so = DisplaySystem.getDisplaySystem().getRenderer().createGLSLShaderObjectsState();
        String vert = load(TestDiffNormSpecmap.class.getClassLoader().getResource(currentShaderStr + ".vert"));
        String frag = load(TestDiffNormSpecmap.class.getClassLoader().getResource(currentShaderStr + ".frag"));
        vert = vert.replace("$NL$", "" + numLights);
        frag = frag.replace("$NL$", "" + numLights);
        so.load(vert, frag);
        so.setUniform("baseMap", 0);
        so.setUniform("normalMap", 1);
        so.setUniform("specularMap", 2);
        FloatBuffer tangent = geometry.getTangentBuffer();
        // the binormal is computed in the shader from tangent and normal
        so.setAttributePointer("modelTangent", 3, false, 0, tangent);

This code should help you out.


monkey_scratches_head said:

Did you have your binormals and tangents created?
Tbh when I started I had no idea about binormals and tangents, but I've know learnt what there are, don't really know if it's made me a better person tho

Ditto, I didn't know about them until a couple months ago when working with normal maps myself.

monkey_scratches_head said:

...not quite perfect though, as there is still a seam (in Blender there is a seam in the UV mapping, although this does not show in Blenders rendering). After spending some time playing around and trying different UV mapping options and placement of seams they all yield the same visual problem

Uh no I disagree. There are different ways of generating tangents/binormals.

Lex who used to work with jme and shaders contributed to jme3 an "advanced" tangent/binormal generator that did some things like split UVs and such to generate smooth tangents/binormals. I think the OgreXMLGenerator might be using the same method.

SomethingNew wrote:
Ditto, I didn't know about them until a couple months ago when working with normal maps myself.
Good to hear I'm not the only one who did know about them!
SomethingNew wrote:
What is this object? 
One of my own creation; purpose is of PoC to test out using normal maps generated in Blender to see if they work in jme.
SomethingNew wrote:
you could hide the seam with another object?
Yes, there is always a way that can be done.
SomethingNew wrote:
Are you sure you are rendering the uvs in blender and not just a material?
> Shading>Texture buttons: the image is marked as a normal map
> Shading>Material buttons>Map Input: UV
> Shading>Material buttons> Map To: Nor

(would have created yet another fraps shot, but the button panel in blender doesn't render in it - strange)
Momoko_Fan wrote:
to jme3 an "advanced" tangent/binormal generator
Is this yet another reason to migrate to jme3 I can hear?  :D
Momoko_Fan wrote:
I think the OgreXMLGenerator might be using the same method.
Huh, okay I'll download the command line tool and see what I can produce, hopefully it'll include  smooth tangents/binormals across map join areas ...I have a suspicion it may be another late night  :-o

try re-importing your model in blender and check to see if edges along your uv seams have been split, I dont know if its format specific or something but some formats get split along their uv's creating seams happen to md5 as well

You can find Lex's tangent/binormal generator for jme2 here:

However it was not updated for a long time, I cannot guarantee it's reliability but it's probably better than the current one used in jME2.

mcbeth wrote:
try re-importing your model in blender and check to see if edges along your uv seams have been split
Thanks a good idea, I'll have to sort out the ogre viewer or get the importer script for Blender (if there is one).

Despite that good idea I've ploughed on ahead and installed and used the Ogre command line tools, which was a relatively painless experience (Although the msi doesn't tell you where it chose to install them

Yes Lex has ported his generator to jME3, I think it is complete. Check the bump mapping tests there to see usage.

Generating binormal is possible via the shader by doing a cross product with the normal and tangent.

Momoko_Fan wrote:
generating binormal is possible via the shader by doing a cross product with the normal and tangent.
Interestingly that is already being done in the shader referenced by the TangentBinormalGenerator (as I was looking into how to generated the Binormal when I recieved the reply notification).

Lex's project didn't look too diferent to the JME2 shader code, however it was JME1 code with MeshBatch throughout - I didn't even get to run the tests  :(

The jme render is not quite as bad as it look in the screenshot, as the seam dissapear complete when close to the shape, however when at distance you can make out the seam, I'm not sure but that may be down to the filtering used on the normal map.

The OgreXml command line tools do seem to produce a nicer effect with the tangents - smoother.
I'll play around with the magnification filters tomorrow (see if that solves the join visible from distance problem), if it does then I've got a way of getting normal map models from Blender into Jme  :D

I'll keep you posted.

Great success!

This means I can now get a normal map generated in Blender3D into JME2 - yay!

The problem with the seam from the Ogre command line tangents was solved by changing:




Obvious now I think about it, as the minification filter determines how the normal map is shrunk when viewing it from a distance. As in the normal map image the non-mapped area is black, this must of caused the problems with the average for the texel values with the linear / mipmap filters.

...anyway - A big thank you to everyone that replied to my plea for help on this, as it probably would have taken me a great deal longer to solve my problem without all your help!