Tutorials to .com

Tutorials to .com » Software » Game-developer » Advanced shader language (High-Level Shader Language)

Advanced shader language (High-Level Shader Language)

Print View , by: iSee ,Total views: 8 ,Word Count: 3388 ,Date: Wed, 27 May 2009 Time: 2:13 PM

Advanced shader language (High-Level Shader Language) - DirectX9

Translator: superb David - lonely sword

Are you tired of using color browser written in assembly language? Can try advanced shader language (High-Level Shader Language - HLSH). Microsoft DirectX9 includes development and debug can be used for the class c shader language HLSH. Such characteristics of the beginning of DirectX 8.0 is an extension of the compilation of shaders, vertex shaders can be used for (vertex shaders), Pixel Shader (pixel shaders), as well as special effects.

Class C++ function HLSH support shader development and support functions (fuctions), expression (expresstions), statements (statements), the standard data types (standard date types), custom data types (user-desighed date types), pre-processing instructions (preprocessor directives).

****** Data types (date types )******

Value types (scalar types)

bool true or false

int 32-bit integer

half 16 bit floating point

float 32 bit floating point

doule 64 bit floating point

Not all target platforms support integer data, integer type may be floating-point hardware simulation. On these platforms to operate in excess of type integer part bit integer into a floating-point type would be the expression, which does not guarantee the implementation of DirectX features desired.

Not all target platforms support half and doule type, if we do not support the type of simulation will be used to float.

Vector type (vector types)

vector composed of four types of vector float

vector <type,size> types by size, composed of a numerical vector

The various components of the vector scalar can access, through the array access syntax, as follows:

vec [0] (same as vec.x)

vec [3] (same as vec.w)

Can also be the name of access, access to grammar through structural members, the names of the following vector set as follows:

Default set

x y z w

Color set

r g b a

Access through the name of the vector (Original Vectors containing swizzled components of the vector) can be written in two or more connected components of the form name. For example: yyzw or bgr. Linking the names of the name must come from the same set. Repeat the same part is null and void.

Matrix type (matrix types)

matrix 4 * 4 matrix, the composition of the float type

matrix <type,rows,columns> row * col matrix composed by the type type

Matrix of the various parts can be accessed through the scalar by an array access syntax is as follows:

mat [2] (same as mat.m 20m 21m 22m 23)

mat [2]. w (same as mat.m23) / / / sic

mat [2] [3] (same as mat.m23)

Can also be the name of access, access to grammar through structural members, the names of the following matrix set up as follows:

1 Based on the set

_11 _12 _13 _14

_21 _22 _23 _24

_31 _32 _33 _34

_41 _42 _43 _44

Based on the set 0

_m00 _m01 _m02 _m03

_m10 _m11 _m12 _m13

_m20 _m21 _m22 _m23

_m30 _m31 _m32 _m33

Access through the name of the matrix (original Vectors containing swizzled components of the matrix) can be written in two or more connected components of the form name. For example: _41_42_43 or _m01_m02_m03_m04. Linking the names of the name must come from the same set. Repeat the same part is null and void.

Object type ****** ******

String (string)

ASCII string type, did not accept the operation and status of the string. Note the string parameters and ID3DXEffect interface can be queried by the application (query).

Pixel shader (pixelshader)

An object that pixelshader pixel shader Direct3D object. When the shader function not to operate directly at pixel shader, pixel shader technique can be internal to the equipment set up. The following example can be an object pixelshader questioned by members of access to grammatical structure.

const string version;

Pixelshader literal value that can be compiled into a block:

pixelshader ps = asm (ps.2.0 mov oC0, c0);

Compile or a call:

pixelshader ps = compile ps_2_0 psmain ();

Sampler (sampler)

A sampler sampler Direct3D object layer. Its kind of device was used to sample texture layer. Sampler has been designated the type of texture and filtering.

Texture (texture)

A texture object that Direct3D texture object. When the shader function is not operating directly texture, the texture can be set up in the technique to the equipment. The following example of a texture object can be questioned by members of access to grammatical structure.

const string type;

const string format;

