Home Technical Talk

Synced tangent basis workflow from 3ds Max to Unity 5?

Hi guys!

I'm not sure whether or not my normal map baking workflow is synced. I am using 3ds Max 2016 for baking and Unity 5 as my target game engine. Ideally, I just want to make my low poly object a single SG and not care about hard edges and UV splits anymore. As I understand it, the synced tangent basis workflow allows me to do that. I'm familiar with the Cage vs Explicit Mesh normals discussion and in theory with other quirks of normal map baking. I'm still not sure if my workflow is synced. Here is what I do (the crucial settings):

1) Bake with "Projection Options" in the "Render to Texture" dialog set to Red: Right and Green: Up. Is that correct for Unity? According to the Wiki it should be, but I don't know if it's up to date.

2) Then export the low poly mesh with "tangents and Binormals" checked in the FBX exporter.

3) In Unity's FBX importer settings I would choose "Tangents" to "Import".

Is that all I have to do? Or am I missing a big piece of the puzzle?

Before that I always used to export my low poly for baking to xNormal (without tangents and binormals in FBX) and use that tangent space calculator plugin for Unity. In Unity I would then set the importer to "Calculate Tangent Space". I would prefer to do it all in 3ds Max though as I like to avoid any import/export that is not absolutely necessary.

Thanks so much for any help!


