Chapter 13. HLSL Basics
Let’s take a break from developing the game for a minute and talk about High Level Shader Language (HLSL). Pre-XNA, DirectX allowed developers to send instructions directly to the graphics device through a mechanism called the Fixed Function Pipeline (FFP). This worked fine for a while, until graphics cards and hardware began to become incredibly complex. The more capabilities that were added to the hardware, the more detailed and complex the FFP needed to become to allow developers to take full advantage of that hardware.
Tip
Even on modern cards, the FFP is implemented as a shader—just one
that operates behind the scenes. This is very similar to the way that
BasicEffect
gives developers access
to a simple version of the FFP.
Instead of continually adding features to the FFP and extending it, Microsoft decided instead to allow developers to talk directly to the hardware devices in a different language built specifically for those devices.
The first attempt to solve this problem was to allow developers to program directly to the hardware using assembly language. While this approach was functional, developers still needed a higher-level language to develop in. Enter HLSL. HLSL began as a joint project between Microsoft and NVIDIA. At some point, however, the development effort split, and NVIDIA’s language (called C for Graphics, or Cg) went one route and Microsoft’s language (called HLSL) went another.
HLSL allows developers to write in a language that is similar ...
Get Learning XNA 4.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.