#include "common.slang"

struct VertexShaderInput {
    // Per Vertex
    uint vertex_id : SV_VertexID;
    float3 pos;

    // Per Instance
    float4 pos_size;
    float4 uv0uv1;
    float4 uv2uv3;
};

struct VertexShaderOutput {
    float4 pos : SV_POSITION;
    float2 uv;
};

struct PixelShaderOutput {
	float4 color : SV_TARGET;
};

[shader("vertex")]
VertexShaderOutput main_vertex(VertexShaderInput input) {
    VertexShaderOutput output;

    float4x4 view_matrix = view(float3(camera_x, camera_y, 0), radians(camera_tilt), camera_distance);
    float4x4 projection_matrix = projection(radians(fovy_degrees), aspect_ratio, NEAR_PLANE);
    float4x4 view_projection_matrix = mul(projection_matrix, view_matrix);

    output.pos = mul(view_projection_matrix, float4(input.pos_size.xy + input.pos.xy, 0, 1));
    
    switch(input.vertex_id) {
        case 0: output.uv = input.uv0uv1.xy; break;
        case 1: output.uv = input.uv0uv1.zw; break;
        case 2: output.uv = input.uv2uv3.xy; break;
        case 3: output.uv = input.uv2uv3.zw; break;
    }

    return output;
}

[[vk::binding(0, 2)]]
Sampler2D<float4> tex1;

[shader("pixel")]
PixelShaderOutput main_fragment(VertexShaderOutput input) {
	PixelShaderOutput output;

	output.color = tex1.Sample(float2(input.uv));
	
	return output;
}
