<languageVersion: 1.0;>
kernel LambertNormalMapShaderDir
<
	namespace: "com.away3d";
	vendor: "Away3d";
	version: 1;
	description: "Applies a Lambert (diffuse) shaded lighting effect with support for normal maps, used for directional lights.";
>
{
	input image3 lightMap;
	input image3 normalMap;
	input image3 positionMap;
	output pixel3 dst;
	
	parameter float4x4 positionTransformation
	<
		minValue: float4x4(-8000.0);
		maxValue: float4x4(8000.0);
		defaultValue: float4x4(0.0);
	>;
	
	parameter float3 diffuseColor
	<
		minValue: float3(0.0);
		maxValue: float3(1.0);
		defaultValue: float3(1.0);
		description: "The diffuse colour of the light";
	>;
	
	parameter float3 lightDirection
	<
		minValue: float3(-1.0);
		maxValue: float3(1.0);
		defaultValue: float3(0.0, 0.0, 1.0);
		description: "The direction of the light source";
	>;
	
	void evaluatePixel()
	{
		float3 coord3d = sampleNearest(positionMap, outCoord());
		coord3d.x = coord3d.x*positionTransformation[0][0]+positionTransformation[3][0];
		coord3d.y = coord3d.y*positionTransformation[1][1]+positionTransformation[3][1];
		coord3d.z = coord3d.z*positionTransformation[2][2]+positionTransformation[3][2];
		
		float3 n = normalize(2.0*(sampleNearest(normalMap, outCoord())-float3(0.5)));
		
		float nDotD = max(-dot(lightDirection, n), 0.0);
		
		dst = sampleNearest(lightMap, outCoord())+diffuseColor*nDotD;
	}
}
