DirectX - First HLSL



The high-level shader language or high-level shading language is considered as a proprietary shading language which is developed by Microsoft. It includes an API to augment the shader assembly language. DirectX includes various versions of programmable shaders. The first one appeared in the year 2000 and complete unified shader model was generated with Direct3D 10 and higher versions.

Working in the assembly language helps user to create API in short supply. NVidia and Microsoft hold their position in PC graphics market and collaboration with more accessible shader language. Both the compile shaders are implemented for DirectX.

It has to be noted that Open Graphics library also called as OpenGL is an open source, cross-platform 2D/3D graphics API.

The higher level languages are usually based on the C language, i.e., the name Cg stands for C with graphics. It uses curly brackets, semicolons and other familiar C styled syntax. It also includes high-level concepts like functions, expressions, named variables and statements to the shader programmer.

The simple demonstration of the assembly language with equivalent code in HLSL is mentioned below −

sampler2D ourImage;
float4 main(float2 locationInSource : TEXCOORD) : COLOR {
   return tex2D( ourImage , locationInSource.xy);
}

Here, the first line is declaring a variable name ourImage, which is the input to the shader. After this, we call for main function that takes a single parameter and returns a value. The return value is vital, as it is the output of the pixel shader. That “float4” represents the RGBA values that are assigned to the pixel shown on the screen.

This is about the simplest pixel shader imaginable. This is a preliminary look at shader code. There are detailed discussions of HLSL syntax throughout this tutorial.

The pixel shader examines each rasterized pixel figure mentioned below, applies the shader algorithm, and gives output the final color value. It includes frequently used additional textures with the original raster image. They excel at color modification and image distortion. If you want to apply a subtle leather texture to an image, the pixel shader is your tool.

The pixel shader in the pipeline is shown in the below image −

First HLSL
Advertisements