Windows Developer Documentation

Graphics API Reference > DirectX > High-Level Shading Language (HLSL)

High-Level Shading Language (HLSL) Reference

The High-Level Shading Language (HLSL) is a proprietary language developed by Microsoft for writing shader programs that run on the GPU. It provides a C-like syntax that makes it easier to write complex shader logic compared to assembly-level shading languages.

Overview

HLSL is used to define the behavior of graphics pipelines, controlling how vertices are transformed, how pixels are colored, and how other graphical effects are rendered. It's an integral part of the DirectX graphics API.

Key Concepts

Syntax Examples

Basic Vertex Shader

This example demonstrates a simple vertex shader that passes vertex position and color to the next stage.


struct VS_INPUT {
    float4 pos : POSITION;
    float4 color : COLOR;
};

struct VS_OUTPUT {
    float4 pos : SV_POSITION;
    float4 color : COLOR;
};

VS_OUTPUT main(VS_INPUT input) {
    VS_OUTPUT output;
    output.pos = input.pos; // Pass position through
    output.color = input.color; // Pass color through
    return output;
}
            

Basic Pixel Shader

This example demonstrates a simple pixel shader that outputs a solid color.


float4 main() : SV_TARGET {
    return float4(1.0f, 0.0f, 0.0f, 1.0f); // Output red color
}
            

Built-in Functions

HLSL provides a rich set of built-in functions for:

Resources and Bindings

Further Reading