Saturday, March 30, 2013

Using SDK Meshes from DX11 Tutorials

The DX Tutorials come with a bunch of assets which is in the SDK Mesh format. The issue with this format, when compared to the previous .X Format is that the new SDK Mesh format is in binary, and .X atleast had the option for being in text. The good news is that you can still use all these assets in your engine. I managed to reuse the SDK Mesh models that DX Tutorials has provided with my own Engine.

You could just use the DXUT framework to load them, or, be like me and incorporate the loading into your own engine. All of the code is in SDKMesh.h and SDKMesh.cpp in any of the DX Samples using the DXUT Framework. If you notice the code, the framework loads the binary file as an array of bytes, and fixes the pointers to point into areas in this array. All of the pointer fixups are based on the SDK Mesh definitions.

The main thing to remember is the vertex format. The following is the format you have to use for these meshes ( atleast for the power plant model) :

struct TexNormal_VS_Input
{
float3 pos: POSITION;
float3 normal: NORMAL0;
float2 tex: TEXCOORD0;
};

If there's a difference for other models, I will definitely update this post.
 
Once you have this set up, the rest is the same as the framework. The good thing about the SDK Mesh format is that there are pointers reserved for the actual Buffers and texture handles. Also you do not have to allocate extra memory. All of the work is already done when you load the binary data and do the pointer fixup based on the headers. All you have to do is make sure the buffers and textures are bound to the right spot before you make the draw call. If you already have used shader reflection to determine your binding points for each of the shader resources and created a framework around that (like I did), then setting up the draw call should be straight forward.

Following is a screenshot from the engine which loads up the Power Plant SDK Mesh provided by the DX Tutorials. The shader just displays the Diffuse part of the mesh.
 


Next Stop: Experimenting with different lighting methods (forward vs  deferred vs tiled forward vs tiled deferred)

2 comments:

Alessandro Silva said...

You mean that you port the SdkMesh from the sdk jun 2010 to the windows 8 sdk using DirecTXmath , or you just are still using the DirectX sdk jun 2010 in vs 2012 ??

createthematrix said...

i'm using the windows 8 sdk for directX. But, i ported the DXUT SDK Mesh from SDK June 2010. I needed to do that because i wanted to make use of my own buffers and data structures for rendering the SDKMesh. I'm not using any of the DXUT libraries from this. It's basically parsing the file, and creating my own meshes from that file.