XNA for C#
DirectX 9 for C#
DirectX 9 for C++
DirectX 9 for VB
Forum
   August 19: 2D - Chapter 3 posted
My Book: Out Now!
      
       Go to section on this site

Additional info


Latest Forum posts

 BSP Tree Tutorial
  Posted by: lbmurali
  When: 21/08/2008 at 13:41:47

 Loading compiled .xnb files
  Posted by: lbmurali
  When: 21/08/2008 at 13:33:00

 The city isn't very detailed and....
  Posted by: dom96
  When: 21/08/2008 at 12:52:47

 Height-map, low framerate
  Posted by: Rich_Zap
  When: 21/08/2008 at 11:45:00

 Vertex and Index
  Posted by: radulph
  When: 21/08/2008 at 08:33:06

 The city isn't very detailed and....
  Posted by: radulph
  When: 21/08/2008 at 08:26:03

 Vertex and Index
  Posted by: engine
  When: 21/08/2008 at 06:11:35

 What about Joypad Control
  Posted by: greyrat
  When: 20/08/2008 at 22:19:13

 The city isn't very detailed and....
  Posted by: radulph
  When: 20/08/2008 at 17:20:00

 I have a problem(with camera i think)
  Posted by: vToMy
  When: 20/08/2008 at 16:25:45


Ads

High Level Shader Language (HLSL) Introduction

Welcome to this introduction on XNA and HLSL.

- HSL – What ?!?
- HLSL, the High Level Shader Language
- But I don’t care about this HLSL, just show me some more XNA code I can copy-paste into my own application!

Well of course I could go on showing you more and more XNA commands, defining some more renderstates, etc. Looking a bit further, it’s clear that all of these commands are at some point translated into commands for the hardware, the graphical card in your pc.

Before 2002, game programmers could only use the Fixed Function Pipeline, meaning the commands provided by DirectX. Since DirectX 8, a lot of flexibility has been added to the way programmers can control their graphics cards. Since then, it’s possible to directly program the vertex and pixel shaders in the GPU, the Graphical Processing Unit. This way, programmers are able to program every graphical effect they could think of, thus bypassing the limited set of DirectX/XNA instructions.

- So what you’re saying is that I can throw away everything I’ve learnt about XNA programming and start learning HLSL??

By all means, no. We’re still going to need a full 100% of what we’ve seen up till now. The difference is that this time we’re going to write our own effects. In a few chapters, you’ll see what is happening in there, how vertices are transformed, etc

- Why would I care about all these low-level commands? The nice thing about XNA is that it takes care of all the maths for us!

The more you can do manually, the more power you have about what is actually drawn on the screen. Hey, this is the 3rd series, it’s time we move on to something more advanced! It is still a ‘high level’ language, so you won’t be seeing any low-level commands, like assembler.

- So, in a nutshell, why would I want to start using this HLSL?

HLSL is used not to improve the gameplay, but to enhance the quality of the final image. Every vertex that is drawn will pass through your vertex shader, and even every pixel drawn will have passed through your pixel shader. The shaders can perform pretty much any manipulation you can think of on their data! HLSL is the only missing link between XNA code and what you see on the screen, so no doubt you’ll benefit from this knowledge. It is also incredibly useful when debugging, and absolutely necessary to add some cool visual effects to your game.

To demonstrate the use of HLSL and shaders, I have written this 3rd Series of XNA tutorials. Have a look at the lighting on one of the screenshots. You can see all lights cast shadows. This is a nice example of something that would be quite impossible to achieve without shaders. As with the previous Series, we’ll start by showing the basics, and gradually build up our application. In the end, you’ll have a complete overview of the meaning of shaders, and have a good understanding of what you can do with them! Pretty much what a tutorial should do, I guess..



So much for this introduction to HLSL. You might still be wondering where HLSL fits into the big picture. The image below demonstrates this, and will be explained while writing our first vertex and pixel shader in the next 2 chapters.




DirectX Tutorial 2 - HLSL introduction

If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !



Click here to go to the forum on this chapter!






Google
 
Webwww.riemers.net


If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !



- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2008 Riemer Grootjans
Translations

This site in English
This site in Korean
This site in Czech

Microsoft MVP Award



2007 - 2008 MVP Award
DirectX - XNA

Contents

News
Home
Forum
XNA 2.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Tutorials (141)
XNA 2.0 using C# (70)
2D Series: Shooters! (3)
3D Series 1: Terrain (13)
3D Series 2: Flightsim (14)
3D Series 3: HLSL (18)
Starting point
HLSL introduction
Vertex format
Vertex shader
Pixel shader
Per-pixel colors
Textured triangle
Triangle strip
World transform
World normals
Per-pixel lighting
Shadow map
Render to texture
Projective texturing
Real shadow
Shaping the light
2D screen processing
Preshaders
3D Series 4: Adv. terrain (19)
Short Tuts (3)
DirectX using C# (54)
DirectX using C++ (15)
DirectX using VB (2)
-- Expand all --


Thank you!

Support this site --
any amount is welcome !

Stay up-to-date

I don't have the time to keep a News section, so stay informed about the updates by clicking on this RSS file!