//////////////////////////////////////////////////////////////////////////////
//
// Asura_PS2_Shadows.h
//
// Copyright (c) 2003-2004 Rebellion. All rights reserved.
// Some portions based on SCEE sample.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_PS2_SHADOWS_H___
#define ___ASURA_PS2_SHADOWS_H___ 1

// M A C R O S ///////////////////////////////////////////////////////////////

// Override these in your project's Asura_EngineConfiguration.h if required.
#ifndef ASURA_PS2_FADE_SHADOW_DIST_START
    #define ASURA_PS2_FADE_SHADOW_DIST_START        (15.0f)
#endif
#ifndef ASURA_PS2_FADE_SHADOW_DIST_END
    #define ASURA_PS2_FADE_SHADOW_DIST_END          (20.0f)
#endif
#ifndef ASURA_PS2_SHADOW_ALPHA
    #ifdef ASURA_PS2_ADJUST_SHADOWS_FOR_STATIC_LIGHTING
        #define ASURA_PS2_SHADOW_ALPHA              (0.6f)
    #else
        #define ASURA_PS2_SHADOW_ALPHA              (0.3f)
    #endif
#endif
#ifndef ASURA_PS2_SHADOW_OFFSET_Y
    #define ASURA_PS2_SHADOW_OFFSET_Y               (-0.02f)
#endif
#ifndef ASURA_PS2_SHADOW_CASTING_LIGHT_OFFSET_Y
    #define ASURA_PS2_SHADOW_CASTING_LIGHT_OFFSET_Y (-50.0f)
#endif
#ifndef ASURA_PS2_SHADOW_CASTING_BACKFACE_BIAS
	#define ASURA_PS2_SHADOW_CASTING_BACKFACE_BIAS (0.1f)
#endif
#ifndef ASURA_PS2_SHADOW_CASTING_BACKFACE_RATE
	#define ASURA_PS2_SHADOW_CASTING_BACKFACE_RATE (1280.0f)
#endif

// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////

class Asura_Animation;
class Asura_SphericalHarmonics_Order2_RGB;
class Asura_Vector_3;

// C L A S S E S /////////////////////////////////////////////////////////////

union Asura_PS2_QW;

class Asura_PS2_Shadows
{

    public:

        // C L A S S   M E T H O D S /////////////////////////////////////////
        
        //
        // Functionality for projected shadows.
        //

		// NOTE : this class ONLY deals with those things which are not dependent on a specific shadow buffer
		// hence there is a lot less code that there used to be !

        // Methods for dealing with shadow position and fading the alpha
        // according to how far the receiving surface is away from the caster.
        // Note that the y coordinate returned is not biased so callers will
        // need to deal with offsetting the shadow to prevent z fighting.
        static void Proj_GetShadowYAndHeightForAnim( const Asura_Animation* pxAnim, const Asura_Vector_3& xAnimPos, float* pfShadowY, float* pfHeight );
        static void Proj_GetShadowYAndHeightForPos( const Asura_Vector_3& xPos, float* pfShadowY, float* pfHeight );

        static u_int  Proj_GetRenderToBfrPRIMSetting( void );
        static u_long Proj_GetRenderToBfrRGBAQ( void );

        //
        // General shadow-related utility methods.
        //

        // Returns value in range [0, 255].
        static float CalcAlphaForMinDistFromCam( const Asura_Vector_3& xBSCentre, float fBSRadius, u_int uCamVisFlags, float* pfMinDistFromCam = NULL );
        static float CalcAlphaForMinDistFromCam( float fMinDistFromCam );

        // Returns a value in [0, 2]. Accounts internally for squared falloff
        // being disabled. The SH is assumed to be in worldspace.
        static float CalculateShadowLightLevelFromSH( const Asura_SphericalHarmonics_Order2_RGB& xSH, float fAlpha );

		static float s_fShadowBackfaceBias;		// when set to zero, vertical faces will not be shadowed
		static float s_fShadowBackfaceRate;		// determines how quickly we go from no shadow to full shadow

		static float s_fShadowDistanceFalloffStart;	// distance at which shadows start to fade out
		static float s_fShadowDistanceFalloffEnd;	// distance at which there are no shadows

		static void Proj_GetShadowFalloffControls( Asura_PS2_QW *pxOut );

};

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ___ASURA_PS2_SHADOWS_H___
