Hard Light Productions Forums

Modding, Mission Design, and Coding => The Modding Workshop => Topic started by: Vengence on August 05, 2010, 05:12:50 pm

Title: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 05, 2010, 05:12:50 pm
Hey all, I've been having just a few issues and nagging questions with normal maps and UV layouts.

I've had a small history with this issue. Basically the number one problem is SEAMS. But in this case the seam problem goes into outright lighting issues! Basically if you split a model in half, UV and skin one half of it then normal map it... you will get a NASTY seam right down the middle. One side is highlighted, the other is shadowed. This is a nasty nasty effect that looks just plain horrible. Here is my problem model and one other example I have had in the past:

http://img84.imageshack.us/img84/1843/blizzardnormal.jpg

Compare to the heightmap I converted

http://img31.imageshack.us/img31/8090/blizzardheight.jpg

To the UV Map

http://img227.imageshack.us/img227/4336/blizzardbumpmap.jpg

Contrast to this similar issue

http://img828.imageshack.us/img828/8689/rampanterror.jpg

The problem is a combo UV - Normal map issue. Let's consider this, a normal map adjusts the normals of a model to create an illusion of depth which corresponds to the colors of the UV Map. The ship model has been mirrored across the middle with the engines mirrored side to side and vertically and given the UV map's orientation and arrangement I believe it logical that given the normal map's conversion to the UV's orientation and the model's mirrored body... it seems to have created a mishmash of normal directions, causing what should be shining white to shadow darks. This also reflects in models with lots of UV seams, creating nasty visible seams on models.

I have been working on a partial solution to this and the wings and body SHOULD be resolved... but my worry is the engines, maybe more too. They seem to change in their lighting radically, possibly as a result of being mirrored. This is kind of a scary issue given that the engines dominated a large part of the old UV map, I wouldn't want to UV each engine. Frankly I just don't know what to do. I could resolve these issues one at a time, creating a gigantic UV map to accommodate a properly UV oriented map with few mirrors but I kinda need some advice here...

For one: What sort of UV orientation should I use? If the ship is pointing along the X Axis, what direction in the UV map should the ship be oriented? Pointing up? Or to the sides? Or even down? Are there any solutions regarding the engines? Or possibly eliminating the whole seam issue while retaining the mirroring? Should I Just screw normal maps altogether with this model and save me time by using parallax mapping?
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Thaeris on August 05, 2010, 05:32:47 pm
I'll regret to tell you that I don't know what to do about the problem, but what model is that? It's really impressive!
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Droid803 on August 05, 2010, 05:35:42 pm
I'll regret to tell you that I don't know what to do about the problem, but what model is that? It's really impressive!

Thaeris: http://www.hard-light.net/forums/index.php?topic=62856.0, http://www.hard-light.net/forums/index.php?topic=61889.0
Be amazed. Vengeance makes awesome stuff.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: General Battuta on August 05, 2010, 05:39:45 pm
I am 95% sure there's a fix for this issue. PM Vasudan Admiral, he'd probably know. Or Water. Or one of those old hands!
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Droid803 on August 05, 2010, 05:46:01 pm
Or both, you mean?
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 05, 2010, 06:34:45 pm
It's really impressive!
Thanks for the compliment, this tends to happen when you find someone who happened to enrolled in an art college.

I'll PM our Vasudan leadership then, I pray this is a simple fix as I tell ya this UV-Normal map issue has haunted me for years.

I forgot to mention this little dilemma that trying to fix these UVs I had. I UVed with saving space in mind, hence the mirroring but as it is the results are terrible  :shaking:. Now.... I can fix this the old fashioned way but I'd need a bigger UV map. My old UV map is 2048x1024 and was made several years ago, with some time and skill I can probably conserve more space but to fix the normal maps I'd need a biiiiiig UV map... I'm talking 2048x2048, and for a FIGHTER! Now in FPS terms, this is somewhat okay but for a space sim... I am unsure. The fighter model as it is now is 18,000 tris, I have an optimized model in the works which shaved off 2000 tris but.... even at 15,000 tris and a 2048x2048 map.... goodness folks can our beloved FS2Open contain this? Even if aggressively LODed? On that note I have a beast of a capital ship about to hit 50,000 tris and it isn't even done yet.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: The E on August 05, 2010, 06:41:57 pm
A single 2048^2 map is not a big deal. With the way FSO handles these things, the absolute number of textures has a greater effect than the resolution of the textures.

