#include "dxstdafx.h"
#include "CelShading.h"

#pragma once


//------------------------------------------------------------------------------------------------
// Constructor
// Makes the EffectCommon class to load the effect and setup the basics handles (world matrix,etc)
// And if the effect is correctly loaded, it initialize its own handles and variables
//------------------------------------------------------------------------------------------------
CelShading::CelShading() : RTEffectsCommon(L"./FXFiles/RealTime/CelShading.fx")
{
	// If the effect is correctly loaded
	if(m_pEffect)
	{
		// Retrieve the cel-shading specific handles
		m_hBacklightEmulation = m_pEffect->GetParameterByName(NULL, "g_bBacklightEmulation");
		m_hNbShades = m_pEffect->GetParameterByName(NULL, "g_fNbShades");

		// Prepare the handle for the technique
		m_hDot3CelShadingTechnique = m_pEffect->GetTechniqueByName("Dot3CelShading");
	}
	else // If no effect
	{
		// Every handle is NULL
		m_hBacklightEmulation  =
		m_hNbShades =
		m_hDiffuseTexture =
		m_hDot3CelShadingTechnique = NULL;
	}

	// Init the default effect parameters value
	m_bBacklightemulation = true;
	m_fNbShades = 2.0f;
}


//--------------------------------------------------------------------------------------
// Update the shader effect parameters and setup the technique
//--------------------------------------------------------------------------------------
void CelShading::SetupCurrentEffectParameters()
{
	// Setup cel-shading values
	m_pEffect->SetBool(m_hBacklightEmulation, m_bBacklightemulation);
	m_pEffect->SetFloat(m_hNbShades, m_fNbShades);

	// Use the Dot3 Cel-Shading Technique
	m_pEffect->SetTechnique(m_hDot3CelShadingTechnique);
}