48 lines
1.2 KiB
HLSL
48 lines
1.2 KiB
HLSL
struct vs_input {
|
|
float4 pos : POSITION;
|
|
float4 col : COLOR;
|
|
float line_thickness : THICKNESS;
|
|
float line_spacing : SPACING;
|
|
float2 offset : OFFSET;
|
|
};
|
|
|
|
struct ps_input {
|
|
float4 screen_pos : SV_POSITION;
|
|
float4 col : COLOR;
|
|
float line_thickness : THICKNESS;
|
|
float line_spacing : SPACING;
|
|
float2 offset : OFFSET;
|
|
};
|
|
|
|
cbuffer vs_constants : register(b0)
|
|
{
|
|
float4x4 projection;
|
|
};
|
|
|
|
ps_input vs_main(vs_input input)
|
|
{
|
|
ps_input output;
|
|
|
|
output.screen_pos = mul(projection, float4(input.pos.xy, 0.f, 1.f));
|
|
output.col = input.col;
|
|
output.line_thickness = input.line_thickness;
|
|
output.line_spacing = input.line_spacing;
|
|
output.offset = input.offset;
|
|
|
|
return output;
|
|
}
|
|
|
|
float4 ps_main(ps_input input) : SV_TARGET
|
|
{
|
|
float2 screen_pos = input.screen_pos.xy + input.offset;
|
|
float thickness = input.line_thickness;
|
|
float spacing = input.line_spacing;
|
|
float4 color = 0;
|
|
|
|
float2 v = abs(round(screen_pos / spacing) * spacing - screen_pos);
|
|
float dist = min(v.x, v.y);
|
|
color = input.col * step(dist, thickness / 2);
|
|
|
|
return color;
|
|
}
|