For reference, there's a model coming up in War In Heaven that has about 86k polies in detail0, the new Hatshepsut weighs in at ~20k polygons.

The engine can handle models at that level of detail just fine, provided the texture count is reasonably low.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 05, 2010, 06:49:45 pm
Okay... on that word just to clarify... if a 15,000 tri model with aggressive lodding (5000 LOD1, 500 LOD2, 50 LOD3 ect) with a single 2048x2048 with all shader and glow textures is okay? Well I feel a bit better now  :D.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: The E on August 05, 2010, 06:59:36 pm
That will be perfectly fine. I wouldn't recomment using dozens of them in a mission, but they shouldn't pose that much of a risk.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Scooby_Doo on August 05, 2010, 07:07:28 pm
I have a hard time telling which direction normal maps are facing but are they facing the opposite direction on each side?

If so then you must either map both sides individual or split them (resulting in smoothing problems you complained about).  Objects with attached vertices (the main hull in this case) cannot share uv space.  The wing pods (provided their seperate subobjects) can share the uvspace since they're not connected.  Unforunately it's a pain in the ass and bad for texture space.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 05, 2010, 07:18:32 pm
I have a hard time telling which direction normal maps are facing but are they facing the opposite direction on each side?

If so then you must either map both sides individual or split them (resulting in smoothing problems you complained about).  Objects with attached vertices (the main hull in this case) cannot share uv space.  The wing pods (provided their seperate subobjects) can share the uvspace since they're not connected.  Unforunately it's a pain in the ass and bad for texture space.

It is most likely possible that they are opposite but when I look at it they don't LOOK opposite. On the secondary example I showed, a character I called Rampant, had opposite normals along the seam down his back and shoulders. I do indeed believe mapping both sides may be my only remaining choice for best normal map presentation at this point.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: blowfish on August 05, 2010, 07:55:55 pm
I think a workaround to this problem may have been implemented in FSO's rendering engine.  Not sure about that though.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Water on August 06, 2010, 04:47:10 am
it seems to have created a mishmash of normal directions, causing what should be shining white to shadow darks. This also reflects in models with lots of UV seams, creating nasty visible seams on models.

For one: What sort of UV orientation should I use?
UV orientation is not important. The normal map uses whatever uv's you provide.