Replies

  • monster
    Offline / Send Message
    monster polycounter
    Unity 5.3+ uses MikkTSpace and 3ds Max uses it's own calculation. Unity 5.2 and older used their own calculation as well, so you need the xNormal Unity plugin with older Unity.

    You should use xNormal (or other MikkTSpace baker) to bake normal maps. OR render a world space normal from 3ds Max and use HandPlane to convert to a tangent map.
  • ConSeannery
    monster, thank you for your quick response! Good to know that Unity finally uses MikkTSpace.

    I thought exporting tangents and binormals via FBX solves the problem of mismatching tangent spaces at the expense of larger FBX files? That isn't the case?

    Btw, are my settings in the "Projection Options" in the "Render to Texture" correct for Unity?


  • Farfarer
    Exporting tangents and binormals won't fix it.

    Unity will discard the binormal and simply store a handedness value, which would be fine if the tangent basis was orthogonal, but 3DS Max's is not.

    3DS Max's normal maps also require that the tangent basis be normalized per-pixel (which Unity doesn't do).
  • ConSeannery
    So Wes from Allgegorithmic got it wrong in his video:

    https://www.youtube.com/watch?v=gR3r7Xmhmlk&list=PLB0wXHrWAmCx994Cb7iRFSmupYHFw5DTx&index=21
    ?

    Or is this workflow OK for Maya? The baked normal maps looked fine in Unity.

    I never heard of a non-orthogonal tangent basis. Wow, this stuff is so unnecessarily convoluted.

    So eventually I have to use xNormal to get a synced tangent basis workflow? Does xNormal default to MikkTspace now or do I still need your plugin?

    Also, what's the consensus on MightyBake and Knald. Have these evolved to something better than xNormal? Thanks! :)
  • monster
    Offline / Send Message
    monster polycounter
    He's saying the same thing we are saying. He's baking with Substance Painter (mikkT) for Unreal (mikkT). His info is out of date for Unity 5.3, but it applied to 5.2 and older. Follow the unreal instructions for Unity 5.3 and newer.

    xNormal and all other bakers default to mikkT as far as I know. Only 3ds Max doesn't. (I don't know about Maya maybe somebody else can let us know.)
  • musashidan
    Offline / Send Message
    musashidan high dynamic range
    Yes, Monster's right, XN, Sp/SD, modo, blender, Toolbag all use mikkt. Old maya/max do not. Synced means baker/destination must use same tangent basis.
  • ConSeannery
    But when he imports the FBX model with tangents and binormals into SP, he explicitely tells SP to not calculate it's own per per fragment tangents. So I assumed that the baking process would use the imported tangents and binormals and not MikkTspace calculated tangents/binormals. Is does not?
  • musashidan
    Offline / Send Message
    musashidan high dynamic range
    But when he imports the FBX model with tangents and binormals into SP, he explicitely tells SP to not calculate it's own per per fragment tangents. So I assumed that the baking process would use the imported tangents and binormals and not MikkTspace calculated tangents/binormals. Is does not?

    it's the other way around. Export with t/bn unchecked. Allow baker (SP) and destination engine to calculate. So in SP case compute per fragment is checked. This is how syncing works,  because baker/engine use the same tangent basis (mikkt) you allow them to calculate t/bn
  • ConSeannery
    Yes, I understood that part. But in the latter half of the tutorial (which shows the Unity case) Wes exports tangents + binormals via FBX and in SP unchecks "Compute tangent space per fragment" upon import. As far as I understand it, this way the SP baker uses the exported FBX tangents + binormals for baking (i.e. not MikkTspace).
    In Unity he then imports the tangents from the FBX and the results look fine. So why does this work for him when according to Farfarer exporting tangents + binormals alone won't fix the underlying issue. Someone stated that most likely Maya isn't using mikktspace either (like Max). So we have a tangent basis mismatch there, too.
  • musashidan
    Offline / Send Message
    musashidan high dynamic range
    Maybe it's and old tut before Unity had mikkt? I'm not sure as I use UE. Unsynced obviously works as it's been the hacky way people have done it for years. Yes, both Max and Maya have their own tangent basis whilst pretty much everything else now supports mikkt. Personally, with so many modern, dedicated baking solutions around now I don't see the point in Max/Maya baking.

    So no, your baking isn't synced as your baker/engine have different tangent basis. 
  • monster
    Offline / Send Message
    monster polycounter
    What version of Unity are you using? If the answer is 5.3 or newer then follow the Unreal steps. Even Wes says so. :)


  • ConSeannery
    Ok, thanks guys. Good to know that Unity makes our lives a bit easier now.

    I'm just a bit baffled that there is no way to get a straight synced workflow between 3ds Max and Unity without external tools. Very odd.

    Final question:

    Assuming I had no access to an external baker due to whatever reason and I had to bake within Max. Would exporting the tangents + binormals via FBX and importing them in Unity at least make normal mapping artifacts less noticable as compared to not exporting them and letting Unity calculate their own?
  • Eric Chadwick
    Doubtful.

    Best bet is to try some tests and see what happens. Nothing beats testing it yourself.
  • musashidan
    Offline / Send Message
    musashidan high dynamic range


    Best bet is to try some tests and see what happens. Nothing beats testing it yourself.
    100%

    But basically you will not be able to use the averaged verts/synced workflow for hard surface assets between Max and Unity.
  • EarthQuake
    If you have to bake in Max, but need Mikkt, look into baking object space maps in Max and converting to tangent in Handplane.
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    But ... convert to what, in Handplane ?

    Input Tangent and Binormal,
    or
    Input Tangent with Computed Binormal ?

    Also, a general technical question: based on the comment by Wes shown in the screenshot above, the current unified way of working is to not export tangents in the FBX - but of course everything else needs to be carefully exported (hard edges, edited vertex normals in the case of a weighted pass on the mesh, triangulation choice, and so on - all of which are thankfully supported by FBX and OBJ if I am not mistaken).

    What is the technical reasoning behind that ? Isn't storing everything BUT one specific set of data an open door for some potential issues  ? Or is it just something that has been decided in order to be compatible with as many 3d formats as possible ?

    [edit] : answer below in the PDF linked by Jed. The reason to leave this open is precisely because there is no unified way to calculate this data, and that's when Mikkt calculation steps in to save the day.

    (I think that an image clearly showing what each data set represents would be a big help for everyone - veterans and newcomers alike !)

    Lastly, are the exact specifications for Mikkt available somewhere ?
  • Eric Chadwick
    pior said:
    (I think that an image clearly showing what each data set represents would be a big help for everyone - veterans and newcomers alike !)
    I started a table here, but ran out of time (and energy) to finish it. Would love some assistance with this if anyone's interested.
    http://wiki.polycount.com/wiki/Normal_Map_Technical_Details#Synched_Workflow
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    Totally willing to help on that as soon as time allows - covering Blender>Xnormal>Marmoset>UE (using OBJ) as far as I am concerned.

    (On a side note, I know that Maya can actually display tangent combing directly on the model, which certainly helped me understand this topic better a few years back, so maybe the guide could show some screenshots of that. I also find the xnormal 3d viewer to be a great help when it comes to tracking down these kind of issues as early as possible)
  • JedTheKrampus
    Offline / Send Message
    JedTheKrampus polycounter lvl 8
    @pior: you can read the paper here http://image.diku.dk/projects/media/morten.mikkelsen.08.pdf

    and the source code is here, follow the links to mikktspace.c and mikktspace.h https://wiki.blender.org/index.php/Dev:Shading/Tangent_Space_Normal_Maps
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    Thanks Jed, that does clarify it. The PDF does a great job at explaining the need for a very specific tangent calculation (basically throwing everything arbitrarily done by Maya/Max/everything else out of the window).

    It is interesting that there exists no unique or correct way to interpret what is the accurate reconstruction of tangent space at pixel level. This problem is further complicated by the fact that there is no unique way to determine the approximations for vertex level tangent space either. These two observations are a strong indication of a compatibility problem in terms of sampled normal maps generated by different software.

    Good stuff.
  • monster
    Offline / Send Message
    monster polycounter
    pior said:
    Also, a general technical question: based on the comment by Wes shown in the screenshot above, the current unified way of working is to not export tangents in the FBX... What is the technical reasoning behind that ? Isn't storing everything BUT one specific set of data an open door for some potential issues  ? Or is it just something that has been decided in order to be compatible with as many 3d formats as possible ?
    You can safely export the tangents and binormals as long as you disregard them in the baking app and game engine.

    Substance Painter

    Enable: Compute tangent space per fragment
    https://support.allegorithmic.com/documentation/display/SPDOC/Project+configuration

    Unreal 4

    Import Normal Method: Import Normals
    https://docs.unrealengine.com/latest/INT/Engine/Content/FBX/ImportOptions/

    Unity 5.3+

    Normals: Import
    Tangents: Calculate Tangent Space
    http://docs.unity3d.com/540/Documentation/Manual/FBXImporter-Model.html
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    Yup, makes total sense. I was naively expecting that all would be good in the world if if all exporters and importers respected tangents and binormals ... but the following totally justifies the use of a custom calculation:

    https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/3DSMax/files/GUID-49490C91-E450-4F62-BF5D-F84A1F768959-htm.html

    Basically even when the option is enabled, the FBX format cannot really store it anyways. That explains a lot.

    Now of course there is also the issue of various exporters/importers handling quad diagonals differently (if I am not mistaken, XNormal and Toolbag2 differ in that regard), but that's another topic altogether and easily solved by triangulating before baking and exporting anyways.
  • Tzur_H
    Offline / Send Message
    Tzur_H polycounter lvl 9
    Thanks for clarifying it all, monster
  • JedTheKrampus
    Offline / Send Message
    JedTheKrampus polycounter lvl 8
    Also, in my testing I got good results in Unity with Compute Tangent Space per Fragment disabled, and in UE4 with Compute Tangent Space per Fragment enabled, assuming Substance Painter bakes similarly to Xnormal.
  • Thousand
    Offline / Send Message
    Thousand polycounter lvl 9
    thanks for sharing that discussion, very interesting
Sign In or Register to comment.