#pragma once

#include "..\DXFunctions\RenderList.h"

class ShadowRenderList : public RenderList
{
	DXColor m_LightColor;
	DXVector3 m_LightDir;
	float	m_ConstBias;
	float	m_SlopeBias;
	float	m_LambertScale;
	bool	m_UseID;

public:
	ShadowRenderList(void)
	{
		m_LightColor = DXColor(1, 1, 1, 1);
		m_LightDir = DXVector3(0, 0, -1);
		m_ConstBias = 1;
		m_SlopeBias = 4;
		m_LambertScale = 1;
	}

	~ShadowRenderList(void){}

	void OnInitShader(ShaderEffect* const fx) 
	{
		D3DXHANDLE handle;

		handle = fx->GetShader()->GetParameterBySemantic(NULL, "LIGHTDIR");
		if (handle)
			fx->SetFloatArray(handle, (float*)&m_LightDir, 3);

		handle = fx->GetShader()->GetParameterBySemantic(NULL, "LIGHTCOLOR");
		if (handle)
			fx->SetVector(handle, static_cast<DXVector4>(m_LightColor));

		handle = fx->GetShader()->GetParameterBySemantic(NULL, "SMCONSTBIAS");
		if (handle)
			fx->SetFloat(handle, m_ConstBias);

		handle = fx->GetShader()->GetParameterBySemantic(NULL, "SMSLOPEBIAS");
		if (handle)
			fx->SetFloat(handle, m_SlopeBias);

		handle = fx->GetShader()->GetParameterBySemantic(NULL, "LAMBERTSCALE");
		if (handle)
			fx->SetFloat(handle, m_LambertScale);
	}
	
	void SetLight(const DXVector3& dir, const DXColor& col)
	{
		m_LightDir = dir;
		m_LightColor = col;
	}

	void SetSMBias(const float constbias, const float slopebias)
	{
		m_ConstBias = constbias;
		m_SlopeBias = slopebias;
	}

	void SetLambertScale(const float scale)
	{
		m_LambertScale = scale;
	}

	//set all jobs 0 that are culled
	void CullJobsByPlane(const DXPlane& p)
	{
		int n = m_List.GetElementCount();
	
		RenderJob** pljob = m_List.GetStack();

		while(n--)
		{
			RenderJob** const pjob = pljob++;
			const RenderJob* const job = *pjob;

			if(!job || !job->UserData)
				continue;
	
			const OBS* const obs = (OBS*)job->UserData;
			if(obs->IsCulled(p))
				*pjob = NULL;
		}
	}
	
	void SetUseID(const bool useid) { m_UseID = useid; }
};