FBX improvements in XNA Game Studio 3.0

Originally posted to Shawn Hargreaves Blog on MSDN, Thursday, September 18, 2008

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:

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!

Blog index   -   Back to my homepage