Normal Map Lighting - help

The place for artists, modellers, level designers et al to discuss their approaches for creating content for OGRE.
User avatar
semicolon
Halfling
Posts: 94
Joined: Sun Jul 04, 2004 4:42 pm
Location: Bangkok, Thailand
Contact:

Post by semicolon »

Hi all,

I still have some questions about normal map. Is the "tangent vector" and "tangent edge" the same? If not, what are the difference between them?

Thanks,
Semicolon
"Nature is the mother of learning"
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

First you'll have to define what a 'tangent edge' is - I've never heard the term before.

Normal mapping requires a way to orient all vectors into a consistent space - and typically, repeating normal maps are in tangent space, that is the same space as a texture with the Z pointing directly 'out' towards you. A tangent vector expresses the local X axis of the surface as determined from the UV coordinates. Together with the vertex normal you can calculate the 3 axes representing the local space at the surface (the local Y is called the binormal). You can then transform light vectors into that space and perform operations between them and the normal from the normal map.

Note that you don't always need tangent vectors to do normal mapping. Normal maps can be stored in tangent space, object space or even world space. Normal maps are most generally applicable when stored in tangent space, which is why most examples (including ours) do it that way - but if you have more specific cases you can cheat a little.

For example, a 'tiled' normal map which can be applied to any model needs to be in tangent space so as to be generalised to any mesh, and the mesh will need tangent vectors. A normal map that's designed for a single model (e.g. the sort generated from Melody) could be stored in object space, and then with a modified shader you could skip the tangent space bits and use the object-space light directly, so you wouldn't need tangent vectors. Lastly, if you have world geometry that's completely static, you can use world-space normal maps and use world coordinates for everything (I've used this in a terrain system before), again not needing tangent vectors.

HTH
User avatar
semicolon
Halfling
Posts: 94
Joined: Sun Jul 04, 2004 4:42 pm
Location: Bangkok, Thailand
Contact:

Post by semicolon »

Thank you Sinbad. This is very valuable information about normal mapping. It really makes me clear.

By the way, Tangent edge is shown to me from the Orge exporter in MAX. That's why I keep asking about the real meaning and use of it. Then I thought Tangent edge and Tangent vector is the same. Also mentioned by Ryan of how he tried export his models with tangent vector from the MAX exporter. (Sorry if I might understand it wrong.)

Semicolon
"Nature is the mother of learning"
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

i've never heard of tangent edge, where did you hear about it?
User avatar
semicolon
Halfling
Posts: 94
Joined: Sun Jul 04, 2004 4:42 pm
Location: Bangkok, Thailand
Contact:

Post by semicolon »

Sorry I think I might mess up myself. I just checked the exporter it said Tangent vector and edge list. :oops: Hmm... :roll:

Semicolon
"Nature is the mother of learning"
User avatar
PeterNewman
Greenskin
Posts: 128
Joined: Mon Jun 21, 2004 2:34 am
Location: Victoria, Australia
Contact:

Post by PeterNewman »

Well, as part of this ongoing saga we finally got a chance to actually play with this.

As far as we can tell, the tangents are being made wrong. We bring out a model and the normals look fine (shading is smooth etc). We convert it to XML then reconvert it to mesh using -t -e (non manifold mesh). Then apply normal mapping, and poof, shading all over the place. Basically looks like the old "smoothing groups" problem, except it only shows up AFTER generating tangent vectors.

Need to make a debugging tool that'll display vertex normals and tangents or something, so we can see whats going on, but no time, no time! We have the vertex-lit version that "will do" but we're trying to get the normal mapping/fragment program lighting back in if we can!

This said, we are using the 0.15.1 OgreXMLConverter, the most recent model exporter (we think, not sure on that, no later then 0.15.1 for sure). Were there known issues back around this time that have been fixed since?
User avatar
semicolon
Halfling
Posts: 94
Joined: Sun Jul 04, 2004 4:42 pm
Location: Bangkok, Thailand
Contact:

Post by semicolon »

Hi PeterNewman,

As I have talked with the Author of the exporter, Banania. The option for generating "Tangent Vectors" is just to run the "OrgeXMLConverter.exe"

Semicolon
"Nature is the mother of learning"
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

There is a newer version of OgreXmlConverter etc, 0.15.2, but the main changes were enhancements to the edge list builder.

The Athene model was built with the '-t' option on the OgreXmlConverter (I regenerated all the models in 0.15.2 by converting them to XML and back again), and the very same code is used to generate tangents for the knot and the Ogre head in the Demo_Dot3Bump demo. So I'm surprised you've had problems.

Can you confirm that you have correctly configured texture coords on your model? Are you using multiple texture coord sets? I hope you didn't feed the model through the -t option more than once, too - the tool warns you about that but you can override it.
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

the model is a model within a model, however when the model is exported by itself its fine (when generating tangent vectors) but when attached to another object(making it one whole model) it doesn't generate the vectors correctly. Could generating tangent vectors have a limitation when it comes to object complexity? does it matter how many verts/faces the model has?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Looking at the code, it might not calculate the tangents properly if you have > 1 submesh which both share the same vertex data, and the usage of the shared data does not overlap. This is because it marks the shared vertex data as 'done' after having processed one of the submeshes which uses it, but if the submesh only used a subset of the shared geometry it effectively hasn't finished.

You can get around this by making the geometry for each submesh dedicated instead of shared, which is worth it in any case if the submesh usage is distinct. Multiple submeshes does work - that's confirmed by the fact that the Ogre head normal maps just fine (it's 4 submeshes). And no, face / vertex count doesn't matter.
User avatar
hebdemnobad
Goblin
Posts: 274
Joined: Wed Feb 09, 2005 5:09 pm
Location: catskill escarpment, new york, usa
x 3
Contact:

Post by hebdemnobad »

hello sinbad if you have a moment i am encountering a related difficulty...i have gotten normal maps to work fine, but i am at a loss for figuring out how to add a specular pass to the .material script that i am using for the www.pelicancrossing.com project. the post is

http://www.ogre3d.org/phpBB2/viewtopic.php?t=9182

long live cthulu and all the shamblers from the stars, once the stars are right
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Please don't double-post, I pick up all threads.
User avatar
hebdemnobad
Goblin
Posts: 274
Joined: Wed Feb 09, 2005 5:09 pm
Location: catskill escarpment, new york, usa
x 3
Contact:

Post by hebdemnobad »

understood
Chris_with_a_Gun
Greenskin
Posts: 106
Joined: Wed Nov 24, 2004 5:58 pm

Post by Chris_with_a_Gun »

Hi,

how can I convert object space normals to tangent or world space? I suspect my "strange lighting problems" there. When using the interpolated vertex normals, everything is fine with lighting and shadows. When I use a normal map the enhancements to the way the surface structure looks, are amazing - but something seems to be wrong with the lighting. The object is rotating and the light is fixed. But the lighting and shadows on the mesh do not change - despite every angle the object is headed. On the other hand the lighting and shadowing change, if I move the camera.
Chris_with_a_Gun
Greenskin
Posts: 106
Joined: Wed Nov 24, 2004 5:58 pm

Post by Chris_with_a_Gun »

I figured something out myself :)

gl_NormalMatrix * myNormal solved my problem from above

My normal map is in world space, and now I've converted my sampled normal into object space, right? And that would mean gl_Normal is also world space? But how do I get a tangent space normal into object space?

thanks alot
Post Reply