const int width;

const int height;

const int depth;

Vertex shader (vertexshader)

Direct3D object vertexshader said a vertex shader object. When the shader function is not operating directly when vertex shaders, vertex shaders can be set up in the technique to the equipment. The following example can be an object vertexshader questioned by members of access to grammatical structure.

const string version;

Pixelshader literal value that can be compiled into a block:

vertexshader vs = asm (vs.2.0 mov oPos, c0);

Compile or a call:

vertexshader vs = compile vs_2_0 psmain ();

The structure of object access method has not been entirely consistent.

****** Type structure (struct types)

struct keyword is used to define the structure of the type. Once the structure is defined, we can, through its identifier (ID) has been invoked.

struct [id] (member_list)

Member_list by a member of one or more statements (member declarations) component. Members is similar to variable declaration statement (statement below), unless they can not be initialized or a separate state for the static, extern, volatile, or const.

User-defined types ****** ******

typedef keyword is used to define a type name. const keyword is used to indicate the type of its constants. Array_suffix can be put on the back of each ID. Once the custom type is defined, we can, through its identifier (ID) has been invoked.

typedef [const] type id [array_suffix] [, id ...];

A array_suffix by the expression of one or more int that their dimensions (dimension).

With the Direct3D extensions (D3DX) 8.0 to maintain compatibility, the following types are automatically defined:

typedef int DWORD;

typedef float FLOAT;

typedef vector VECTOR;

typedef matrix MATRIX;

typedef string STRING;

typedef texture TEXTURE;

typedef pixelshader PIXELSHADER;

typedef vertexshader VERTEXSHADER;

For convenience, the following types are automatically defined (# said a number between 1-4)

typedef vector bool #;

typedef vector int #;

typedef vector half #;

typedef vector float #;

typedef vector double #;

typedef matrix bool # x #;

typedef matrix int # x #;

typedef matrix half # x #;

typedef matrix float # x #;

typedef matrix double # x #;

Type Conversion ****** ******

Scalar-to-scalar

Always effective, and when the transformation from type bool to an integer or floating-point type when, false is considered 0, true is 1. When an integer or floating-point type when converted to bool, 0 for true, non-0 for false. When type conversion from floating point to integer type, the value is in addition to more than (the value is rounded toward zero)

Scalar-to-vector

Always effective, value-type filler copy vector

Scalar-to-matrix

Always effective, value-based replication to fill matrix

Scalar-to-object

Invalid

Scalar-to-structure

If all parts of the structure are the effective values, copy the structure of numerical filled

Vector-to-scalar

Always effective, and to choose the first part of vector

Vector-to-vector

Target vector must be greater than the resources left to maintain the value of the vector, to remove excess value. The aim is to line matrix, figure out the structure of matrix and vector can be regarded as

Vector-to-matrix

Size must be equal

Vector-to-object

Invalid

Vector-to-structure

Not more than the structure of the vector, and the structure of the various parts of the figures are effective

Matrix-to-scalar

Always effective, select the upper left part of the matrix

Matrix-to-vector

Size must be equal

Matrix-to-matrix

The target matrix in any one-dimensional resources are not greater than the matrix, the upper left to maintain the value of this operation, remove the excess value.

Matrix-to-object

Invalid

Matrix-to-structure

Equivalent to the size of the structure of the size of the matrix structure is an integral part of all figures

Object-to-scalar

Invalid

Object-to-vector

Invalid

Object-to-matrix

Invalid

Object-to-object

Object type is identical to the effective

Object-to-structure

Structure must contain more content than the members of this type must be a member of the same type and structure

Structure-to-scalar

Structure must contain at least one member of the digital type

Structure-to-vector

Structure is at least the size of the vector, the first component of the figures must be, until the size of matrix

Structure-to-matrix

Structure must be at least the size of the matrix. An integral part of the first figures to be, until the size of matrix

Structure-to-object

The structure contains at least a member of an object. Members of the type of the object type must be identical.

Structure-to-structure

The target structure must be greater than the resource structure

Tired, look at how to decide whether to continue repercussions.


Game Developer Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.