#include "..\Header Files\Ninfa3D.h"

extern IVideoDriver* driver;

class MappingShaderCallBack : public IShaderConstantSetCallBack
{
public:
	virtual void OnSetConstants(video::IMaterialRendererServices* services,s32 userData)
	{
		int Index[] = { 0,1,2 };
		services->setPixelShaderConstant("colorMap",reinterpret_cast<const float*>(&Index[0]),1);
		services->setPixelShaderConstant("normalMap",reinterpret_cast<const float*>(&Index[1]),1);
		services->setPixelShaderConstant("specularMap",reinterpret_cast<const float*>(&Index[2]),1);
		services->setPixelShaderConstant("heightMap",reinterpret_cast<const float*>(&Index[2]),1);

		unsigned int cnt = driver->getDynamicLightCount();

		float LightRad[6];
		int LightType[6];
		bool LightExist[6];

		for(unsigned int i = 0;i<6;++i)
		{
			SLight light;

			if(i < cnt)
				light = driver->getDynamicLight(i);
			else
			{
				light.DiffuseColor.set(0.0f,0.0f,0.0f);
				light.SpecularColor.set(0.0f,0.0f,0.0f);
				light.AmbientColor.set(0.0f,0.0f,0.0f);
				light.Radius = 1.0f;
			}

			LightRad[i] = (0.5f / (light.Radius * 2.0f));

			switch(light.Type)
			{
			case ELT_POINT:
				LightType[i] = 1;
				break;
			case ELT_SPOT:
				LightType[i] = 2;
				break;
			case ELT_DIRECTIONAL:
				LightType[i] = 3;
				break;
			}

			if((light.DiffuseColor.getRed()   != 0.0f) &&
			   (light.DiffuseColor.getBlue()  != 0.0f) &&
			   (light.DiffuseColor.getGreen() != 0.0f))
				LightExist[i] = true;
			else
				LightExist[i] = false;
		}

		services->setVertexShaderConstant("LightExist[0]",reinterpret_cast<const float*>(&LightExist[0]),6);

		services->setPixelShaderConstant("LightRad[0]",reinterpret_cast<const float*>(&LightRad[0]),6);
		services->setPixelShaderConstant("LightExist[0]",reinterpret_cast<const float*>(&LightExist[0]),6);
		services->setPixelShaderConstant("LightType[0]",reinterpret_cast<const float*>(&LightType[0]),6);
	}
};