Monday, October 10, 2011

3D C# D3D11 (As in 3D rendering with C# and DirectX 3D 11)

Eternal Coding - Discovering 3D rendering with C# and Direct3D 11

"To develop 3D applications, you will have to understand underlying concepts. The aim of this article is to define these concepts in order to use them with Direct3D 11.

The final project is available here :

From vertex to pixel

The first element we have to know is the vertex (with its plural form : vertices). A vertex is a point in 3D space. We can represent it with its simplest structure : a 3 values vector : x, y and z.

All we can see in a 3D application is built upon a set of vertices which define the backbone of our objects.


Using Direct3D 11

To use DirectX 11 (and its 3D part: Direct3D 11), we will use a managed wrapper called SlimDX (

Indeed, DirectX is a COM API and SlimDX allows us to use it efficiently (by reducing the overhead of marshalling between .NET and COM).


To initialize Direct3D 11, we need to define 4 required variables:

  • The device which will be our broker to the driver of the graphic card
  • The swap chain which defines how the rendered image will be copied from the graphic card to the display window
  • The back-buffer which is the graphic card’s memory dedicated to produce the rendered image
  • The render view which is the view on the back-buffer. With Direct3D 11, the buffers are not used directly but through views. It is a really interesting concept as it allows us to have only one memory resource with many views on it (with different associated semantics)

The initialization code will be the following:



So we are now ready to produce high quality rendering. By using shaders and .fx files, we can render every kind of advanced materials. The only limit is our imagination (and our mastering of optical effects Sourire).

Our system renders a list of vertices and faces, so rendering a plane or a complete city is nearly the same thing (obviously, rendering a city will require some additional optimizations!)

Feel free to play with the associated code and unleash the power of 3D!


For some reason, DirectX development always seemed scary to me. So much a lower level, closer to the metal level, of development that I just avoided it (since I'm not a game dev and all that). But while it's still a little scary, this article made it seem a little less so, putting a little light on the subject and casing away some of the shadows...

No comments: