/****************************************************************************************

		BasicShader.h

		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Ray Dream
		Date:	9/29/98

		Revision History

		when		who					what & why
		==========	================	======================================================
		08/11/99	Guillaume&Christy	Added inheritance to all the Basic* classes

*****************************************************************************************/

#ifndef __BasicShader__
#define __BasicShader__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "BasicCOMImplementations.h"
#include "MCBasicTypes.h"

#include "I3DExShader.h"

#include "IMFResponder.h"

struct I3DShShader;

/// \addtogroup BaseClass
/// \{
/***********************************************************************\
*                                                                       *
*     TBasicShader                                                      *
*                                                                       *
\***********************************************************************/
/// Basic Shader class.  Derive from this for a default implementation of I3DExShader
/// \see I3DExShader
class TBasicShader :  public I3DExShader, public TBasicDataExchanger
{
	public:
		virtual MCCOMErr 		MCCOMAPI QueryInterface						(const MCIID &riid, void** ppvObj);
		virtual uint32 			MCCOMAPI AddRef								()	{ return TBasicDataExchanger::AddRef(); }
	
		virtual boolean 		MCCOMAPI IsEqualTo							(I3DExShader* aShader);
		virtual MCCOMErr 		MCCOMAPI GetShadingFlags					(ShadingFlags& theFlags);
		virtual EShaderOutput	MCCOMAPI GetImplementedOutput				(); 
		virtual boolean			MCCOMAPI WantsTransform						() { return true; };
		virtual boolean			MCCOMAPI IsChannelConstantInUVSpace			(const uint32& uvSpaceID, const uint32& channelIndex);
		virtual MCCOMErr		MCCOMAPI GetShadersForChannel				(const uint32& uvSpaceID, const uint32& channelIndex, TMCPtrArray<I3DShShader>& outShaders);

		virtual boolean			MCCOMAPI HasExplicitLightingModel			(const LightingContext& lightingContext);
		virtual MCCOMErr		MCCOMAPI ShadeAndLight2						(LightingDetail& result,const LightingContext& lightingContext,I3DShLightingModel* inDefaultLightingModel,TAbsorptionFunction* absorptionFunction);
		virtual MCCOMErr		MCCOMAPI DoShade							(ShadingOut& result,ShadingIn& shadingIn);
		virtual real			MCCOMAPI GetValue							(real& result,boolean& fullArea,ShadingIn& shadingIn);
		virtual real			MCCOMAPI GetColor							(TMCColorRGBA& result,boolean& fullArea,ShadingIn& shadingIn);
		virtual void			MCCOMAPI GetReflection						(TReflectionParameters& reflectionParams,const ShadingIn& shadingIn);
		virtual void			MCCOMAPI GetTransparency					(TTransparencyParameters& transparencyParams,const ShadingIn& shadingIn);
		virtual real			MCCOMAPI GetVector							(TVector3& result,ShadingIn& shadingIn);
		virtual void			MCCOMAPI GetShaderApproximation				(ShadingOut& result,ShadingIn& shadingIn);
		virtual void			MCCOMAPI GetShaderApproxColor				(TMCColorRGBA& result,ShadingIn& shadingIn);
		virtual MCCOMErr		MCCOMAPI GetBump							(TVector3& result,ShadingIn& shadingIn);

		virtual void			MCCOMAPI ConvertToPoly						(TMCArray<TVector2>* vertices);
		virtual boolean			MCCOMAPI OutlineInPreviewMode				();
		virtual boolean			MCCOMAPI Contains							(ShadingIn& shadingIn, TVector2& localUV);		

		virtual MCCOMErr		MCCOMAPI GetOriginalParametricTextureMap	(const uint32&uvSpaceID, const uint32&channelIndex, IShTextureMap** outMap)
										{ *outMap = NULL; return MC_S_FALSE; }

		virtual boolean			MCCOMAPI GetSubShaderPreview(IShParameterComponent** shader, IShParameterComponent* subShader, FourCharT subShaderKeyword);
		virtual void			MCCOMAPI GetShaderPreview(IShParameterComponent** shader);
		virtual boolean			MCCOMAPI PreviewSubShaderAsTopShader(IDType keyword) { return false; }

