Problem with normal map

Hay guys,



I’m trying to allow users to use generated textures as normal maps.

I made the normal map texture out of the created texture and applied it, along with color texture, to the model.

Here is my result. As you can see there are some strange artifacts.



http://imgur.com/8ZQ1t



The result color texture looks like this:

http://imgur.com/gRLdG



And here is the normal map:

http://imgur.com/zTbgJ



The UV coordinates are identical. The color texture is stored as TexCoord buffer and normal map as TexCoord2 buffer.



And one more example of more advanced object:

http://imgur.com/13SR0



When I set only color texture everything looks fine.

Has anyone an idea what might be wrong??

I’ve never seen purple in a normal map?

The texture I used was very simple that is probably why the colors are purple. But nevertheless I will check the algorithm. Maybe it really messes something up.

Have you normalized the normal map? Those don’t look correct to me. If the whole map is uniform color like white, then the result should be 0.5, 0.5, 1.0 (or 127, 127, 255).

Even if the normal map is incorrect I think there is also another issue. I’m not sure but there may be some errors with the UV system in jme.



I made a model that used normal map that is 100% correct. It is a 2D image.

When I apply it to blender with another image as a color texture I get this:

http://i.imgur.com/dlKLp.png



And here is how it looks in jme:

http://i.imgur.com/A3zC0.png



I then changed the color texutre to simple 3D texture (Bllend texture) and that is my result in blender:

http://i.imgur.com/8ZhET.png



But that is how it looks in jme:

http://i.imgur.com/MYjb3.png



The UV coordinates of the normal map image were not changed. Only the color texture was different.



So it is possible that my normal maps are not entirely correct but there is something wrong with the UV system as well.

The color textures UC coordinates are stored as TexCoords while normal map UV’s as TexCoords2.

the 1st one looks ok to me the only problem is that the green channel of the normal map should be inverted.



The second one is totally screwed up but i don’t have a clue of what it is in the first place in blender. A 3D normal map?

The last one’s texture coordinates are all messed up, it looks like.



Something to keep in mind… some of us manually construct our geometry and give them perfect normals, tangents, texture coordinates, etc. and they render 100% perfect. So if you see results like the above then it’s something wrong with the mesh data.

assetManager.loadTexture( new TextureKey(“Textures/normal.jpg”, false)); ? … all though in your screensshot the texture looks super zoomed in.


@Kaelthas said:
The color textures UC coordinates are stored as TexCoords while normal map UV's as TexCoords2.


Perhaps it's using TexCoords (not TexCoords2) for the normal map also ? I've never used different coords like that.

JME materials use TexCoord for all of the textures: diffuse, normal, and bump.

@nehon said:
The second one is totally screwed up but i don't have a clue of what it is in the first place in blender. A 3D normal map?

The normal map is a flat texture. The color is created from a 3D generated texture but in the end it is a 2D texture attached to the model. So nothing different from the correct example.

@thetoucher said:
assetManager.loadTexture( new TextureKey("Textures/normal.jpg", false)); ?

Nope, that didn't help. But you're right it looks like heavily zoomed in. No idea why.
When I do not use any other texture the result is quite the same as with 3d texture.

@pspeed said:
JME materials use TexCoord for all of the textures: diffuse, normal, and bump.

OK I can try to transform the texture to the UV's used by color texture. But then I have no idea why do we need more TexCoord types ???
I thought that I can use it to add another texture with different UV's.

OK I think I know what is wrong here.

The normal map maps itself on the given color texture and not on the mesh’s faces.



I made an experiment and applied a color and normal textures both using user’s defined UV’s.

The result looked OK the shadows appeared where they should.

And then I altered the UV’s of the color texture. I applied cube projection on the model.

To my surprise the shadows were in the places where they were expected even though the color texture looked completely different on the model than before.



Is there a way to change that behaviour? Can I make UV’s to map themselves on the faces rather than on the color texture ??

@Kaelthas said:
But then I have no idea why do we need more TexCoord types ???

We use TexCoord2 for light maps only.
The thing is...you can have plenty of different set of texture coordinates but you have to use them in your shader.

As Paul mentioned Jme's lighting material use TexCoord for diffuse, normal, specular, and parallax maps, then it optionally uses texCoord2 for light maps if you checked the "separatedTexCoord" attribute.

If you want the loaded model and texture to work with the lighting material it has to follow those rules.
@Kaelthas said:
OK I think I know what is wrong here.
The normal map maps itself on the given color texture and not on the mesh's faces.

I made an experiment and applied a color and normal textures both using user's defined UV's.
The result looked OK the shadows appeared where they should.
And then I altered the UV's of the color texture. I applied cube projection on the model.
To my surprise the shadows were in the places where they were expected even though the color texture looked completely different on the model than before.

Is there a way to change that behaviour? Can I make UV's to map themselves on the faces rather than on the color texture ??

By shadows you mean with the PSSM or BasicShadowRenderer? If you use those, the textures do not use the uv of the mesh, they are projected on them with a projection matrix.