Home Technical Talk

Object space vs. tangent? (Character model)

Hey guys, first post. Sorry of this has been covered, but I'm pretty new to the whole normal mapping game and basically I've modelled a character and detailed in ZBrush. Basically, I've generated both tangent and object space normal maps for the character. I think that the object space looks pretty good and makes the low poly model look quite high, whereas the tangent IMO doesn't appear to look any better than a generic bump map.

I'll post renders later (my net on my 3D computer's playing up at the moment) but I'm trying to figure out if I'm doing something wrong? The tangent space normal still have the low-poly character look low-poly, but a with a few details I could have painted as a bump map in a few minutes compared to the time it took to ZBrush everything.

I've been reading that object/world space normals cause odd shading problems if animated, though upon a quick test I couldn't see anything particularly off when the model was deformed.

Replies

  • Jay Evans
    Offline / Send Message
    Jay Evans polycounter lvl 18
    Depends on the game engine, but for the most part these days every game I've seen is using tangent on the characters. So if you are planning on eventually putting things in a game engine, I'd take the time to learn how to make tangent space maps work for you. They should look identical if setup properly.
  • Rob Galanakis
    You are probably generating your tangent space incorrectly if there is a significant difference (if in zbrush you are generating it at a subdivision level higher than 0). Object space normals will look nicer (at least I've heard) because they are more explicit and don't need to rely on surface normals, while tangent space are relative to the surface normal. But OS normal maps cannot deform... it isn't just a shading problem, it is that they become entirely wrong when they deform.
  • Ryan Clark
    Offline / Send Message
    Ryan Clark polycounter lvl 18
    The professor is right; if it's an animated character, you need to use tangent-space.
  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    btw, although tangent-space of course is used in like 99% or so for characters. It is not correct that object space couldnt be used. After all its just another "space" and animation transforms could be applied as well. Think of the pre-pixel lighting era, where just vertex normals were animated/deformed, and those are stored in object space as well.
  • Kevin Albers
    Offline / Send Message
    Kevin Albers polycounter lvl 18
    I've never seen a game asset use world-space normal maps.
    My guess is that one of your tangent space channels is flipped. You might try inverting the green channel and seeing if that corrects the issue.
  • Eric Chadwick
    Earthquake has been using object-space maps for his weapon models. I remember him swearing by them. I mean in a good way. smile.gif
  • EarthQuake
    I remember we did a test with deforming objects, we just took a prop and added very simple skining and bent it back and forth. The lighting seemed to transform correctly but we never really tested it extensively because there was no need to use it with organics, and we mirror a lot of stuff on our character models.

    The way i seem to remember it being explained to me as that the "theoretical problems" with deforming object space stuff actually exsist with deforming tangent space stuff as well, but it works fine there too obviously. Now i may be completely miss-quoting here and talking out of my ass, i'll try to get a better explanation.


    But having said all that, really there just isnt much reason you should use object space on a character, unless it is a robot or something that is completely hard edged, then it would be a better use.

    [edit] ok got a decent quote here

    EarthQuakeblah: can you write a little bit about what your final conclusion was in regards to deforming object space normals? I cant really remember what you told me
    jeffrussell: ah
    jeffrussell: object space normals: you can deform them
    jeffrussell: simply requires a bit more work in the pixel shader
    jeffrussell: but allows for faster geometry processing, so its about a wash
    jeffrussell44: faster geometry because you dont have to send tangents/bitangents etc
    EarthQuake: is the idea that all the data is already there for doing the math, since you just keep track of the vert transformations with the rigged mesh? and just use that to figure out the correct lighting?
    jeffrussell: right, basically we have to xform vert normals and tangents etc by the transform matrices that result from skeletal animation anyways - what you can do instead is transform each pixel in the normal map instead
    jeffrussell: so again, that moves work to the pixel shader
    jeffrussell: but it can be worth it
    EarthQuakeblah: ok cool, thanks!
  • Eric Chadwick
    I wonder if you'd have see some major lighting weirdness when the character lifts their arms above their head, like any bone rotation that's very different from the davinci pose. The object-space colors would seem to be very different from the regular world-oriented colors. Dunno, don't have any experience with object space maps.
  • EarthQuake
    Yeah i think crazybutcher brought up that issue the last time we were talking about this, and i think i was told that issue would be/is also present when deforming tangent space normals as well, but cant recall.
  • Eric Chadwick
    I don't think so. The nature of tangent space mapping is that when the verts are deformed so are the tangents, and the lighting space is being transformed using those tangents, on every frame. AFAIK object space doesn't use per-vertex tangents.

    I think there's a method to convert object space into tangent space, might be the way it's done.
  • EarthQuake
    Well we have the shader in there now, suposedly working. I'll have to just take one of our characters, convert a tangent space map to object and throw some animations on it and see what happens, i'll see if i can get permision to post the results when i get around to doing this.
  • Ryan Clark
    Offline / Send Message
    Ryan Clark polycounter lvl 18
    @CrazyButher: Sure it's possible to animate object-space normals, but it's more expensive because you need to deform them per-pixel.

    With tangent-space normals, only the basis vectors need to be animated. That's an inexpensive per-vertex operation. That's why everybody uses tangent-space normals for animating objects.

    Uncorrected, the lighting problem looks the same in both cases. But it's cheap to correct using tangent space, and more expensive to correct using object space.
  • Eric Chadwick
    Thank god for programmers who can set us fumbling artists straight. smile.gif
  • Jay Evans
    Offline / Send Message
    Jay Evans polycounter lvl 18
    All the BF characters I did had world\object space maps. Its rare, but it works just the same if your engine is set up for it.

    Here is a dude back from early 04 :P When normalmaps.. and my knowledge of them were pretty new haha
    http://media.pc.ign.com/media/568/568737/img_1942917.html


    These days I only see tangent space maps being used.
  • Ryan Clark
    Offline / Send Message
    Ryan Clark polycounter lvl 18
    Interesting!

    Maybe I'm wrong about deforming object-space normals being expensive then.
  • Rob Galanakis
    Well think about what you would need to do to deform with OS normal maps.

    Currently we take our Normal (and if not using tangent space lighting, tangent and binormal), transform them based on the bones, then either convert the normal to tangent space, or transform each vector to world space.

    In the pixel shader, we use the normal map as-is if using tangent space lighting, or if we are using WS lighting we multiply our WS vectors by our normal map.

    So maybe we are wrong, if we are doing WS lighting we can use OS normal maps? Either way we are getting a transformation matrix to transform our normals in our pixel shader- as long as we have the correct matrix to do so, we should be alright?

    I do feel like I'm missing something, though.
  • Jay Evans
    Offline / Send Message
    Jay Evans polycounter lvl 18
    Anyway.. all of this doesnt even really matter, because tangent space maps are about 1 billion times easier to edit, blend, mirror, rotate, and touch up than object space maps. So using anything else is tying one hand behind your back as an artist.
  • EarthQuake
    It really depends on what you're doing, if its mechanical stuff object space is about 1 billion time easier to create lowpoly meshes for, and render nice clean distortion free normals for, whereas trying to get a tangent space map working on a complicated weapon for example, without tripling the tricount and having horrible seams or bad smoothing errors is like tying one hnad behind your back. =)
  • Jay Evans
    Offline / Send Message
    Jay Evans polycounter lvl 18
  • EarthQuake
    All that said its great if your engine supports both, because they are both definitely useful in their own ways =)
  • Rob Galanakis
    Well it'd be pretty simple, really, just a material flag (or even a boolean) that would say whether to do the calculations for object or tangent space normals, which shader to use, etc. The idea of an 'engine supporting' shader tech as such as really a popular misnomer... it is just a matter of adjusting the material pipeline (data from the export, and shaders). I'll ask the graphics guy at work tommorrow and maybe do some experiments tonight... I'm quite convinced it can work (as EQ's gfx guy said) but I'd like a working example.
  • EarthQuake
    Yeah thats all we have, a little tag in the material file to use tangent or object.
  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    there is no reason it shouldnt work. As said there were animated vertex normals, now with OS-normalmap it's the same, just on pixel level.

    You can think of those spaces as a "axis cross" with 3 vectors for each major axis. Whether you feed 3 vectors to transform tangentspace to worldspace, or objectspace to worldspace makes no difference here. It's rotating the stored normal to a new orientation to take transforms into account.

    What is cheaper is rotating the "tolight" vector in tangentspace on vertex level, and send that vector to pixelshader in which you just do the angle calculation with the stored tangentspace normal. Which is what Ryan suggested.
    However modern pipelines do all lighting stuff on pixelshader level (and mostly worldspace, UE3 & Crysis for sure). Because it's better to handle multiple lights, especially with branching support. So they only send "tangent to world" matrices and the world position to pixel shader. And you can send "object to world" just as well.

    a benefit from using OS is that you need less vertex attributes to be sent from application to vertex shader (ie no tangent/binormal). Which means less storage costs for meshes / faster upload of dynamic data. I guess I need to make some AAA eyecandy demo with luxinia to give my words some more gravity wink.gif
  • Ryan Clark
    Offline / Send Message
    Ryan Clark polycounter lvl 18
    Is a single object-to-world matrix sufficient when your object is changing shape?

    Vertices are moving around inside your object. Their movement is not reflected in your object-to-world matrix. So if you're lighting correctly, then you must be doing something to account for the movement of vertices.

    EDIT: I think I understand... do you mean that you're supplying a different "object-to-world" matrix from each vertex, to account for its deformation? So it's more like a "vertex-to-world" transform passed into the pixel shader?
  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    yes, hence I said the vertex-shader sends the data to pixel-shader (so it is per vertex). But strictly speaking of "spaces" it remains objectspace to worldspace (object to deformed object to world / object to deformed world, depending on how bone matrices are fed from CPU).
  • Michael Knubben
    "Nerds on Valentine's Day: a revealing documentary"

    This is very interesting to follow, though. I'm far from well-versed in the technical issues behind game-art, and it's nice to see some of it get worded in a few different, easy to comprehend ways.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    After talking with one of the programmers here, I have a question - do models using object-space normal maps have to be 100% uniquely UV-mapped?

    Also, he mentioned precision issues with them, since local normal maps are just in the half-space (180 degrees on X/Y, -1 to 1 on Z), they are less likely to suffer from artifacts since each colour channel has to hold half the "range" of normals that an object-space map does.
  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    similar to the tangent stuff, you could encode per vertex a "mirror axis" to make object space maps that are mirrored. Though I am unsure if this has been done before.

    the artefact thing is indeed true, mostly you have XY from -1 to 1, just like objspace, but Z normally is 0 to 1
    however I also think most software you use to bake normalmaps will do 8-bit [-1,1] for tangent stuff for each channel...
    another trick is that you do 16 bit [-1,1] for XY and store that into a 32-bit texture, and calc Z (assuming it always points "up") in the pixel shader for high precision normalmaps.
  • EarthQuake
    I've never noticed any artifacts or precision issues with object space maps, i get better quality out of them in 100% of cases i've seen, and they compress quite a bit better in our engine too. With tangent space you have all those gradiations to compensate for the lowpoly's normals, and you can get really horrible compression artifacts on some graphics cards.

    Not being able to mirror OS normals is one of the biggest cons of using them, but in most cases where i'de like to use OS maps i'de rather have one thats half the size of a tangent map than have to suffer through the ugly smoothing and compression problems that tangent maps have.

    CB: About mirroring, would you have to somehow specify which polys get mirrored, or use uv orientation or something? Because arent tangents and normals pretty much thrown out hte window when calculating OS maps?

    [edit] Another thing i forgot to mention is the versatility they have when doing things like LODs, you can take a 4000 poly mesh, lod it down to 400 polys and as long as the uvs are still relatively the same your lighting is still going to match up. Now i'm sure this isnt really a big deal to most people, but its quite cool. No need to rebake your textures for your lods.
  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    the fact that you dont need normals & tangents at runtime for OS maps, doesn't mean they may never be used in the pipeline... Therefore in a preprocessing (custom) tool you can analyze topology and react accordingly. If you have interest in the idea we can discuss it in private.
  • Rob Galanakis
    Artifacts: I can't imagine OS maps would have any significant artifacts, as EQ said. But that is speculation and I haven't tested it. DXT formats compress TS maps quite horribly, it would probably be better with OS because of the diversity of colors. But again, speculation.

    About mirroring... I guess, as CB said, you could do something like use the vertex tangents to determine flipped verts... generally, we want to fix this problem so we can mirror TS normal maps, so we fix the tangents on a mirrored mesh (through some mesh processing utility for the engine), but we could potentially use something like this to determine if UV's are mirrored? I'm still not sure how that'd be done (of course, we could also just add in some new vertex data to encode an X or Y flip, such as R or G vertex colors, and use that to determine flipping of OS channels).

    MightyPea: Please be my Valentine.
  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    instead of sending a per-vertex tangent
    you send a per-vertex mirror normal

    for the "correct" side (ie what is really stored in the normalmap) that would simply be "0,0,0"
    and for the mirrored vertices it would be the mirror plane's normal. Using that normal being 0 or "somevalue" you can flip the texture OS normal again to the correct "side".

    The plane normal you compute in the custom tool, by comparing vertex object positions of "overlapping" regions. As with tangent stuff you need to split the mesh along seams in a preprocess tool. And of course when baking you must make sure that each UV chunk has continously pixels of only one side.

    the preprocess tool could sample the texture and find out which is the "stored" side.
  • EarthQuake
    It would be cool if it was automated so that anything outside of the 0-1 uv range could be used to detect if it was mirrored, because thats something i do anyway for baking purposes when using mirrored stuff. Dunno if that would actually be helpful or not?
  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    yes that would work even better, as the user then tells the code already which is the correct side, and no algo to auto detect it has to be done.
  • vividly_pathetic
    [ QUOTE ]
    I've never seen a game asset use world-space normal maps.
    My guess is that one of your tangent space channels is flipped. You might try inverting the green channel and seeing if that corrects the issue.

    [/ QUOTE ]

    Thanks for the thoughts guys, it's been quite informative to a noob like myself.
    And Kevin, you're right. I flipped both red And green channels and it's looking much better, so thanks a lot. (Though I think the overall shading in Object-Space looks a lot closer to the original hi-res Zbrush model than the tangent, though).
  • EarthQuake
    Could you post some screenshots? You may still have some errors that can be easily fixed if we're allowed to look at what you have.
  • vividly_pathetic
    I think I've got it sorted out, but I'll try post some shots tomorrow (if I can get the blasted wifi working on my 3D computer...) Thanks.
Sign In or Register to comment.