Introduction

介绍

One of the most empowering new components of DirectX 9 is the High Level Shading Language (HLSL). Using this standard high level language, shader writers are able to think at the algorithm level while

implementing shaders, rather than worry about meddlesome hardware details such as register allocation, register read-port limits, instruction co-issuing and so on. In addition to freeing the developer from hardware details, the HLSL also has all of the usual advantages of a high level language such as easy code reuse, improved readability and the presence of an optimizing compiler. Many of the chapters in this book and in the ShaderX2 - Shader Tips & Tricks book will utilize shaders which are written in HLSL. As a result, it will be much easier for you to understand and work with those shaders after reading this introductory chapter.

In this chapter, we will outline the basic structure of the language itself as well as strategies for integrating HLSL shaders into your application.

DirectX9 最受推崇的新组件之一就是高阶着色语言(High Level Shading Language ,简称HLSL)。使用这种标准化的高阶语言,着色器编写者能够在算法的层次上考虑和实现着色器代码,而不用困扰于诸如寄存器分配(register allocation)、寄存器读取端限制(register read-port limits)、指令并发(instruction co-issuing)等等之类的硬件细节。HLSL也具有高阶语言通常的有点,如代码易于重用、改良过的可读性和具有优化能力的编译器。本书和《ShaderX2 - Shader Tips & Tricks》这两本书的许多章节内的着色器代码都是使用HLSL编写的。在读完这一导引章节后,您会更容易地理解和使用那些着色器代码。本章节中,我们将会介绍语言的基本结构和将HLSL着色器代码整合到您的应用程序中的策略。