www.pudn.com > notWow.rar > Effect.cpp
#include "Effect.h"
#include "Config.h"
extern Config g_Config;
bool Effect::Init(LPDIRECT3DDEVICE9 pd3dDevice)
{
m_pd3dDevice = pd3dDevice;
DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3DXSHADER_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3DXSHADER_DEBUG;
#endif
#ifdef DEBUG_VS
dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT;
#endif
#ifdef DEBUG_PS
dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT;
#endif
HRESULT hr;
if(g_Config.UsePST())
hr = D3DXCreateEffectFromFile(m_pd3dDevice, L"hlsl.fx", NULL, NULL, dwShaderFlags, NULL, &m_pEffect, NULL );
else
hr = D3DXCreateEffectFromFile(m_pd3dDevice, L"hlsl_nps.fx", NULL, NULL, dwShaderFlags, NULL, &m_pEffect, NULL );
if(FAILED(hr))
return false;
m_hTexture = m_pEffect->GetParameterByName(0,"g_Texture");
m_hViewProj = m_pEffect->GetParameterByName(0,"g_mViewProj");
m_hMatrixPalette = m_pEffect->GetParameterByName(0,"g_mMatrixPalette");
m_hAmbient = m_pEffect->GetParameterByName(0,"g_MaterialAmbient");
m_hDiffuse = m_pEffect->GetParameterByName(0,"g_MaterialDiffuse");
m_hEmissive = m_pEffect->GetParameterByName(0,"g_MaterialEmissive");
m_hSpecular = m_pEffect->GetParameterByName(0,"g_MaterialSpecular");
m_hPosition = m_pEffect->GetParameterByName(0,"g_Position");
m_hDirection = m_pEffect->GetParameterByName(0,"g_Direction");
m_hAlpha = m_pEffect->GetParameterByName(0,"g_Alpha");
m_hLightDir = m_pEffect->GetParameterByName(0,"g_LightDir");
m_hLightColor = m_pEffect->GetParameterByName(0,"g_LightColor");
return true;
}
bool Effect::Reset()
{
return SUCCEEDED(m_pEffect->OnResetDevice());
}
void Effect::Lost()
{
m_pEffect->OnLostDevice();
}
void Effect::Free()
{
SAFE_RELEASE(m_pEffect);
}
void Effect::SetTechnique(EFFECTTYPE Type)
{
if(Type == EFFECT_WORLD)
m_pEffect->SetTechnique("World");
else if(Type == EFFECT_WORLD_FAR)
m_pEffect->SetTechnique("World_Far");
else if(Type == EFFECT_TERRIAN)
m_pEffect->SetTechnique("Terrian");
else if(Type == EFFECT_TERRIAN_FAR)
m_pEffect->SetTechnique("Terrian");
else if( Type == EFFECT_CHAR)
m_pEffect->SetTechnique("Char");
else if( Type == EFFECT_ITEM )
m_pEffect->SetTechnique("Item");
else if( Type == EFFECT_SKY )
m_pEffect->SetTechnique("Sky");
else if( Type == EFFECT_BG)
m_pEffect->SetTechnique("BG");
}
void Effect::SetTechnique(MODELTYPE Type)
{
if( Type & MODEL_WORLD )
m_pEffect->SetTechnique("World");
else if( (Type & MODEL_CHARACTER) || (Type & MODEL_CREATURE) )
m_pEffect->SetTechnique("Char");
else if( Type & MODEL_ITEM )
m_pEffect->SetTechnique("Item");
else if( Type & MODEL_TERRIAN)
m_pEffect->SetTechnique("Terrian");
}
void Effect::SetTexture(LPDIRECT3DTEXTURE9 pTex)
{
if(g_Config.UsePST())
m_pEffect->SetTexture(m_hTexture,pTex);
else
m_pd3dDevice->SetTexture(0,pTex);
}