Code Sample – Quad Batch Vertex Shader

[hlsl]
cbuffer constants : register(cb0)
{
float4 cameraToNdc;
};

struct VS_IN
{
float4 dimension: QUAD_DIMENSION; //(hw, hh, cx, cy)
float4 transform: QUAD_TRANSFORM; //(x, y, rot, *)
float4 visual : QUAD_VISUAL ; //(u, v, alpha, glow)
};

struct VS_OUT
{
float4 position : SV_POSITION;
float4 visual : QUAD_VISUAL; //(u, v, alpha, glow)
};

VS_OUT VS(VS_IN input)
{
VS_OUT output;

//center offset
float2 corner =
input.dimension.xy – input.dimension.zw;

//rotation matrix
float2 trigs =
float2(sin(input.transform.z), cos(input.transform.z));
float2x2 rotation
= { trigs.y, -trigs.x, trigs.x, trigs.y };

//final output
output.position =
float4
(
(
mul(rotation, corner)
+ input.transform.xy
) * cameraToNdc.xy,
0.0, 1.0
);
output.visual = input.visual;

return output;
}

[/hlsl]

Leave a Reply