#include "world.inc"
#include "material.inc"

struct VS_INPUT
{
	float4 Pos : POSITION;
	float4 Color : COLOR0;
};

struct GS_INPUT
{
	float4 Pos : SV_POSITION;
	float4 Color : COLOR0;
};

struct PS_INPUT
{
	float4 Pos : SV_POSITION;
	float4 Col : COLOR0;
};


GS_INPUT VS(const VS_INPUT In)
{
	GS_INPUT Out;
	Out.Pos = mul(In.Pos, WorldViewProj);
	Out.Color = In.Color;
	return Out;
}

// Geometry shader for a wire
[maxvertexcount(8)]
void GS(lineadj GS_INPUT input[4], inout LineStream<PS_INPUT> stream)
{
	PS_INPUT output;

	for(uint i=0; i<4; i++){
		if(input[i].Color.a > 0){
			output.Pos = input[i].Pos;
			output.Col = float4(0.0, 0.0, 0.0, input[i].Color.a);
			stream.Append(output);

			uint i1 = (i+1)%4;
			output.Pos = input[i1].Pos;
			output.Col = float4(0.0, 0.0, 0.0, input[i].Color.a);
			stream.Append(output);

			stream.RestartStrip();
		}
	}
}

float4 PS(PS_INPUT In) : SV_Target
{
	return In.Col;
}