The simple way to sort the mirror seam problem is to not have the mirrored parts meet.
(http://i229.photobucket.com/albums/ee67/waternz/uv/UV-mirror.jpg)
Other than that mirrored parts shouldn't cause any problems. Any issues in that area may be an export problem rather than a normal map problem. If you pm an obj and normal map I can send a different version back to verify the issue.
(http://i229.photobucket.com/albums/ee67/waternz/mesh/max-export1.jpg)
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 06, 2010, 08:19:01 am
I did some tests, seems like orientation might not be the big cause I thought it was, but what still stumps me is why the lighting on some parts of the model are so off. The model hasn't been exported or anything. I found a small problem was an exaggerated normal map setting but it hasn't fixed a lighting issue and could potentially look really odd ingame.

notice the highlight on the normal mapped wing is reversed that of the non normal mapped. Well maybe not 'reversed' but why is it not visible. Also notice the thing attaching the gun to the wing one the right wing (its right) is shiny bright but moot dark on either side.
(http://img339.imageshack.us/img339/2433/reversedlighting1.jpg)
(http://img228.imageshack.us/img228/4937/reversedlighting2.jpg)

EDIT:
Well in any case, to fix the central seam problem I'll have to remap the UVs some. The biggest plus to this would be some more space to work with and all. Well thanks for your feedback in any case.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 06, 2010, 06:34:59 pm
I figured I'd turn this into a progress blog or something. For all I know some of those who are new to UVing may find this entertaining watching me suffer burning in UVW Unwrapping hell.

In my line of work, UVing is a half boring, half fun process. Boring in that you don't see any effing progress. Fun in that it is simple to do. Finally frustrating in that it takes so long to do. Here is the progress on the new UV Map

(http://img444.imageshack.us/img444/372/uvmap.jpg)

The new feature to this UV map over the previous one is that it is going to be 2x the size of the previous one so I won't be drawing lines 1-2px thin anymore. Also with darned luck I may be able to stuff most of the stuff into the map. But at this rate I am unsure. The good news is that I have the vast majority of VISIBLE space unwrapped onto the UV map with 1/4 space remaining for everything else. The bad news? All that remaining space is left for the engine pods, missiles, wing cannons, and nose cannons. All of which are some of the most polygon intensive and detailed parts of the models.

The key to making a good UV map is putting as much space as possible to what is very visible and going small on small details that aren't likely to be seen. As indicated, the main hull of the fighter occupies almost 2000 pixels in height and width. Meaning the body's resolution will most certainly be as sharp as possible. That is good ya? I hope so. The worry I am having is stuffing the rest of the model in that tiny space.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Water on August 06, 2010, 07:13:35 pm
notice the highlight on the normal mapped wing is reversed that of the non normal mapped. Well maybe not 'reversed' but why is it not visible. Also notice the thing attaching the gun to the wing one the right wing (its right) is shiny bright but moot dark on either side.
I have seen this happen  in a pof before, in a Max exported model. The highlights were on the opposite side to where they should be. It wasn't the normal map. You need to talk to some Max people first to solve it. I'm not sure how you save normals the wrong way in Max, but start there.

Title: Re: Help regarding Normal Map/UV Map relation
Post by: Aardwolf on August 06, 2010, 07:17:31 pm
Simply put, FSOpen's normal map shader is doing it wrong. I encountered a similar problem when I was implementing tangent-space normal mapping in a program of my own, and I think I know what the issue is...

For everyone else who doesn't, tangent-space normal maps (the kind FSO uses) work like this:

There's a normal vector (fairly straight forward, it's the direction "out" from the surface, possibly using the per-vertex defined normals, i.e. smoothing info. I don't know if FSO does that or not. Next, depending on the terminology you use, you could say there are 2 tangent vectors, or a tangent vector and a bi-tangent vector. These are basically vectors in the plane of the polygon which correspond to the u- and v- texture axes. Basically they're the directions in which u and v increase the fastest; the gradients of u and v with respect to position.

These vectors are normalized (meaning they're scaled to have a length of 1), and the shader lights the object as though its normal vector were the linear combination of these 3 vectors with the coefficients for the 1st tangent, 2nd tangent, and normal vector being the reg, green, and blue components of the normal map (of a traditional "blue" normal map, of course, not the converted green/alpha maps FSO uses), respectively.

I suspect the problem is this:

The 2nd tangent vector (sometimes called the bi-tangent) is often perpendicular to the 1st tangent vector; if the texture is not skewed at all, they are exactly perpendicular. Thus, a program can get away with using a cross-product (the cross product of two vectors is a vector guaranteed to be perpendicular to both of the two input vectors) rather than doing the potentially more expensive calculation necessary to compute 2 tangent vectors. However, if a model is mirrored (with accordingly mirrored texture coordinates), the direction of the cross product vector is opposite of what it is on the other side.

So really the program (or the vertex shader) just needs to calculate both tangent vectors.

I'll bring this to the attention of someone on the SCP, maybe it can be fixed and in the nightly builds soon.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 06, 2010, 08:19:21 pm
Indeed the model is mirrored, which is pretty much the problem. But I have little other choice but to submit to that problem. In 3DS Max I have 2 ways of trying to reset normals. There is reapply the smooth modifier which will allow you to set the normals on the model. Then there is Reset X Form which is handy for fixing nasty issues and transforms. I've tried this before, and same result on the model. I would UV both sides of the wing but that will eat up too much UV space.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Water on August 06, 2010, 08:51:10 pm
Mirrored uv's from Blender don't cause the issues you are seeing. Try this, export the model to obj, re-import to Max and you'll find the lighting issues have probably changed. 

Vengence, the lighting problems are in Max? or FSO?
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 06, 2010, 09:25:54 pm
Well the renders I supplied aren't exactly placed in a black background, so Max.

I tried the export to OBJ, did nothing. Well this could... hopefully just be a max problem. My new UV map won't have any seams but it will still likely have that reverse lighting issue if I am unlucky. In any case time will tell.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Commander Zane on August 06, 2010, 09:31:33 pm
It's good to see you back on with that amazing fighter. :D
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Water on August 06, 2010, 09:37:59 pm
Try a test export to pof, if there are no lighting issues, then you  are probably right about it being just a Max issue. Blender exports mirrored normals fine, but displays them inverted within Blender.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 06, 2010, 09:51:16 pm
Inverted? you mean backwards? Well Max also has a normal tool which can be used to invert normals. Perhaps I should give that export a try? Granted the model isn't born with holes in it... but that is basically what the normal tool does.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Water on August 06, 2010, 10:39:29 pm
Inverted? you mean backwards? Well Max also has a normal tool which can be used to invert normals. Perhaps I should give that export a try? Granted the model isn't born with holes in it... but that is basically what the normal tool does.
I mean the mirrored uv have their bumps inverted in Blender not the polys. The same thing can be achieved by inverting the green channel on the normal map.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Col. Fishguts on August 07, 2010, 05:38:32 am
I've also sometimes had this problems with normal maps. I got rid of it by not welding the mirrored parts together in the UVW editor. Map the offending parts separately, then do the mirroring manually in the UVW editor and stack the parts manually on top of each other, but don't do the "Weld selected" operation.

NOTE: I'm only referring to the "weld" operation in the UVW editor, not the geometry editor... the geometry stays perfectly solid, no detached polygons.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 07, 2010, 09:18:57 am
You know what? You may have a point Fishguts. I'll give it a go when I finish laying out the UVs before mirroring, then I'll remap the problem parts.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vasudan Admiral on August 07, 2010, 09:46:40 pm
Water's quite correct - the issue here is with 3ds, not your normal maps or geometry. Do a test conversion and see how it looks in FSO, because taylor figured out how to get FSO to flip the normal depth on the mirrored side already, which is pretty good. Not totally perfect as some lighting directions you'll still see the seam, but you won't get that inverted normals effect on one side. :)

I'm not a max user but apparently this doesn't happen with the symmetry modifier? Is that what you're using?
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 08, 2010, 11:58:14 am
No I just mirrored the model. And I think I have witnessed the effect in FSO. Indeed there is still a slight seam but it is nowhere near as pronounced as in max. This makes me cringe to think I spent all these hours making a new UV map to replace the old one XD. In any case, it is good to know this is a mostly Max issue. Saves my hide a good bit. Least I hope. In any case the final layout should look even better.... if I am lucky. It is getting quite cramped. I may have to create a second texture... which isn't such a good idea.

I think this is good progress except for one nasty issue. The engine and missile rack is most likely going to suck up the last of the UV space, no room for canopy or the fuselage cannons.
(http://img138.imageshack.us/img138/1420/cylinderuv.jpg)

EDIT:
I just put a few more things in, yup.... no more room. I gotta either shrink some stuff or make a second map.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on August 12, 2010, 11:43:46 am
Just a light bump for progress

Image is in 1080p HD so I'm not displaying the pic here (It'd eclipse the forum!)

http://img72.imageshack.us/img72/5434/blizzardrender.jpg

The only problem I made was again due to space issues... I really hope you folks are right about FSO eliminating the normals issue... Now the engines have that same seam issue, but up and down this time. Blah... well I hope this works.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Angelus on August 12, 2010, 01:48:52 pm
Just a light bump for progress

Image is in 1080p HD so I'm not displaying the pic here (It'd eclipse the forum!)

http://img72.imageshack.us/img72/5434/blizzardrender.jpg

The only problem I made was again due to space issues... I really hope you folks are right about FSO eliminating the normals issue... Now the engines have that same seam issue, but up and down this time. Blah... well I hope this works.


Looks good, that ship.  :yes:

And you can use the lvlshot tags for images, just qoute me to see how.

(http://img72.imageshack.us/img72/5434/blizzardrender.jpg)
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Aardwolf on August 13, 2010, 10:32:24 pm
Bleh. I tried to code a fix, but got frustrated and gave up.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Bobboau on December 08, 2010, 11:13:40 pm
Simply put, FSOpen's normal map shader is doing it wrong. I encountered a similar problem when I was implementing tangent-space normal mapping in a program of my own, and I think I know what the issue is...

For everyone else who doesn't, tangent-space normal maps (the kind FSO uses) work like this:

There's a normal vector (fairly straight forward, it's the direction "out" from the surface, possibly using the per-vertex defined normals, i.e. smoothing info. I don't know if FSO does that or not. Next, depending on the terminology you use, you could say there are 2 tangent vectors, or a tangent vector and a bi-tangent vector. These are basically vectors in the plane of the polygon which correspond to the u- and v- texture axes. Basically they're the directions in which u and v increase the fastest; the gradients of u and v with respect to position.

These vectors are normalized (meaning they're scaled to have a length of 1), and the shader lights the object as though its normal vector were the linear combination of these 3 vectors with the coefficients for the 1st tangent, 2nd tangent, and normal vector being the reg, green, and blue components of the normal map (of a traditional "blue" normal map, of course, not the converted green/alpha maps FSO uses), respectively.

I suspect the problem is this:

The 2nd tangent vector (sometimes called the bi-tangent) is often perpendicular to the 1st tangent vector; if the texture is not skewed at all, they are exactly perpendicular. Thus, a program can get away with using a cross-product (the cross product of two vectors is a vector guaranteed to be perpendicular to both of the two input vectors) rather than doing the potentially more expensive calculation necessary to compute 2 tangent vectors. However, if a model is mirrored (with accordingly mirrored texture coordinates), the direction of the cross product vector is opposite of what it is on the other side.

So really the program (or the vertex shader) just needs to calculate both tangent vectors.

I'll bring this to the attention of someone on the SCP, maybe it can be fixed and in the nightly builds soon.

when taylor was first writing up the normalmapping shaders we had a semi-longish conversation about this, at least what was being done 3 years ago was that a binormal vector was sent to the shader then the tangent was made from this (and the normal), i tried arguing that he should be sending both to the shader but all of the example code he was finding did not do this so I don't think I ever convinced him this was the right way to do it. I might have convenced him to add a 'handedness' scalar that would correct inverted normals, but it still would not have handled scewed UV space well. in any event this was three years ago, i have no idea how things are being done now and this is probably unrelated to how things are being done currently.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on December 08, 2010, 11:50:25 pm
What a necro  :). Well you have no worries now since Freespace 2 handles this even better than 3DS Max. This is a pic I have located on my laptop. I'm away from the computer with the source files.

(http://img404.imageshack.us/img404/2760/screen0035.jpg)

The issue with mirroring and normal maps WAS unavoidable. Really the only way to avoid it is through clever mapping and technique. But in Freespace 2 those effects are highly minimized, thank goodness.

Now I am no fan of locking topics, but considering the end results worked perfectly thanks to the amazing FSOpen engine, AND a great release fighter, I think we can consider this topic ended  :). Unless of course... there are questions to be asked? Feel free, but I suspect the topic has reached an end.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Commander Zane on December 09, 2010, 10:08:07 am
I don't think many people have noticed that there's a release for it on FSMods yet, you should spotlight it in-game some and give it some attention. :D
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on December 10, 2010, 09:59:42 am
I did sort of promote it in a topic with the eponymous title of "[Release] Blizzard Fighter" and showed a good bit of ingame screens. I only have the feeling that if I promote it again I'll be spamming XD. How shall I promote it further without sounding like I am an attention nut  :p?

Whoops... then again I didn't have any in game actiony pics... Well poo looks like I'll have to cook some up... oh wait I have pics  :)

(http://img189.imageshack.us/img189/8128/blizzardingame02.jpg)
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Black Wolf on December 10, 2010, 10:33:41 am
I did sort of promote it in a topic with the eponymous title of "[Release] Blizzard Fighter" and showed a good bit of ingame screens. I only have the feeling that if I promote it again I'll be spamming XD. How shall I promote it further without sounding like I am an attention nut  :p?

I think I can help with that :)

Quick question though, are those normal maps in the existing DL? If not, reckon you could update it? They're really amazing.
Title: Re: Help regarding Normal Map/UV Map relation
Post by: Vengence on December 10, 2010, 12:20:26 pm
Those should be the normal maps. I really only had two versions. One made from CrazyBump and one from Photoshop. The CrazyBump version was too.... bulging so I stuck with the photoshop's clean lines. Yes the final model should have those normal maps.

If it doesn't appear right it is probably the map I made in FRED. There are 3 suns, one is on the opposite side soooooo.... hehe yeah.

I just saw the post on the front page too. Thanks!  :D

Edit: If you wish, I can give you a small tutorial about some normal map techniques, but honestly my methods aren't too different than normal ones. All it was really was a ton of effort to make something good.