OpenGL 3 & DirectX 11: The War Is Over

Shader Model 5

With Shader Model 5, Microsoft applies certain concepts of object-oriented programming to its shader language, HLSL. Unlike preceding versions, which introduced new capabilities (Dynamic Branching, integer support, etc.), the purpose here is to facilitate programmers’ work by solving a common problem in current game engines: namely the upsurge in the number of shaders due to the large number of permutations. We’ll take a concrete example: Suppose that an engine manages two types of materials, plastic and metal, and two types of light: spot and omni. A programmer has to write four shaders in order to handle all cases:

renderPlasticSpot () … // rendering plastic using spot light …

renderPlasticOmni () … // rendering plastic using omni light …

renderMetalSpot() … //rendering metal using spot light ...

renderMetalOmni() … //rendering metal using omni light …

This example is very simple since there are only two materials and two types of light, but in practice there can be several dozen. Obviously doing it this way can quickly become unmanageable. There’s a tremendous amount of code duplication and each time a bug is corrected somewhere it has to be corrected in all the other shaders. To solve this problem, programmers use what’s commonly called an über–shader, which brings together all the combinations:

Render() #ifdef METAL // code specific to metal material #elif PLASTIC // code specific to plastic material #endif #ifdef SPOT // code specific to spot light #elif OMNI // code specific to omni light #endif

This solution solves the problem by generating shaders on the fly from common code fragments. The downside is that it makes reading the shaders difficult and requires additional effort to be sure that all the fragments are inserted where they need to be. But with Direct3D 11, it’s now possible to make your code much more legible by using a derived interface and classes:

Light myLight; Material myMaterial; Render() myMaterial.render (); myLight.shade ();

Light and Material are interfaces, and the code is contained in the derived classes OmniLight and SpotLight, PlasticMaterial and MetalMaterial. So the code is all in a single place, which makes bug correction easier. At the same time, legibility doesn’t suffer thanks to the organization of the code, which resembles the concept of virtual functions in object-oriented languages. This feature will be welcomed by programmers, but won’t have any real impact for gamers.


As you can imagine, we’ve only skimmed the surface of Direct3D 11’s new features and Microsoft hasn’t even released all the details yet. Among the topics we haven’t mentioned are the increase in maximum texture size from 4K x 4K to 16K x 16K and the possibility of limiting the number of mipmaps loaded in VRAM. There’s also the possibility of changing the depth value of a pixel without disabling functionality like early Z checking, support for double-precision floating-point types, scatter memory writes, etc.

Create a new thread in the UK Article comments forum about this subject
This thread is closed for comments
Comment from the forums
    Your comment
  • mi1ez
    So, is the tesselation stage similar to AF or bi/trilinear filtering?
  • JDocs
    Tesselation, from what I've seen, takes a simple model intended for say a 4650 and "upgrades" it in memory making it more complicated and details for higher end cards. If I understand this correctly it will drastically reduce development time and costs while increasing visual quality.
  • Anonymous
    Hmm, not sure about "upgrading" in memory. I looks like it just lets you pass in the control points that define your geometry rather than passing in all vertices for the mesh, which you yourself would probably have defined in a similar manner anyway.
  • Anonymous
    Direct3D remains utterly irrelevant to me as a Linux user.
  • bobwya
    shrugDirect3D remains utterly irrelevant to me as a Linux user.

    But it is relevant to a lot of GNU/Linux users as the Wine programmers have to compatiblise what M$ implements in their 3D API... Currently they are making a dogs dinner of DirectX 9.0 support. However Windows games are generally well supported if they have an OpenGL option... Far Cry for example will not render under Wine in DirectX mode but when switched to OpenGL it works very well.

    It is sad to hear about the difficulties OpenGL is having therefore.

  • Scooby2
    Tessellation as far as I'm aware is adding more triangles to a model to give smoother surfaces over curves. It does not add any visual details but does add to the complexity of the model.
  • Scooby2
    adding more triangles

    It breaks down the existing geometry into smaller triangles. (most 3d models are built out of triangles to begin with)
  • mayones
    Very good aricle, thanks! I'm an OpenGL developer as well, and I wish it the best. I think that now, OpenGL needs money and commercial support - unfortunately these are the rights of current world. It would be a shame to have only one modern 3D API...
  • marmot
    "the professional market, where OpenGL is the standard"
    what market are you talking about? Please detail. Your readers are mostly common computer users, not specialsts knowing in-depth details about the computer graphics market.

    "Since the ARB—the group in charge of ratifying the API’s development—included many different, competing companies.."
    What are the most important members of this ARB? Whose words have big weight in that group? The readers might be curious - who are the people generating the conflicts that slow down the OpenGL evolution?

    And by the way, why ATI and nVidia don't just take care about OpenGL and ignore that silly ARB? If they can't because of patents and such, they should make a new API from the scratch. Im pretty sure they are more than capable of it.
  • sckoobs
    The problem with OpenGL is that industry users (e.g. CAD and scientific users) are opposed to change in the API which is blatantly against the ethos of the games development community. Industry users have already spent a lot of money on the OpenGL apps, so naturally they don't want the features they use to die. I think that what Khronos has done to date is the most logical route to take given the constraints they are working within.

    The ideal solution would be to cut any ties that lead to a conflict of interest and pursue untainted API refreshes as they had originally promised.

    As a cross-platform developer I want OpenGL to be a true competitor to D3D, I don't use anywhere near the full feature set of what current versions provide but if it looses at the top end, support will dwindle and the bottom end will also be affected.
  • khelben1979
    If OpenGL even have a chance of competing against DirectX 10, then I'm more than impressed! OpenGL is the way to go for Linux and I and many others with me would like to use Linux as an gaming platform instead of Windows.

    I'm very tired of using Windows and I don't like the operating system. It works, but it isn't very fun, unlike Linux which IS a enjoyable experience and feels fast even on old computer hardware, unlike Windows which never get the power it needs.