FBX improvements in XNA Game Studio 3.0


One of the less obvious changes in our 3.0 release is that we picked up an updated version of the FBX SDK from our partners at Autodesk, which enables some cool new functionality in our FBX importer:

  • Multiple textures
  • Multiple texture coordinate channels
  • Effect materials
  • Material name strings are now imported correctly

To use this stuff, you first need to make sure you have the latest version of the Max or Maya FBX exporters.

Now create a material that uses more than one texture. For instance I used Max to apply a diffuse texture map, specular map, and bump map. Here’s how that data shows up when I read it with our 3.0 FBX importer:

    <Resource ID="#Resource1" Type="Graphics:BasicMaterialContent">
      <Name>ShawnsTestMaterial</Name>
      <OpaqueData>
        <Data Key="DiffuseColor" Type="Framework:Vector3">0.5 0.5 0.5</Data>
        <Data Key="EmissiveColor" Type="Framework:Vector3">0 0 0</Data>
        <Data Key="Alpha" Type="float">1</Data>
        <Data Key="SpecularColor" Type="Framework:Vector3">0 0 0</Data>
        <Data Key="SpecularPower" Type="float">1.9</Data>
      </OpaqueData>
      <Textures>
        <Texture Key="Texture">
          <OpaqueData>
            <Data Key="TextureCoordinate">TextureCoordinate0</Data>
          </OpaqueData>
          <Reference>#External1</Reference>
        </Texture>
        <Texture Key="SpecularFactor0">
          <OpaqueData>
            <Data Key="TextureCoordinate">TextureCoordinate0</Data>
          </OpaqueData>
          <Reference>#External2</Reference>
        </Texture>
        <Texture Key="Bump0">
          <OpaqueData>
            <Data Key="TextureCoordinate">TextureCoordinate1</Data>
          </OpaqueData>
          <Reference>#External3</Reference>
        </Texture>
      </Textures>
    </Resource>

See those extra two textures? See how the TextureCoordinate opaque data records which coordinate channel goes with each one?

The bad news is that if you load and draw this model in the usual way, these extra textures will not actually show up. That is because BasicEffect has no idea how to apply specular or bump maps, so the default material processor will just throw them away.

To render this kind of richer material, you must provide a suitable shader, then use a custom processor to apply it to your model. The improvement is that in 3.0, such processors now have more information about how the original material was set up in Max or Maya. With sufficient smarts, you could make a processor that examined the material to see which of many possible texture layers were present, chose the best fit from a set of shaders, then automatically applied the appropriate shader, passing all the correct textures through to it.

A more automated approach for using custom shaders comes into play if you apply a Direct3D material directly to your object in Max (I believe this is not currently supported by Maya). This now works in FBX the same way it previously did with X files. You can export an FBX file that uses a custom D3D effect as a material, import this into the Content Pipeline, where the material will show up as an EffectMaterialContent, then load it into your game, where the material will come through as an instance of your custom Effect already configured with the appropriate textures and parameter values.

This kind of thing makes me a happy chappie.

Go Autodesk!


Comments (20)

  1. Grayoff says:

    Shawn, Would you please tell what version of the FBX format should be used for export from Max – 2006.11 or 2009.1?

  2. lhendricks says:

    Shawn,

     I use Blender (it’s free so it fits my hobby budget perfectly) and have been using the FBX exporter from Blender to get models to use in XNA 2.0.  Do you know if anyone has tried it with the 3.0 importer?

  3. ShawnHargreaves says:

    > Would you please tell what version of the FBX format should be used for export from Max – 2006.11 or 2009.1?

    You should use the 2009 version. Either will work, but if you use the 2006 release, you won’t get any of these new features.

  4. ShawnHargreaves says:

    > I use Blender (it’s free so it fits my hobby budget perfectly) and have been using the FBX exporter from Blender to get models to use in XNA 2.0.  Do you know if anyone has tried it with the 3.0 importer?

    We’ve done as much testing as we could with as many FBX files as we could find, but it’s impossible for us to be 100% certain we covered everything in an area as wide open as this!

    My expectation is that FBX files exported from Blender should still work just the same as they used to, but these new material features will not show up until/if someone adds them to the Blender exporter.

    If you have worries about this, now would be a great time to try things out with the 3.0 beta version of the importer, and let us know via Connect if you run into any problems…

  5. blindrenderer says:

    Actually Maya supports HLSL shader as well as CgFx shader.  You just need to turn on this plug-in in your setting, and then you will see HLSL shaders working in Maya.

    The only problem is that Maya FBX Exporter from AutoDesk doesn’t export HLSL shader, which is odd since new FBX SDK supports both CgFx and HLSL shaders.  Anyways, at this moment 3DS Max only exports HLSL shader(not CgFx) to FBX, and Maya only exports CgFx shader(not HLSL) to FBX.

    I was hoping that XNA 3.0 would provide Maya FBX exporter that supports HLSL shader.  I guess that’s not the case?

  6. ShawnHargreaves says:

    The XNA Game Studio team is not in the business of writing modelling tools or exporters: that side of things comes from our partners such as Autodesk.

    It’s actually possible that you might have some luck authoring Cg shaders in Maya, then converting these to HLSL in a processor. You should still be able to access the data in your processor, although it would have to do some fixups to replace the Cg shader with a suitable HLSL equivalent. The two shader systems are very similar, though, so this might be viable as a way of authoring the data, setting up your parameter bindings, etc.

  7. Lynch3 says:

    I’ve been banging at trying Maya + HLSL to FBX for an hour or so.  The best method will probably be the hack method Shawn has suggested, or using the FBX API and Maya API to extend the FBX exporter in maya.  You could make a plugin that acts as a second pass to the current FBX exporter, and fills in the shader details based on the HLSL shader node.

    Personally I think the XNA team needs to start applying some additional pressure to get the Maya exporter updated to support the HLSL shader nodes 🙂

  8. blindrenderer says:

    I want to share this good news!

    A couple months ago, I asked Autodesk to support HLSL export from Maya.  And today I got the confirmation that it will be supported before XNA 3.0 is out.  Here is the forum thread.

    http://area.autodesk.com/index.php/forums/viewthread/14945/#84278

  9. jsangco says:

    Some of the built in Max shaders will not render correctly "out-of-the-box" when importing into GS3.0.  

    As example, in XNA Game Studio, the user is required to set both the vertex and pixel shader. There are max shaders that do not and thus will not work.  

    It’s pretty easy though to just tweak the Max shaders so they work 😀

  10. Grayoff says:

    Please, explain

    how can i assign a Direct3D material to object in Max?

    I have plugin for Max 9, installed with DirectX SDK, which allows  to create "DX Shader Material". But if I try to export such material to FBX, error comes.

    May be You are using any other plugins, or only special FX are allowed for export to FBX, or anything else?

  11. ShawnHargreaves says:

    > how can i assign a Direct3D material to object in Max?

    I’m far from a Max expert, but this works for me using a stock install of Max 2009:

    – Open the Material Editor

    – Click Get Material

    – Select DirectX Shader from the Material/Map Browser

  12. joviol72 says:

    Hello,

    I was wondering if tangent data were exported as well, in order to implement normal mapping in the application.

  13. ShawnHargreaves says:

    > I was wondering if tangent data were exported as well, in order to implement normal mapping in the application.

    I don’t believe that is exported in the FBX file, but there is no need for that because tangent data is just a generated derivative of the normal and texture coordinate information. Anyone who needs this for rendering purposes can compute it for themselves. If you are using the XNA Framework Content Pipeline, you can do that by checking the generate tangent frames option in your content processor properties.

  14. FessLaeda says:

    re:A more automated approach for using custom shaders comes into play if you apply a Direct3D material directly to your object in Max (I believe this is not currently supported by Maya). This now works in FBX the same way it previously did with X files. You can export an FBX file that uses a custom D3D effect as a material, import this into the Content Pipeline, where the material will show up as an EffectMaterialContent, then load it into your game, where the material will come through as an instance of your custom Effect already configured with the appropriate textures and parameter values.

    I tried to add DirectX Shader

    "Material Editor->Standart->DirectX shader"

    and get this message

    "Failed to export the following materials, they will be exported as generic materials:

    -01- Default"

    I could not found any string about shader in fbx file after.

    What does it mean – "will be exported as generic materials"?

  15. FessLaeda says:

    Looks like it not work in 3dsmax 2008. We can use several texture and it exporte fine, but DirectX material is not exporte.

    I install 3dsmax 2009 and exporter(plugin already was there) do without errors, pathes to the shaders present in fbx file and shaders parameters too. Create job! Really cool. 🙂

  16. FessLaeda says:

    It would be really cool too if we could get custom parameter of string type from 3dsmax in OpaqueData. 🙂

  17. trivus says:

    Shawn, thanks for all the great informations.

    Sorry if I’m being stupid or anything, but could you please tell me how to read data from .FBX file, and print them out like you showed in this page?

    I’m using XNA 3.0, and Max2009, newest fbx exporter.

  18. ShawnHargreaves says:

    trivus: look in the obj directory after you build your project.

  19. chenoon says:

    Hello, thanks for your post. I’m not sure I understood the process when using Direct3D material.

    Here is what I do :

    In 3dsmax 2009 I created a mesh with a Direct3D material. I use the lightMap.fx given with 3dsmax. The shader references two textures diffuse.png and lightMap.png.

    I export the sene with the FBX exporter.

    In XNA, the model is imported with "Autodesk FBX" and processed with the default "Model – XNA Framework".

    At render time, I run through the ModelMeshes and ModelMeshParts and set the following parameters :

    Effect effect = meshPart.Effect;

    effect.Parameters["World"].SetValue(world);

    effect.Parameters["View"].SetValue(view);

    effect.Parameters["Projection"].SetValue(projection);

    I do not see the model at all. Any idea ?

    Thanks

  20. amt allah says:

    what about fbx from motion builder i want to use it in XNA plz help