#include "convert_rgb8.hls"

// Vector field
sampler	VECTOR_FIELD	: register (s0);

// Reciprocal of Grid Size
float INV_GRID_SIZE		: register (c1);

void main
	(
		float2 coords	: TEXCOORD0, // grid coordinates
		out float4 div	: COLOR0 // divergence
	)
{
	float4 wL = extractNeg(tex2D(VECTOR_FIELD, coords - float2(INV_GRID_SIZE, 0)));
	float4 wR = extractNeg(tex2D(VECTOR_FIELD, coords + float2(INV_GRID_SIZE, 0)));
	float4 wB = extractNeg(tex2D(VECTOR_FIELD, coords - float2(0, INV_GRID_SIZE)));
	float4 wT = extractNeg(tex2D(VECTOR_FIELD, coords + float2(0, INV_GRID_SIZE)));

	div = compressNeg(0.5f * ((wR.x - wL.x) + (wT.y - wB.y)));
}
