Normal maps issues

Hello

I have a problem with normal maps

they seem to be inverted depending on the orientation to the directional light
althought i generate the tangent space for all my models

on the following screenshot, one can observe the same models but rotated 0° and 180°

i create them by transforming a gray scale image with gimp normal map plugin
so i am not sure if i configure the plugin correctly before generating the normal map

but it should not be the problem as it appears correctly on some faces or in some orientation (cfr screenshot)

any advice ?

thx

Try to invert the red or green channel of your maps. I don’t know how gimp generates normal map, but for example, to have blender normal maps to work in JME you need to invert one channel (i never recall which one…)

@nehon said: Try to invert the red or green channel of your maps. I don't know how gimp generates normal map, but for example, to have blender normal maps to work in JME you need to invert one channel (i never recall which one...)

Probably y…

I think it’s funny that all of these plugins (by default) generate normal maps that are backwards for JME (to include the wikipedia description on normal maps, blenders normal maps, nVidia’s photoshop plugin for normal maps, etc.). Makes you wonder why we force inversion in Lighting by treating y as negative… probably too late to change now, I guess. Anyone know what normal maps this actually is supposed to work with?

Relating to this documentation page:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:external:blender

The red and green channels should be inverted.

@pspeed said: Probably y...

I think it’s funny that all of these plugins (by default) generate normal maps that are backwards for JME (to include the wikipedia description on normal maps, blenders normal maps, nVidia’s photoshop plugin for normal maps, etc.). Makes you wonder why we force inversion in Lighting by treating y as negative… probably too late to change now, I guess. Anyone know what normal maps this actually is supposed to work with?


Actually we don’t invert anything. We just read from the normal map and keep value as is. Before we were inverting the green channel, but this was removed.
One way would be to allow user to invert channels with a material parameter…but that’s one more uniform…and one or more multiplication per pixel…idk.
I think mifth did it for his shaderBlow lighting shader.

@nehon said: Actually we don't invert anything. We just read from the normal map and keep value as is. Before we were inverting the green channel, but this was removed. One way would be to allow user to invert channels with a material parameter...but that's one more uniform...and one or more multiplication per pixel...idk. I think mifth did it for his shaderBlow lighting shader.

Yeah, I forgot it was fixed:
http://code.google.com/p/jmonkeyengine/source/diff?path=/trunk/engine/src/core-data/Common/MatDefs/Light/Lighting.frag&format=side&r=8010&old_path=/trunk/engine/src/core-data/Common/MatDefs/Light/Lighting.frag&old=8006

I still see the commented out normal.y = -normal.y in my forks of lighting and I think it must still be that way in Lighting… but it’s commented out also. :slight_smile:

I have a question, as I’m also interested in normal mappings:
Is it needed to invert the R and G channels in blender when creating normal maps not using nightly?

I’m confused now.

i tried many things before ,
i added log entries and did a debug to check if the tangeants space was actualy created for each model
i tried inverting x and/or y in the gimp plugin, but still got the same

i dont get it,

after investigating a bit, i noticed the proble occurs is i change my light setup

this is working, having the same bumpiness on each faces of a cube

[java]
Vector3f lightDir2 = new Vector3f(0.5f, -1.0f, -0.5f).normalizeLocal();
DirectionalLight sun2 = new DirectionalLight();
sun2.setColor(ColorRGBA.Gray);
sun2.setDirection(lightDir2);
main.getSceneNode().addLight(sun2);

    Vector3f lightDir3 = new Vector3f(-0.5f, -1.0f, 0.5f).normalizeLocal();
    DirectionalLight sun3 = new DirectionalLight();
    sun3.setColor(ColorRGBA.Gray);
    sun3.setDirection(lightDir3);
    main.getSceneNode().addLight(sun3);

[/java]

this ain’t

[java]
lightDir = new Vector3f(-0.5f, -1.0f, -0.5f).normalizeLocal();
sun = new DirectionalLight();
sun.setColor(ColorRGBA.Gray);
sun.setDirection(lightDir);
main.getSceneNode().addLight(sun);

    Vector3f lightDir2 = new Vector3f(0.5f, -1.0f, -0.5f).normalizeLocal();
    DirectionalLight sun2 = new DirectionalLight();
    sun2.setColor(ColorRGBA.Gray);
    sun2.setDirection(lightDir2);
    main.getSceneNode().addLight(sun2);

    Vector3f lightDir3 = new Vector3f(0.5f, 1.0f, 0.5f).normalizeLocal();
    DirectionalLight sun3 = new DirectionalLight();
    sun3.setColor(ColorRGBA.Gray);
    sun3.setDirection(lightDir3);
    main.getSceneNode().addLight(sun3);

    Vector3f lightDir4 = new Vector3f(-0.5f, 1.0f, 0.5f).normalizeLocal();
    DirectionalLight sun4 = new DirectionalLight();
    sun4.setColor(ColorRGBA.Gray);
    sun4.setDirection(lightDir4);
    main.getSceneNode().addLight(sun4);

[/java]

i have created a test case project to download here :

NormalMapTest.zip

i understand that 4 lights the way i set up would lead to lack of nuances in the normal map,

but so much, that it would be inverted on some faces and invisible on others… seems strange to me

