#pragma once
#include "deferredshadowtechnique.h"
#include "ShadowMapping.h"
#include "..\GameGUI\GUIElement.h"

enum CONFMETHOD
{
	CM_SIMPLE = 0,
	CM_ADAPTED,
	CM_B2FFOCUSDYNAMIC,
	CM_B2FFOCUS,
	CM_COUNT
};

class DeferredShadowConfidence : public DeferredShadowTechnique
{
	ShaderEffect* m_FXConfShadow;
	ShaderEffect* m_FXConfTest;

	CONFMETHOD	m_Method;
	bool		m_bPCFPreTest;
	float		m_ConfT[CM_COUNT];
	int			m_MaxJitter;
	float		m_B2FFocusScale;
	int			m_Threshold;
	int			m_FramesBelow;
	SMJITTERTYPE m_JitterType;
	
	float TestConfReached(const float vnear, const float vfar, const int maxsteps, const Camera& cam) const;

	static void OnConfTechChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData);
	static void OnJitterTypeChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData);
	static void OnPCFPreTestCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData);
	static void OnConfTChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData);
	static void OnMaxPassesChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData);
	static void OnAdaptedThresholdChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData);
	static void OnAdaptedNumBelowChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData);
	
	void CreateMenu(void);

public:
	DeferredShadowConfidence(ShadowApp* const pApp);
	~DeferredShadowConfidence(void);

	void RenderShadowMask(void);
	void DrawControls(void);
	void UpdateInput(void);

	CONFMETHOD GetMethod(void) const { return m_Method; }
	void SetMethod(const CONFMETHOD m);

	bool GetPCFPreTestEnabled(void) const { return m_bPCFPreTest; }
	void SetPCFPreTestEnabled(const bool enable) { m_bPCFPreTest = enable; }
};
