#include "ShaderLight.h"




LightType ShaderLight::getLightType() const
{
	return SHADER_LIGHT;
}
ShaderLight::ShaderLight( void )
{
}
ShaderLight::ShaderLight( const Light& light ): LightWrapper(light)
{
}
void ShaderLight::insertPhongParams( std::vector<FragmentParam>& output )
{
	std::vector<float> temp;
	PhongLight* phongLight = (PhongLight*) this->light;

	temp.push_back( phongLight->color[0] * phongLight->intensity ); 
	temp.push_back( phongLight->color[1] * phongLight->intensity ); 
	temp.push_back( phongLight->color[2] * phongLight->intensity ); 

	output.push_back(FragmentParam("intensity", temp));
	temp.clear();
	temp.push_back( ((PhongLight*) (this->light))->attenuationExp);
	output.push_back(FragmentParam("attenuation", temp));
}

void ShaderLight::insertParams( std::vector<FragmentParam>& output )
{
	switch ( this->light->getLightType() )
	{
		case SPOT_PHONG:
		{
			this->insertPhongParams( output );
			SpotLightPhong* spotLight = (SpotLightPhong*) this->light;

			std::vector<float> temp;
			temp.push_back( spotLight->position.x()); 
			temp.push_back(	spotLight->position.y()); 
			temp.push_back(	spotLight->position.z());
			output.push_back(FragmentParam("lightPosition", temp));

			temp.clear();
			temp.push_back(	spotLight->direction.x()); 
			temp.push_back(	spotLight->direction.y()); 
			temp.push_back(	spotLight->direction.z());
			output.push_back(FragmentParam("direction", temp));

			temp.clear();
			temp.push_back(	spotLight->directionalExp);
			output.push_back(FragmentParam("directionality", temp));
		}
		break;

		case SPOT_PHONG_VRML:
		{
			this->insertPhongParams( output );

			SpotLightPhongVRML* spotLight = (SpotLightPhongVRML*) this->light;

			std::vector<float> temp;
			temp.push_back( spotLight->position.x()); 
			temp.push_back(	spotLight->position.y()); 
			temp.push_back(	spotLight->position.z());
			output.push_back(FragmentParam("lightPosition", temp));

			temp.clear();
			temp.push_back(	spotLight->direction.x()); 
			temp.push_back(	spotLight->direction.y()); 
			temp.push_back(	spotLight->direction.z());
			output.push_back(FragmentParam("direction", temp));

			temp.clear();
			temp.push_back(	spotLight->innerConeCos);
			output.push_back(FragmentParam("innerCone", temp));

			temp.clear();
			temp.push_back(	spotLight->outerConeCos);
			output.push_back(FragmentParam("outerCone", temp));
		}
		break;

		case OMNI_PHONG:
		{
			this->insertPhongParams( output );
			OmniLightPhong* omniLight = (OmniLightPhong*) this->light;

			insertPhongParams(output);
			std::vector<float> temp;
			temp.push_back( omniLight->position.x()); 
			temp.push_back( omniLight->position.y()); 
			temp.push_back( omniLight->position.z());
			output.push_back(FragmentParam("lightPosition", temp));
		}
		break;

		case RECTANGLE_PHONG:
		{
			this->insertPhongParams( output );
			RectangleLightPhong* rectLight = (RectangleLightPhong*) this->light;

			std::vector<float> temp;
			temp.push_back( rectLight->position.x()); 
			temp.push_back( rectLight->position.y()); 
			temp.push_back( rectLight->position.z());
			output.push_back(FragmentParam("lightPosition", temp));

			temp.clear();
			temp.push_back( rectLight->vec1.x()); 
			temp.push_back( rectLight->vec1.y()); 
			temp.push_back( rectLight->vec1.z());
			output.push_back(FragmentParam("vector1", temp));

			temp.clear();
			temp.push_back( rectLight->vec2.x()); 
			temp.push_back( rectLight->vec2.y()); 
			temp.push_back( rectLight->vec2.z());
			output.push_back(FragmentParam("vector2", temp));
		}
		break;

		case DIRECTIONAL_PHONG:
		{
			this->insertPhongParams( output );
			DirectionalLightPhong* dirLight = (DirectionalLightPhong*) this->light;

			std::vector<float> temp;
			temp.push_back( dirLight->position.x()); 
			temp.push_back( dirLight->position.y()); 
			temp.push_back( dirLight->position.z());
			output.push_back(FragmentParam("lightPosition", temp));

			temp.clear();
			temp.push_back( dirLight->vec1.x()); 
			temp.push_back( dirLight->vec1.y()); 
			temp.push_back( dirLight->vec1.z());
			output.push_back(FragmentParam("vector1", temp));

			temp.clear();
			temp.push_back( dirLight->vec2.x()); 
			temp.push_back( dirLight->vec2.y()); 
			temp.push_back( dirLight->vec2.z());
			output.push_back(FragmentParam("vector2", temp));
		}
		break;

		default:
			assert( !"Unexpected light type" );
			break;
	}
}
ShaderLight::~ShaderLight(void)
{
}