can someone enlight me why it is not working with 4 lights ?

thx

@curtisnewton said: i dont get it,

after investigating a bit, i noticed the proble occurs is i change my light setup

this is working, having the same bumpiness on each faces of a cube

[java]
Vector3f lightDir2 = new Vector3f(0.5f, -1.0f, -0.5f).normalizeLocal();
DirectionalLight sun2 = new DirectionalLight();
sun2.setColor(ColorRGBA.Gray);
sun2.setDirection(lightDir2);
main.getSceneNode().addLight(sun2);

    Vector3f lightDir3 = new Vector3f(-0.5f, -1.0f, 0.5f).normalizeLocal();
    DirectionalLight sun3 = new DirectionalLight();
    sun3.setColor(ColorRGBA.Gray);
    sun3.setDirection(lightDir3);
    main.getSceneNode().addLight(sun3);

[/java]

this ain’t

[java]
lightDir = new Vector3f(-0.5f, -1.0f, -0.5f).normalizeLocal();
sun = new DirectionalLight();
sun.setColor(ColorRGBA.Gray);
sun.setDirection(lightDir);
main.getSceneNode().addLight(sun);

    Vector3f lightDir2 = new Vector3f(0.5f, -1.0f, -0.5f).normalizeLocal();
    DirectionalLight sun2 = new DirectionalLight();
    sun2.setColor(ColorRGBA.Gray);
    sun2.setDirection(lightDir2);
    main.getSceneNode().addLight(sun2);

    Vector3f lightDir3 = new Vector3f(0.5f, 1.0f, 0.5f).normalizeLocal();
    DirectionalLight sun3 = new DirectionalLight();
    sun3.setColor(ColorRGBA.Gray);
    sun3.setDirection(lightDir3);
    main.getSceneNode().addLight(sun3);

    Vector3f lightDir4 = new Vector3f(-0.5f, 1.0f, 0.5f).normalizeLocal();
    DirectionalLight sun4 = new DirectionalLight();
    sun4.setColor(ColorRGBA.Gray);
    sun4.setDirection(lightDir4);
    main.getSceneNode().addLight(sun4);

[/java]

i have created a test case project to download here :

NormalMapTest.zip

i understand that 4 lights the way i set up would lead to lack of nuances in the normal map,

but so much, that it would be inverted on some faces and invisible on others… seems strange to me

can someone enlight me why it is not working with 4 lights ?

thx

How did you make the cube?

And actually… some of your lights shine up from the bottom so I’d certainly expect some normal maps to look “backwards” from that perspective. Like, you have lights that are the exact opposite of some of the other lights so of course those normal maps will look completely opposite of the other sides.

Why do you need this strange lighting setup?

<cite>@pspeed said:</cite> And actually... some of your lights shine up from the bottom so I'd certainly expect some normal maps to look "backwards" from that perspective. Like, you have lights that are the exact opposite of some of the other lights so of course those normal maps will look completely opposite of the other sides.

Why do you need this strange lighting setup?

wel i had only one light, but only 3 faces where lit

so i thought adding lights on 4 sides, all pointing to the center of the cube an downward

code fo the cube

[java]
Box box= new Box(1,1,1);
Geometry boxGeo= new Geometry(“”, box );
Material mat= new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
mat.setTexture(“NormalMap”, assetManager.loadTexture(“Textures/normalmap.png”));
boxGeo.setMaterial(mat);
TangentBinormalGenerator.generate(box);
rootNode.attachChild(boxGeo);
[/java]

i try to have the same directional light influence on 4 directions
i must habe been trying to setup light a bit like in blender to have light coming from different directions

yep that was the problem, i must have had som shit in my eyes

thx for the help :slight_smile:

Sounds like you need an ambient light if you want more realistic lighting. One Directional and one Ambient is enough to simulate an outdoor scene, for example.

I wanted to ask a question related to this issue - so I’ll do it here:
Would it be possible to add a normal map converter into the SDK?
It should not cost that much of an effort for the programmer who is most familiar with this.
I would implement it myself if I were even close to being ready for jME SDK development.
The Nodes-Pipeline for Blender that is being suggested by the wiki page is a very ugly solution.

@Ogli said: I wanted to ask a question related to this issue - so I'll do it here: Would it be possible to add a normal map converter into the SDK? It should not cost that much of an effort for the programmer who is most familiar with this. I would implement it myself if I were even close to being ready for jME SDK development. The Nodes-Pipeline for Blender that is being suggested by the wiki page is a very ugly solution.
There's no such thing as a "normalmap converter". In 99% of cases the normalmap will have to be edited by an artist after going through such a process.

There is a normal map generator in the sdk, open the image with the image editor (right-click). It kind of expects a bump map but normal diffuse maps can also work somewhat.

@Momoko_Fan I mean just a button like “Blender normal map to jME normal map”, that inverts said channels and overwrites the source image file.
But, yeah, it is more a ‘cosmetic feature’ and would possibly ruin the view in Blender, if some people save their Blender models and textures to the assets path of jME.

@normen Very cool! I know that there are tools like that out there, working also for photos. So, I can simply render a displacement map in Blender and use it as input? I will try this eventually and compare it to the quality of the normal maps that are directly rendered by Blender.