// NeL - MMORPG Framework
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
#include "stddirect3d.h"
#include "driver_direct3d.h"
using namespace std;
using namespace NLMISC;
namespace NL3D
{
// mem allocator for state records
std::allocator CStateRecord::Allocator;
// ***************************************************************************
// The state manager with cache
// ***************************************************************************
HRESULT CDriverD3D::QueryInterface(REFIID /* riid */, LPVOID * /* ppvObj */)
{
H_AUTO_D3D(CDriverD3D_QueryInterface)
return D3D_OK;
}
// ***************************************************************************
ULONG CDriverD3D::AddRef(VOID)
{
H_AUTO_D3D(CDriverD3D_AddRef)
return 0;
}
// ***************************************************************************
ULONG CDriverD3D::Release(VOID)
{
H_AUTO_D3D(CDriverD3D_Release)
return 0;
}
// ***************************************************************************
HRESULT CDriverD3D::LightEnable(DWORD Index, BOOL Enable)
{
H_AUTO_D3D(CDriverD3D_LightEnable)
enableLight ((uint8)Index, Enable!=FALSE);
return D3D_OK;
}
// ***************************************************************************
HRESULT CDriverD3D::SetFVF(DWORD /* FVF */)
{
H_AUTO_D3D(CDriverD3D_SetFVF)
// Not implemented
return D3D_OK;
}
// ***************************************************************************
HRESULT CDriverD3D::SetLight(DWORD Index, CONST D3DLIGHT9* pLight)
{
H_AUTO_D3D(CDriverD3D_SetLight)
_LightCache[Index].Light = *pLight;
touchRenderVariable (&_LightCache[Index]);
return D3D_OK;
}
// ***************************************************************************
HRESULT CDriverD3D::SetMaterial(CONST D3DMATERIAL9* pMaterial)
{
H_AUTO_D3D(CDriverD3D_SetMaterial)
setMaterialState( *pMaterial );
return D3D_OK;
}
// ***************************************************************************
HRESULT CDriverD3D::SetNPatchMode(FLOAT /* nSegments */)
{
H_AUTO_D3D(CDriverD3D_SetNPatchMode)
// Not implemented
return D3D_OK;
}
// ***************************************************************************
HRESULT CDriverD3D::SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader)
{
H_AUTO_D3D(CDriverD3D_SetPixelShader)
setPixelShader (pShader);
return D3D_OK;
}
// ***************************************************************************
HRESULT CDriverD3D::SetPixelShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount)
{
H_AUTO_D3D(CDriverD3D_SetPixelShaderConstantB)
uint i;
for (i=0; iRelease();
}
// ***************************************************************************
bool CDriverD3D::validateShader(CShader *shader)
{
H_AUTO_D3D(CDriverD3D_validateShader)
CShaderDrvInfosD3D *shaderInfo = static_cast((IShaderDrvInfos*)shader->_DrvInfo);
if (!shaderInfo->Validated)
{
// Choose the good method
D3DXHANDLE hTechnique = NULL;
D3DXHANDLE hCurrentTechnique = NULL;
while (hTechnique == NULL)
{
if (shaderInfo->Effect->FindNextValidTechnique(hCurrentTechnique, &hCurrentTechnique) != D3D_OK)
return false;
// Info
#ifdef NL_FORCE_TEXTURE_STAGE_COUNT
D3DXTECHNIQUE_DESC desc;
nlverify (shaderInfo->Effect->GetTechniqueDesc(hCurrentTechnique, &desc) == D3D_OK);
// Check this is compatible
const uint len = strlen(desc.Name);
if (len)
{
char shaderStageCount = desc.Name[len-1];
if ((shaderStageCount>='0') && (shaderStageCount<='9'))
{
uint stageCount = NL_FORCE_TEXTURE_STAGE_COUNT;
if ((uint)(shaderStageCount-'0')<=stageCount)
// The good technique
hTechnique = hCurrentTechnique;
}
}
#else // NL_FORCE_TEXTURE_STAGE_COUNT
hTechnique = hCurrentTechnique;
#endif // NL_FORCE_TEXTURE_STAGE_COUNT
#ifdef NL_DEBUG_D3D
{
D3DXTECHNIQUE_DESC desc;
nlverify (shaderInfo->Effect->GetTechniqueDesc(hCurrentTechnique, &desc) == D3D_OK);
if (hTechnique)
nlinfo ("Shader \"%s\" : use technique \"%s\" with %d passes.", shader->getName(), desc.Name, desc.Passes);
}
#endif // NL_DEBUG_D3D
}
// Set the technique
shaderInfo->Effect->SetTechnique(hTechnique);
// Set the state manager
shaderInfo->Effect->SetStateManager (this);
shaderInfo->Validated = true;
}
return true;
}
// ***************************************************************************
bool CDriverD3D::activeShader(CShader *shd)
{
H_AUTO_D3D(CDriverD3D_activeShader)
if (_DisableHardwarePixelShader)
return false;
// Clear current textures
_CurrentShaderTextures.clear();
// Shader has been changed ?
if (shd && shd->_ShaderChanged)
{
// Remove old shader
shd->_DrvInfo.kill();
// Already setuped ?
CShaderDrvInfosD3D *shaderInfo = static_cast((IShaderDrvInfos*)shd->_DrvInfo);
if ( !shd->_DrvInfo )
{
// insert into driver list. (so it is deleted when driver is deleted).
ItShaderDrvInfoPtrList it= _ShaderDrvInfos.insert(_ShaderDrvInfos.end(), NULL);
// create and set iterator, for future deletion.
shaderInfo = new CShaderDrvInfosD3D(this, it);
*it= shd->_DrvInfo = shaderInfo;
}
// Assemble the shader
LPD3DXBUFFER pErrorMsgs;
if (D3DXCreateEffect(_DeviceInterface, shd->getText(), (UINT)strlen(shd->getText())+1, NULL, NULL, 0, NULL, &(shaderInfo->Effect), &pErrorMsgs)
== D3D_OK)
{
// Get the texture handle
uint i;
for (i=0; iTextureHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
name = "color" + toString (i);
shaderInfo->ColorHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
name = "factor" + toString (i);
shaderInfo->FactorHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
name = "scalarFloat" + toString (i);
shaderInfo->ScalarFloatHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
}
}
else
{
nlwarning ("Can't create shader '%s':", shd->getName());
if (pErrorMsgs)
nlwarning ((const char*)pErrorMsgs->GetBufferPointer());
shd->_ShaderChanged = false;
_CurrentShader = NULL;
return false;
}
// Done
shd->_ShaderChanged = false;
}
// Set the shader
_CurrentShader = shd;
return true;
}
static void setFX(CShader &s, const char *name, const char *prog, CDriverD3D *drv)
{
H_AUTO_D3D(setFX)
s.setName(name);
s.setText(prog);
nlverify (drv->activeShader (&s));
}
#define setFx(a,b,c) { setFX(a, b, c, this); }
static const char *CloudFx =
" \n\
texture texture0; \n\
texture texture1; \n\
float4 factor0; \n\
\n\
pixelshader two_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
lrp r0.w, v0, t0, t1; \n\
mov r0.xyz, c0; \n\
+mul r0.w, c0, r0; \n\
}; \n\
\n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
PixelShaderConstant[0] = ; \n\
PixelShader = (two_stages_ps); \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap0Fx =
" \n\
texture texture0; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
technique one_stage_1 \n\
{ \n\
pass p0 \n\
{ \n\
// do a standard lighting with the first light \n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
Texture[0] = ; \n\
ColorOp[0] = MODULATE; \n\
ColorArg1[0] = TEXTURE; \n\
ColorArg2[0] = DIFFUSE; \n\
AlphaOp[0] = SELECTARG1; // for alpha test \n\
AlphaArg1[0] = TEXTURE; \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap0blendFx =
" \n\
texture texture0; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
technique one_stage_1 \n\
{ \n\
pass p0 \n\
{ \n\
// do a standard lighting with the first light \n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = SRCALPHA; \n\
DestBlend = INVSRCALPHA; \n\
\n\
Texture[0] = ; \n\
ColorOp[0] = MODULATE; \n\
ColorArg1[0] = TEXTURE; \n\
ColorArg2[0] = DIFFUSE; \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TEXTURE; \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap0blend_x2Fx =
" \n\
texture texture0; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
technique one_stage_1 \n\
{ \n\
pass p0 \n\
{ \n\
// do a standard lighting with the first light \n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = SRCALPHA; \n\
DestBlend = INVSRCALPHA; \n\
\n\
Texture[0] = ; \n\
ColorOp[0] = MODULATE; \n\
ColorArg1[0] = TEXTURE; \n\
ColorArg2[0] = DIFFUSE; \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TEXTURE; \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap0_x2Fx =
" \n\
texture texture0; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
technique one_stage_1 \n\
{ \n\
pass p0 \n\
{ \n\
// do a standard lighting with the first light \n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
Texture[0] = ; \n\
ColorOp[0] = MODULATE; \n\
ColorArg1[0] = TEXTURE; \n\
ColorArg2[0] = DIFFUSE; \n\
AlphaOp[0] = SELECTARG1; // for alpha test \n\
AlphaArg1[0] = TEXTURE; \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap1Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
float4 factor0; \n\
float4 factor1; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; // for alpha test \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap1blendFx =
" \n\
texture texture0; \n\
texture texture1; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
float4 factor0; \n\
float4 factor1; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = SRCALPHA; \n\
DestBlend = INVSRCALPHA; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap1blend_x2Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
float4 factor0; \n\
float4 factor1; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
// modulate the dyn light by 0.5, because of MODULATE2X \n\
float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
\n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = SRCALPHA; \n\
DestBlend = INVSRCALPHA; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE2X; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap1_x2Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
float4 factor0; \n\
float4 factor1; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
// modulate the dyn light by 0.5, because of MODULATE2X \n\
float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
\n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE2X; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; // for alpha test \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
}; \n\
\n\
";
static const char *Lightmap2Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
texture texture2; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
dword color2; \n\
float4 factor0; \n\
float4 factor1; \n\
float4 factor2; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
\n\
// **** 3 stages technique \n\
pixelshader three_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mul r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique three_stages_3 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShader = (three_stages_ps); \n\
} \n\
} \n\
\n\
// **** 2 stages, no pixel shader technique \n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; // for alpha test \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
Lighting = false; \n\
AlphaBlendEnable = true; \n\
SrcBlend = one; \n\
DestBlend = one; \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
} \n\
} \n\
\n\
";
static const char *Lightmap2blendFx =
" \n\
texture texture0; \n\
texture texture1; \n\
texture texture2; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
dword color2; \n\
float4 factor0; \n\
float4 factor1; \n\
float4 factor2; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
\n\
// **** 3 stages technique \n\
pixelshader three_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mul r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique three_stages_3 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShader = (three_stages_ps); \n\
} \n\
} \n\
\n\
// **** 2 stages, no pixel shader technique \n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
Lighting = false; \n\
DestBlend = one; \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
} \n\
} \n\
\n\
\n\
";
static const char *Lightmap2blend_x2Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
texture texture2; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
dword color2; \n\
float4 factor0; \n\
float4 factor1; \n\
float4 factor2; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
// modulate the dyn light by 0.5, because of MODULATE2X \n\
float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
\n\
\n\
// **** 3 stages technique \n\
pixelshader three_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mul_x2 r0.xyz, r0, t0; \n\
mov r0.w, t0; \n\
}; \n\
\n\
technique three_stages_3 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShader = (three_stages_ps); \n\
} \n\
} \n\
\n\
// **** 2 stages, no pixel shader technique \n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE2X; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
Lighting = false; \n\
DestBlend = one; \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
} \n\
} \n\
\n\
\n\
";
static const char *Lightmap2_x2Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
texture texture2; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
dword color2; \n\
float4 factor0; \n\
float4 factor1; \n\
float4 factor2; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
// modulate the dyn light by 0.5, because of MODULATE2X \n\
float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
\n\
\n\
// **** 3 stages technique \n\
pixelshader three_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mul_x2 r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique three_stages_3 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShader = (three_stages_ps); \n\
} \n\
} \n\
\n\
// **** 2 stages, no pixel shader technique \n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE2X; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; // for alpha test if enabled \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
Lighting = false; \n\
AlphaBlendEnable = true; \n\
SrcBlend = one; \n\
DestBlend = one; \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
} \n\
} \n\
\n\
";
static const char *Lightmap3Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
texture texture2; \n\
texture texture3; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
dword color2; \n\
dword color3; \n\
float4 factor0; \n\
float4 factor1; \n\
float4 factor2; \n\
float4 factor3; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
\n\
// **** 4 stages technique \n\
pixelshader four_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
tex t3; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mad r0.xyz, c3, t3, r0; \n\
mul r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique four_stages_4 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
TexCoordIndex[3] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
Texture[3] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShaderConstant[3] = ; \n\
PixelShader = (four_stages_ps); \n\
} \n\
} \n\
\n\
// **** 3 stages technique \n\
pixelshader three_stages_0_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mul r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique three_stages_3 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShader = (three_stages_0_ps); \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
AlphaBlendEnable = true; \n\
SrcBlend = one; \n\
DestBlend = one; \n\
Lighting = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
ColorOp[2] = DISABLE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; // for case when there's alpha test \n\
AlphaOp[2] = DISABLE; \n\
PixelShader = NULL; \n\
} \n\
} \n\
\n\
// **** 2 stages, no pixel shader technique \n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; // alpha in case were alpha test is used\n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
Lighting = false; \n\
AlphaBlendEnable = true; \n\
SrcBlend = one; \n\
DestBlend = one; \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
} \n\
pass p2 \n\
{ \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
} \n\
} \n\
\n\
\n\
\n\
";
static const char *Lightmap3blendFx =
" \n\
texture texture0; \n\
texture texture1; \n\
texture texture2; \n\
texture texture3; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
dword color2; \n\
dword color3; \n\
float4 factor0; \n\
float4 factor1; \n\
float4 factor2; \n\
float4 factor3; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
\n\
\n\
// **** 4 stages technique \n\
pixelshader four_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
tex t3; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mad r0.xyz, c3, t3, r0; \n\
mul r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique four_stages_4 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
TexCoordIndex[3] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
Texture[3] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShaderConstant[3] = ; \n\
PixelShader = (four_stages_ps); \n\
} \n\
} \n\
\n\
// **** 3 stages technique \n\
pixelshader three_stages_0_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mul r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique three_stages_3 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShader = (three_stages_0_ps); \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
DestBlend = one; \n\
Lighting = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
ColorOp[2] = DISABLE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; \n\
AlphaOp[2] = DISABLE; \n\
PixelShader = NULL; \n\
} \n\
} \n\
\n\
// **** 2 stages, no pixel shader technique \n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
Lighting = false; \n\
DestBlend = one; \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
} \n\
pass p2 \n\
{ \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
} \n\
} \n\
\n\
";
static const char *Lightmap3blend_x2Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
texture texture2; \n\
texture texture3; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
dword color2; \n\
dword color3; \n\
float4 factor0; \n\
float4 factor1; \n\
float4 factor2; \n\
float4 factor3; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
// modulate the dyn light by 0.5, because of MODULATE2X \n\
float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
\n\
\n\
// **** 4 stages technique \n\
pixelshader four_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
tex t3; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mad r0.xyz, c3, t3, r0; \n\
mul_x2 r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique four_stages_4 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
TexCoordIndex[3] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
Texture[3] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShaderConstant[3] = ; \n\
PixelShader = (four_stages_ps); \n\
} \n\
} \n\
\n\
// **** 3 stages technique \n\
pixelshader three_stages_0_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mul_x2 r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique three_stages_3 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShader = (three_stages_0_ps); \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
DestBlend = one; \n\
Lighting = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE2X; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
ColorOp[2] = DISABLE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; \n\
AlphaOp[2] = DISABLE; \n\
PixelShader = NULL; \n\
} \n\
} \n\
\n\
// **** 2 stages, no pixel shader technique \n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = true; \n\
SrcBlend = srcalpha; \n\
DestBlend = invsrcalpha; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MULTIPLYADD; \n\
ColorArg0[0] = DIFFUSE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE2X; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
Lighting = false; \n\
DestBlend = one; \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
} \n\
pass p2 \n\
{ \n\
Texture[0] = ; \n\
TextureFactor = ; \n\
} \n\
} \n\
\n\
";
static const char *Lightmap3_x2Fx =
" \n\
texture texture0; \n\
texture texture1; \n\
texture texture2; \n\
texture texture3; \n\
// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
// Other colors are the lightmap Factors for each lightmap \n\
dword color0; \n\
dword color1; \n\
dword color2; \n\
dword color3; \n\
float4 factor0; \n\
float4 factor1; \n\
float4 factor2; \n\
float4 factor3; \n\
\n\
float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
// modulate the dyn light by 0.5, because of MODULATE2X \n\
float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
\n\
\n\
// **** 4 stages technique \n\
pixelshader four_stages_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
tex t3; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mad r0.xyz, c3, t3, r0; \n\
mul_x2 r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique four_stages_4 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
TexCoordIndex[3] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
Texture[3] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShaderConstant[3] = ; \n\
PixelShader = (four_stages_ps); \n\
} \n\
} \n\
\n\
// **** 3 stages technique \n\
pixelshader three_stages_0_ps = asm \n\
{ \n\
ps_1_1; \n\
tex t0; \n\
tex t1; \n\
tex t2; \n\
// multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
mad r0.xyz, c1, t1, v0; \n\
mad r0.xyz, c2, t2, r0; \n\
mul_x2 r0.xyz, r0, t0; \n\
+mov r0.w, t0; \n\
}; \n\
\n\
technique three_stages_3 \n\
{ \n\
pass p0 \n\
{ \n\
TexCoordIndex[2] = 1; \n\
\n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient= ; \n\
MaterialDiffuse= ; \n\
MaterialSpecular= ; \n\
AlphaBlendEnable = false; \n\
\n\
Texture[0] = ; \n\
Texture[1] = ; \n\
Texture[2] = ; \n\
PixelShaderConstant[1] = ; \n\
PixelShaderConstant[2] = ; \n\
PixelShader = (three_stages_0_ps); \n\
} \n\
pass p1 \n\
{ \n\
FogColor = 0x00000000; // don't accumulate fog several times\n\
AlphaBlendEnable = true; \n\
SrcBlend = one; \n\
DestBlend = one; \n\
Lighting = false; \n\
\n\
// the DiffuseTexture texture 0 is in last stage \n\
TexCoordIndex[0] = 1; \n\
TexCoordIndex[1] = 0; \n\
Texture[0] = ; \n\
Texture[1] = ; \n\
TextureFactor = ; \n\
ColorOp[0] = MODULATE; \n\
ColorArg1[0] = TFACTOR; \n\
ColorArg2[0] = TEXTURE; \n\
ColorOp[1] = MODULATE2X; \n\
ColorArg1[1] = CURRENT; \n\
ColorArg2[1] = TEXTURE; \n\
ColorOp[2] = DISABLE; \n\
// Alpha stage 0 unused \n\
AlphaOp[0] = SELECTARG1; \n\
AlphaArg1[0] = TFACTOR; \n\
AlphaOp[1] = SELECTARG1; \n\
AlphaArg1[1] = TEXTURE; // for case when there's alpha test \n\
AlphaOp[2] = DISABLE; \n\
PixelShader = NULL; \n\
} \n\
} \n\
\n\
// **** 2 stages, no pixel shader technique \n\
technique two_stages_2 \n\
{ \n\
pass p0 \n\
{ \n\
// Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
Lighting = true; \n\
MaterialEmissive= ; \n\
MaterialAmbient=