Mikemon/assets/shader/grid.slang

51 lines
1.2 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));
tile_pos -= float2(0.5, 0.5);
output.pos = mul(view_projection_matrix, float4(tile_pos + input.pos.xy, 0, 1));
uint2 pos = uint2(input.instance_id % map_width, uint(input.instance_id / map_width));
uint2 selection_min = min(drag_start, mouse);
uint2 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;
}