HLSL++ provides a C++ interface that mirrors HLSL shading language syntax, including swizzling, native types, and common math functions.
Key Capabilities:
- Swizzling: Access components using
.x, .y, .z, .w or .r, .g, .b, .a. Supports swizzling of swizzles (e.g., foo.wx = bar.yx). - Constructors: Create vectors and matrices using HLSL-style constructors like
float4(1, 2, 3, 4) or combined constructors like float4(vec2, vec2). - Matrix Operations: Use
mul(matrix, vector) for transformations and access static methods for common matrices like float4x4::identity() or float4x4::perspective(). - Extended Types: Supports
float8 for wide SIMD registers and quaternion types. - Data Packing: Use functions like
pack_float4_rgba8_unorm and unpack_rgba8_unorm_float4 for efficient data handling. - Pointer Interop: Overloaded
& operator on individual swizzle members (e.g., &foo.x) allows passing component addresses to libraries like ImGui.
// Native types and Swizzling
float4 foo4 = float4(1, 2, 3, 4);
float3 bar3 = foo4.xzy;
// HLSL functions
float2 logFoo2 = log(bar3.xz);
// Swizzle of swizzle
foo4.wx = logFoo2.yx;
// Combined constructors
float4 baz4 = float4(logFoo2, foo4.zz);
// Matrices and transformations
float4x4 fooMatrix4x4 = float4x4( 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1);
float4 myTransformedVector = mul(fooMatrix4x4, baz4);
// Data packing
uint rgba8Packed = pack_float4_rgba8_unorm(foo4);
float4 rgba8Unpacked = unpack_rgba8_unorm_float4(rgba8Packed);