Author Topic: Normal maps  (Read 3091 times)

nalwesh

  • Jr. Member
  • **
  • Posts: 4
Normal maps
« on: June 19, 2012, 01:14:42 AM »
Hi
I just started using the viewer and it is quite nice and easy to use.
I would like to know if the normal maps should be in tangent or object space?
and since I am a newbie in normal maps excuse my next question but I noticed that if my normal map was normal.png  the viewer generates a normal.png#DOT3# image and was wondering what exactly is that? Thanks

Nawar

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Normal maps
« Reply #1 on: June 19, 2012, 10:43:50 AM »
The engine (and viewer) only support tangent space normal map.

In some model format, only height map is supported or specified. The #DOT3# appender convert the height map into a normal map during the texture loading. Let me know if your texture is already already a normal map, and the viewer wrongly tries to convert it using #DOT3#.

nalwesh

  • Jr. Member
  • **
  • Posts: 4
Re: Normal maps
« Reply #2 on: June 19, 2012, 10:13:37 PM »
Thanks for your quick reply. Unfortunately I generate  my normal map is in object space and need to find a way to convert it to tangent space, but from my reading it seems that each viewer has its own way of interpreting normal maps in tangent space, does that mean if I want to generate normal maps in tangent space and use the bonzai viewer that I need to know exactly how normal maps are interpreted in bonzai?


jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Normal maps
« Reply #3 on: June 19, 2012, 10:28:46 PM »
There's only one way to interprete tangent space. While object space normal map store normals in the model axis system, tangent space normal map stores normals in tangent space, which is an axis system local to a polygon (triangle).

The engine currently only implements shaders for tangent space normal map, but if you provide your own shaders which are working with object space normal, then it will work.

There's some tools like nSpace which are able to convert from object to tangent space.
If you send me a model with normal map in object space (use contact email), I'll give a look to at support for it.
« Last Edit: June 19, 2012, 10:30:47 PM by jerome_j »

nalwesh

  • Jr. Member
  • **
  • Posts: 4
Re: Normal maps
« Reply #4 on: June 19, 2012, 11:17:33 PM »
Thanks jerome_j for your quick reply and help. I have seen your link before and still abit confused and hope you can clarify some things for me. Also I am interested in generating my own normal maps in tangent space rather than using a converter. These are some questions I have:

1. After generating an orthonormal TBN for each face, do I then generate a TBN for each vertex by averaging the TBN's of all faces associated with a vertex?

2. Once I have a TBN system (ie after averaging) for each vertex, how do I compute the normal values of  a pixel within the face, do I use some interpolation method where I interpolate the normals in tangent space of all the 3 vertices associated with that face?

Thanks again for all your help, really appreciate it


jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Normal maps
« Reply #5 on: June 20, 2012, 08:24:53 PM »
I've received the model you've send. I'll give a look to implement shader to support object space normal map in our engine.

You see #DOT3# when opening in the viewer due to the fact your mtl material file assign a normal map to a height map, spec says:
Quote
The image used for a bump texture represents the topology or height of the surface relative to the average surface.  Dark areas are depressions and light areas are high points.  The effect is like embossing the surface with the texture.
We're converting the height map to a tangent space normal map on the fly with the #DOT3# appender.
To assign normal map in mtl file, you can use map_normal instead if you have control to the tool which generates the model.


Quote
1. After generating an orthonormal TBN for each face, do I then generate a TBN for each vertex by averaging the TBN's of all faces associated with a vertex?
After computing tangent vector of each face, you should compute the tangent for each vertex by averaging like for normal. Ie for a given vertex, sum tangents of all face using it and then average and normalize. To make sure tangent and normal are perpendicular, we're using a gram schmidt orthogonalization of the tangent relatively to the normal vector before the normalization.

Quote
2. Once I have a TBN system (ie after averaging) for each vertex, how do I compute the normal values of  a pixel within the face, do I use some interpolation method where I interpolate the normals in tangent space of all the 3 vertices associated with that face?
To convert from object to tangent space, basically you'll have to convert the texture from the object space (which you can consider as the usual x/y/z axis) to the tangent space system which is local for each vertex. This means, you'll have to browse all triangle, lookup in the normal texture for the triangle area used by the triangle uv. For each pixels within this area, compute the tbn space (interpolated between the 3 triangle vertices) and convert the original normal in tangent space.

The most easy way to implement that is probably using opengl directly (which can be done offscreen inside a batch tool): render the model unwrapped (similarly to UV tab of the Mesh panel of the viewer) with a specific shader which will have output the normal in tangent space. Then just copy the contains of the framebuffer in an image file.
« Last Edit: June 20, 2012, 08:29:51 PM by jerome_j »

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Normal maps
« Reply #6 on: June 20, 2012, 09:33:10 PM »
I have just added support for object space normal map.

A dev build will be soon available, in the meantime you can try the viewer applet which has just been updated with object space support. To enable it, go to shader generator tab and check 'Normal in object space' option (also remember you'll have to change map_bump to map_normal in your mtl file).

nalwesh

  • Jr. Member
  • **
  • Posts: 4
Re: Normal maps
« Reply #7 on: June 20, 2012, 10:19:15 PM »
Wow jermoe_j, thank you so much that is amazing, you have been of great help. Really appreciate it, made my life much easier by providing the object space option. Will try it out and also will follow your advice. I might also write some code for generating my normals in tangent space according to your explanation and test it out with your viewer. Will definitely keep you in mind for future consultancy work. Thanks again for all your help.