#include "/Engine/Private/Common.ush"


/* PixelShader */

Texture2D InTexture;
SamplerState InTextureSampler;
float4x4 InHomographyMatrix;

void MainPS(
	FScreenVertexOutput Input,
	out float4 OutColor : SV_Target0
	)
{	
	float2 Position = float2(Input.UV.x, Input.UV.y);

	float S = InHomographyMatrix[2][0] * Position.x + InHomographyMatrix[2][1] * Position.y + InHomographyMatrix[2][2];
	
	float U = (InHomographyMatrix[0][0] * Position.x + InHomographyMatrix[0][1] * Position.y + InHomographyMatrix[0][2]) / S;
	
	float V = (InHomographyMatrix[1][0] * Position.x + InHomographyMatrix[1][1] * Position.y + InHomographyMatrix[1][2]) / S;
	
	float2 UV = float2(U, V);

	OutColor = Texture2DSample(InTexture, InTextureSampler, UV);
}