		virtual int16			MCCOMAPI GetSubShaderViewID(IDType keyword) { return -1; }
		virtual MCCOMErr		MCCOMAPI SetDefaultParameters() { return MC_S_OK; }
		virtual EShaderFunctionType MCCOMAPI GetSubShaderType(IDType keyword) { return kUnknownFunctionType; }

		virtual MCCOMErr		MCCOMAPI SetupPreviewScene(IPreviewMaker* previewMaker, I3DShMasterShader* masterShader) { return MC_E_NOTIMPL; }

		virtual boolean			MCCOMAPI CanBeTransparent(int32 shadingDomainIndex) { return true; }

		// ****************************************************************************
		//								CalculateDirectLighting
		// 
		// -Description:
		//
		// Should calculate the direct lighting and fill result.fAmbientLight result.fDiffuseLight
		// and result.fSpecularLight.
		//
		//
		virtual void MCCOMAPI CalculateDirectLighting(LightingDetail& result,const LightingContext&	lightingContext);
		virtual void MCCOMAPI CalculateReflection(TMCColorRGB& reflectionColor,const LightingContext&	lightingContext,const ShadingOut& shading);
		virtual void MCCOMAPI CalculateCaustics(TMCColorRGB& causticColor,const LightingContext&	lightingContext,const ShadingOut& shading);
		virtual void MCCOMAPI CalculateIndirectLighting(TMCColorRGB& indirectDiffuseColor, real& ambientOcclusionFactor, const LightingContext& lightingContext,const ShadingOut& shading);
		virtual void MCCOMAPI CalculateTransparency(TMCColorRGB& resColor,real32& outAlpha,const LightingContext&	lightingContext,const ShadingOut& shading);
		virtual void MCCOMAPI CalculateAlpha(LightingDetail& result,const LightingContext& lightingContext,const ShadingOut& shading,TAbsorptionFunction* absorptionFunction);
		virtual void MCCOMAPI CalculateSubsurfaceScattering(TMCColorRGB& subsurfaceColor,const TMCColorRGB& currentColor,const LightingContext&	lightingContext,const ShadingOut& shading);
		// ****************************************************************************
		//                             GetRecommendedTextureSize
		//
		/// Calculate the intrinsic appropriate texture size.
		/// \param[in]  channelIndex The channel for which texture is searched
		// \return true if there is such a size, or false of the texture is procedural 
		virtual boolean  MCCOMAPI GetRecommendedTextureSize(uint32 channelIndex, uint32& width, uint32& height) const;
		// ****************************************************************************
		//                             GetRelevantTextureMapFile
		//
		/// \param[in]  channelIndex The channel for which texture is searched
		/// Get the texture map file associated to the specified shading domain.
		virtual void MCCOMAPI GetRelevantTextureBucketCache(uint32 channelIndex, boolean allowMultiplierModification, IShTextureMapBucketCache** outTextureMapFile) const;
		// ****************************************************************************
		//								GetConstantColor
		//
		//  Get the constant color of the shader
		//
		// \return MC_S_OK if there is such a constant color, or MC_E_NOTIMPL otherwise
		virtual MCCOMErr	MCCOMAPI GetConstantColor(TMCColorRGBA& resColor) const;
    // ****************************************************************************
	//								GetTextureMultiplyColor
    //
	//  Get the texture multiply color
    virtual TMCColorRGB MCCOMAPI GetTextureMultiplyColor() const;
    // ****************************************************************************
	//								GetBumpAmplitude
    //
	//  Get the bump amplitude
    virtual real MCCOMAPI GetBumpAmplitude() const;
    // ****************************************************************************
	//								GetConstantValue
    //
	//  Get the constant value of the shader
    //
    // \return MC_S_OK if there is such a constant value, or MC_E_NOTIMPL otherwise
    virtual MCCOMErr	MCCOMAPI GetConstantValue(real& resValue) const;
};
/// \}
#endif
