Mikemon/src/shaders/grid.slang
2025-03-26 22:04:53 +01:00

53 lines
1.3 KiB
Plaintext

#include "common.slang"
struct VertexShaderInput {
// Per Vertex
uint vertex_id : SV_VertexID;
float3 pos;
// Per Instance
uint instance_id : SV_InstanceID;
};
struct VertexShaderOutput {
float4 pos : SV_POSITION;
uint selected;
};
struct PixelShaderOutput {
float4 color : SV_TARGET;
};
[shader("vertex")]
VertexShaderOutput main_vertex(VertexShaderInput input) {
VertexShaderOutput output;
float2 tile_pos = float2(input.instance_id % map_width, float(input.instance_id / map_width));
if ((flags & 0x1) != 0)
tile_pos -= float2(0.5, 0.5);
output.pos = mul(view_projection_matrix, float4(tile_pos + input.pos.xy, 0, 1));
int2 pos = int2(input.instance_id % map_width, int(input.instance_id / map_width));
int2 selection_min = min(drag_start, mouse);
int2 selection_max = max(drag_start, mouse);
output.selected = select(all(pos >= selection_min) && all(pos <= selection_max), 1, 0);
return output;
}
[[vk::binding(0, 3)]]
cbuffer fragment_constants {
float4 tint;
float4 selected_tint;
}
[shader("fragment")]
PixelShaderOutput main_fragment(VertexShaderOutput input) {
PixelShaderOutput output;
output.color = select(input.selected != 0, selected_tint, tint);
return output;
}