#define COMPUTE_SHADER_TILE_GROUP_DIM 64

//This is the buffer from the renderer
//Renderer automatically assigns BACKBUFFER semantic
AppendStructuredBuffer<float3> AppendPositionBuffer : BACKBUFFER;

//TextureArray we want to read from
Texture2D tex <string uiname="Texture";>;

float Threshhold = 0.5;

//Buffer containing uvs for sampling
StructuredBuffer<float2> uv <string uiname="UV Buffer";>;
//StructuredBuffer<float3> depth;

SamplerState mySampler : IMMUTABLE
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};


[numthreads(COMPUTE_SHADER_TILE_GROUP_DIM, 1, 1)]
void CS( uint3 groupId : SV_GroupID, uint3 i : SV_DispatchThreadID, uint3 groupThreadId    : SV_GroupThreadID)
{ 
	float4 col = tex.SampleLevel(mySampler,uv[i.x],0);

	float l = (col.r + col.g + col.b)/3;
	
	//AppendPositionBuffer.Append(float3(col.r, col.g, l));
	
	if (l >= Threshhold){
		AppendPositionBuffer.Append(float3(uv[i.x].x, uv[i.x].y, l));
	}

}


technique11 Process
{
	pass P0
	{
		SetComputeShader( CompileShader( cs_5_0, CS() ) );
	}
}







