Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / 3d / driver / direct3d / driver_direct3d_shader.cpp
blob35a59b9ba5e5d9722aacd9ab5e9e42ec15c3a60b
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stddirect3d.h"
22 #include "driver_direct3d.h"
23 #include "nel/misc/path.h"
24 #include "nel/misc/file.h"
26 #ifdef DEBUG_NEW
27 #define new DEBUG_NEW
28 #endif
30 using namespace std;
31 using namespace NLMISC;
33 namespace NL3D
37 // ***************************************************************************
39 CD3DShaderFX::~CD3DShaderFX()
41 // Must kill the drv mirror of this shader.
42 _DrvInfo.kill();
45 // ***************************************************************************
47 CD3DShaderFX::CD3DShaderFX()
49 _ShaderChanged = true;
52 // ***************************************************************************
54 void CD3DShaderFX::setText (const char *text)
56 _Text = text;
57 _ShaderChanged = true;
60 // ***************************************************************************
62 void CD3DShaderFX::setName (const char *name)
64 _Name = name;
65 _ShaderChanged = true;
68 // ***************************************************************************
70 bool CD3DShaderFX::loadShaderFile (const char *filename)
72 _Text.clear();
73 // Lookup
74 string _filename = NLMISC::CPath::lookup(filename, false, true, true);
75 if (!_filename.empty())
77 // File length
78 uint size = NLMISC::CFile::getFileSize (_filename);
79 _Text.reserve (size+1);
81 try
83 NLMISC::CIFile file;
84 if (file.open (_filename))
86 // Read it
87 while (!file.eof ())
89 char line[512];
90 file.getline (line, 512);
91 _Text += line;
94 // Set the shader name
95 _Name = NLMISC::CFile::getFilename (filename);
96 return true;
98 else
100 nlwarning ("Can't open the file %s for reading", _filename.c_str());
103 catch (const Exception &e)
105 nlwarning ("Error while reading %s : %s", _filename.c_str(), e.what());
108 return false;
111 // ***************************************************************************
113 IShaderDrvInfos::~IShaderDrvInfos()
115 _Driver->removeShaderDrvInfoPtr(_DriverIterator);
118 void CDriverD3D::removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt)
120 _ShaderDrvInfos.erase(shaderIt);
123 // mem allocator for state records
124 std::allocator<uint8> CStateRecord::Allocator;
127 // ***************************************************************************
128 // The state manager with cache
129 // ***************************************************************************
131 HRESULT CDriverD3D::QueryInterface(REFIID /* riid */, LPVOID * /* ppvObj */)
133 H_AUTO_D3D(CDriverD3D_QueryInterface)
134 return D3D_OK;
137 // ***************************************************************************
139 ULONG CDriverD3D::AddRef(VOID)
141 H_AUTO_D3D(CDriverD3D_AddRef)
142 return 0;
145 // ***************************************************************************
147 ULONG CDriverD3D::Release(VOID)
149 H_AUTO_D3D(CDriverD3D_Release)
150 return 0;
153 // ***************************************************************************
155 HRESULT CDriverD3D::LightEnable(DWORD Index, BOOL Enable)
157 H_AUTO_D3D(CDriverD3D_LightEnable)
158 enableLight ((uint8)Index, Enable!=FALSE);
159 return D3D_OK;
162 // ***************************************************************************
164 HRESULT CDriverD3D::SetFVF(DWORD /* FVF */)
166 H_AUTO_D3D(CDriverD3D_SetFVF)
167 // Not implemented
168 return D3D_OK;
171 // ***************************************************************************
173 HRESULT CDriverD3D::SetLight(DWORD Index, CONST D3DLIGHT9* pLight)
175 H_AUTO_D3D(CDriverD3D_SetLight)
176 _LightCache[Index].Light = *pLight;
177 touchRenderVariable (&_LightCache[Index]);
178 return D3D_OK;
181 // ***************************************************************************
183 HRESULT CDriverD3D::SetMaterial(CONST D3DMATERIAL9* pMaterial)
185 H_AUTO_D3D(CDriverD3D_SetMaterial)
186 setMaterialState( *pMaterial );
187 return D3D_OK;
190 // ***************************************************************************
192 HRESULT CDriverD3D::SetNPatchMode(FLOAT /* nSegments */)
194 H_AUTO_D3D(CDriverD3D_SetNPatchMode)
195 // Not implemented
196 return D3D_OK;
199 // ***************************************************************************
201 HRESULT CDriverD3D::SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader)
203 H_AUTO_D3D(CDriverD3D_SetPixelShader)
204 setPixelShader (pShader);
205 return D3D_OK;
208 // ***************************************************************************
210 HRESULT CDriverD3D::SetPixelShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount)
212 H_AUTO_D3D(CDriverD3D_SetPixelShaderConstantB)
213 uint i;
214 for (i=0; i<RegisterCount; i++)
215 setPixelShaderConstant (i+StartRegister, (int*)(pConstantData+i*4));
216 return D3D_OK;
219 // ***************************************************************************
221 HRESULT CDriverD3D::SetPixelShaderConstantF(UINT StartRegister, CONST FLOAT* pConstantData, UINT RegisterCount)
223 H_AUTO_D3D(CDriverD3D_SetPixelShaderConstantF)
224 uint i;
225 for (i=0; i<RegisterCount; i++)
226 setPixelShaderConstant (i+StartRegister, pConstantData+i*4);
227 return D3D_OK;
230 // ***************************************************************************
232 HRESULT CDriverD3D::SetPixelShaderConstantI(UINT StartRegister, CONST INT* pConstantData, UINT RegisterCount)
234 H_AUTO_D3D(CDriverD3D_SetPixelShaderConstantI)
235 uint i;
236 for (i=0; i<RegisterCount; i++)
237 setPixelShaderConstant (i+StartRegister, pConstantData+i*4);
238 return D3D_OK;
241 // ***************************************************************************
243 HRESULT CDriverD3D::SetRenderState(D3DRENDERSTATETYPE State, DWORD Value)
245 H_AUTO_D3D(CDriverD3D_SetRenderState)
246 setRenderState (State, Value);
247 return D3D_OK;
250 // ***************************************************************************
252 HRESULT CDriverD3D::SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
254 H_AUTO_D3D(CDriverD3D_SetSamplerState)
255 setSamplerState (Sampler, Type, Value);
256 return D3D_OK;
259 // ***************************************************************************
261 HRESULT CDriverD3D::SetTexture (DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture)
263 H_AUTO_D3D(CDriverD3D_SetTexture )
264 // Look for the current texture
265 uint i;
266 const uint count = (uint)_CurrentShaderTextures.size();
267 for (i=0; i<count; i++)
269 const CTextureRef &ref = _CurrentShaderTextures[i];
270 if (ref.D3DTexture == pTexture)
272 // Set the additionnal stage set by NeL texture (D3DSAMP_ADDRESSU, D3DSAMP_ADDRESSV, D3DSAMP_MAGFILTER, D3DSAMP_MINFILTER and D3DSAMP_MIPFILTER)
273 setTexture (Stage, ref.NeLTexture);
274 break;
277 if (i == count)
278 setTexture (Stage, pTexture);
280 return D3D_OK;
283 // ***************************************************************************
285 HRESULT CDriverD3D::SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
287 H_AUTO_D3D(CDriverD3D_SetTextureStageState)
288 if (Type == D3DTSS_TEXCOORDINDEX)
289 setTextureIndexUV (Stage, Value);
290 else
291 setTextureState (Stage, Type, Value);
292 return D3D_OK;
295 // ***************************************************************************
297 HRESULT CDriverD3D::SetTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix)
299 H_AUTO_D3D(CDriverD3D_SetTransform)
300 setMatrix (State, *pMatrix);
301 return D3D_OK;
304 // ***************************************************************************
306 HRESULT CDriverD3D::SetVertexShader(LPDIRECT3DVERTEXSHADER9 pShader)
308 H_AUTO_D3D(CDriverD3D_SetVertexShader)
309 setVertexProgram (pShader, NULL);
310 return D3D_OK;
313 // ***************************************************************************
315 HRESULT CDriverD3D::SetVertexShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount)
317 H_AUTO_D3D(CDriverD3D_SetVertexShaderConstantB)
318 uint i;
319 for (i=0; i<RegisterCount; i++)
320 setVertexProgramConstant (i+StartRegister, (int*)(pConstantData+i*4));
321 return D3D_OK;
324 // ***************************************************************************
326 HRESULT CDriverD3D::SetVertexShaderConstantF(UINT StartRegister, CONST FLOAT* pConstantData, UINT RegisterCount)
328 H_AUTO_D3D(CDriverD3D_SetVertexShaderConstantF)
329 uint i;
330 for (i=0; i<RegisterCount; i++)
331 setVertexProgramConstant (i+StartRegister, pConstantData+i*4);
332 return D3D_OK;
335 // ***************************************************************************
337 HRESULT CDriverD3D::SetVertexShaderConstantI(UINT StartRegister, CONST INT* pConstantData, UINT RegisterCount)
339 H_AUTO_D3D(CDriverD3D_SetVertexShaderConstantI)
340 uint i;
341 for (i=0; i<RegisterCount; i++)
342 setVertexProgramConstant (i+StartRegister, pConstantData+i*4);
343 return D3D_OK;
346 // ***************************************************************************
348 CShaderDrvInfosD3D::CShaderDrvInfosD3D(CDriverD3D *drv, ItShaderDrvInfoPtrList it) : IShaderDrvInfos(drv, it)
350 H_AUTO_D3D(CShaderDrvInfosD3D_CShaderDrvInfosD3D)
351 Validated = false;
354 // ***************************************************************************
356 CShaderDrvInfosD3D::~CShaderDrvInfosD3D()
358 H_AUTO_D3D(CShaderDrvInfosD3D_CShaderDrvInfosD3DDtor)
359 Effect->Release();
362 // ***************************************************************************
364 bool CDriverD3D::validateShader(CD3DShaderFX *shader)
366 H_AUTO_D3D(CDriverD3D_validateShader)
367 CShaderDrvInfosD3D *shaderInfo = static_cast<CShaderDrvInfosD3D*>((IShaderDrvInfos*)shader->_DrvInfo);
369 if (!shaderInfo->Validated)
371 // Choose the good method
372 D3DXHANDLE hTechnique = NULL;
373 D3DXHANDLE hCurrentTechnique = NULL;
374 while (hTechnique == NULL)
376 if (shaderInfo->Effect->FindNextValidTechnique(hCurrentTechnique, &hCurrentTechnique) != D3D_OK)
377 return false;
379 // Info
381 #ifdef NL_FORCE_TEXTURE_STAGE_COUNT
382 D3DXTECHNIQUE_DESC desc;
383 nlverify (shaderInfo->Effect->GetTechniqueDesc(hCurrentTechnique, &desc) == D3D_OK);
385 // Check this is compatible
386 const uint len = strlen(desc.Name);
387 if (len)
389 char shaderStageCount = desc.Name[len-1];
390 if ((shaderStageCount>='0') && (shaderStageCount<='9'))
392 uint stageCount = NL_FORCE_TEXTURE_STAGE_COUNT;
394 if ((uint)(shaderStageCount-'0')<=stageCount)
395 // The good technique
396 hTechnique = hCurrentTechnique;
399 #else // NL_FORCE_TEXTURE_STAGE_COUNT
400 hTechnique = hCurrentTechnique;
401 #endif // NL_FORCE_TEXTURE_STAGE_COUNT
403 #ifdef NL_DEBUG_D3D
405 D3DXTECHNIQUE_DESC desc;
406 nlverify (shaderInfo->Effect->GetTechniqueDesc(hCurrentTechnique, &desc) == D3D_OK);
407 if (hTechnique)
408 nlinfo ("Shader \"%s\" : use technique \"%s\" with %d passes.", shader->getName(), desc.Name, desc.Passes);
410 #endif // NL_DEBUG_D3D
413 // Set the technique
414 shaderInfo->Effect->SetTechnique(hTechnique);
416 // Set the state manager
417 shaderInfo->Effect->SetStateManager (this);
419 shaderInfo->Validated = true;
421 return true;
424 // ***************************************************************************
426 bool CDriverD3D::activeShader(CD3DShaderFX *shd)
428 H_AUTO_D3D(CDriverD3D_activeShader)
429 if (_DisableHardwarePixelShader)
430 return false;
432 // Clear current textures
433 _CurrentShaderTextures.clear();
435 // Shader has been changed ?
436 if (shd && shd->_ShaderChanged)
438 // Remove old shader
439 shd->_DrvInfo.kill();
441 // Already setuped ?
442 CShaderDrvInfosD3D *shaderInfo = static_cast<CShaderDrvInfosD3D*>((IShaderDrvInfos*)shd->_DrvInfo);
443 if ( !shd->_DrvInfo )
445 // insert into driver list. (so it is deleted when driver is deleted).
446 ItShaderDrvInfoPtrList it= _ShaderDrvInfos.insert(_ShaderDrvInfos.end(), (NL3D::IShaderDrvInfos*)NULL);
447 // create and set iterator, for future deletion.
448 shaderInfo = new CShaderDrvInfosD3D(this, it);
449 *it= shd->_DrvInfo = shaderInfo;
452 // Assemble the shader
453 LPD3DXBUFFER pErrorMsgs;
454 HRESULT hr = D3DXCreateEffect(_DeviceInterface, shd->getText(), (UINT)strlen(shd->getText())+1, NULL, NULL, 0, NULL, &(shaderInfo->Effect), &pErrorMsgs);
455 if (hr == D3D_OK)
457 // Get the texture handle
458 uint i;
459 for (i=0; i<CShaderDrvInfosD3D::MaxShaderTexture; i++)
461 string name = "texture" + toString (i);
462 shaderInfo->TextureHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
463 name = "color" + toString (i);
464 shaderInfo->ColorHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
465 name = "factor" + toString (i);
466 shaderInfo->FactorHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
467 name = "scalarFloat" + toString (i);
468 shaderInfo->ScalarFloatHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
471 else
473 nlwarning ("Can't create shader '%s' (0x%x):", shd->getName(), hr);
474 if (pErrorMsgs)
475 nlwarning ((const char*)pErrorMsgs->GetBufferPointer());
476 shd->_ShaderChanged = false;
477 _CurrentShader = NULL;
478 return false;
481 // Done
482 shd->_ShaderChanged = false;
485 // Set the shader
486 _CurrentShader = shd;
488 return true;
492 static void setFX(CD3DShaderFX &s, const char *name, const char *prog, CDriverD3D *drv)
494 H_AUTO_D3D(setFX)
496 s.setName(name);
497 s.setText(prog);
498 nlverify (drv->activeShader (&s));
501 #define setFx(a,b,c) { setFX(a, b, c, this); }
503 static const char *CloudFx =
504 " \n\
505 texture texture0; \n\
506 texture texture1; \n\
507 float4 factor0; \n\
509 pixelshader two_stages_ps = asm \n\
510 { \n\
511 ps_1_1; \n\
512 tex t0; \n\
513 tex t1; \n\
514 lrp r0.w, v0, t0, t1; \n\
515 mov r0.xyz, c0; \n\
516 +mul r0.w, c0, r0; \n\
517 }; \n\
519 technique two_stages_2 \n\
520 { \n\
521 pass p0 \n\
522 { \n\
523 Texture[0] = <texture0>; \n\
524 Texture[1] = <texture1>; \n\
525 PixelShaderConstant[0] = <factor0>; \n\
526 PixelShader = (two_stages_ps); \n\
527 } \n\
528 }; \n\
532 static const char *Lightmap0Fx =
533 " \n\
534 texture texture0; \n\
536 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
537 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
539 technique one_stage_1 \n\
540 { \n\
541 pass p0 \n\
542 { \n\
543 // do a standard lighting with the first light \n\
544 Lighting = true; \n\
545 MaterialEmissive= <g_black>; \n\
546 MaterialAmbient= <g_black>; \n\
547 MaterialDiffuse= <g_dyn_factor>; \n\
548 MaterialSpecular= <g_black>; \n\
549 AlphaBlendEnable = false; \n\
551 Texture[0] = <texture0>; \n\
552 ColorOp[0] = MODULATE; \n\
553 ColorArg1[0] = TEXTURE; \n\
554 ColorArg2[0] = DIFFUSE; \n\
555 AlphaOp[0] = SELECTARG1; // for alpha test \n\
556 AlphaArg1[0] = TEXTURE; \n\
557 } \n\
558 }; \n\
562 static const char *Lightmap0blendFx =
563 " \n\
564 texture texture0; \n\
566 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
567 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
569 technique one_stage_1 \n\
570 { \n\
571 pass p0 \n\
572 { \n\
573 // do a standard lighting with the first light \n\
574 Lighting = true; \n\
575 MaterialEmissive= <g_black>; \n\
576 MaterialAmbient= <g_black>; \n\
577 MaterialDiffuse= <g_dyn_factor>; \n\
578 MaterialSpecular= <g_black>; \n\
579 AlphaBlendEnable = true; \n\
580 SrcBlend = SRCALPHA; \n\
581 DestBlend = INVSRCALPHA; \n\
583 Texture[0] = <texture0>; \n\
584 ColorOp[0] = MODULATE; \n\
585 ColorArg1[0] = TEXTURE; \n\
586 ColorArg2[0] = DIFFUSE; \n\
587 AlphaOp[0] = SELECTARG1; \n\
588 AlphaArg1[0] = TEXTURE; \n\
589 } \n\
590 }; \n\
594 static const char *Lightmap0blend_x2Fx =
595 " \n\
596 texture texture0; \n\
598 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
599 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
601 technique one_stage_1 \n\
602 { \n\
603 pass p0 \n\
604 { \n\
605 // do a standard lighting with the first light \n\
606 Lighting = true; \n\
607 MaterialEmissive= <g_black>; \n\
608 MaterialAmbient= <g_black>; \n\
609 MaterialDiffuse= <g_dyn_factor>; \n\
610 MaterialSpecular= <g_black>; \n\
611 AlphaBlendEnable = true; \n\
612 SrcBlend = SRCALPHA; \n\
613 DestBlend = INVSRCALPHA; \n\
615 Texture[0] = <texture0>; \n\
616 ColorOp[0] = MODULATE; \n\
617 ColorArg1[0] = TEXTURE; \n\
618 ColorArg2[0] = DIFFUSE; \n\
619 AlphaOp[0] = SELECTARG1; \n\
620 AlphaArg1[0] = TEXTURE; \n\
621 } \n\
622 }; \n\
626 static const char *Lightmap0_x2Fx =
627 " \n\
628 texture texture0; \n\
630 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
631 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
633 technique one_stage_1 \n\
634 { \n\
635 pass p0 \n\
636 { \n\
637 // do a standard lighting with the first light \n\
638 Lighting = true; \n\
639 MaterialEmissive= <g_black>; \n\
640 MaterialAmbient= <g_black>; \n\
641 MaterialDiffuse= <g_dyn_factor>; \n\
642 MaterialSpecular= <g_black>; \n\
643 AlphaBlendEnable = false; \n\
645 Texture[0] = <texture0>; \n\
646 ColorOp[0] = MODULATE; \n\
647 ColorArg1[0] = TEXTURE; \n\
648 ColorArg2[0] = DIFFUSE; \n\
649 AlphaOp[0] = SELECTARG1; // for alpha test \n\
650 AlphaArg1[0] = TEXTURE; \n\
651 } \n\
652 }; \n\
656 static const char *Lightmap1Fx =
657 " \n\
658 texture texture0; \n\
659 texture texture1; \n\
660 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
661 // Other colors are the lightmap Factors for each lightmap \n\
662 dword color0; \n\
663 dword color1; \n\
664 float4 factor0; \n\
665 float4 factor1; \n\
667 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
668 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
670 technique two_stages_2 \n\
671 { \n\
672 pass p0 \n\
673 { \n\
674 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
675 Lighting = true; \n\
676 MaterialEmissive= <factor0>; \n\
677 MaterialAmbient= <g_black>; \n\
678 MaterialDiffuse= <g_dyn_factor>; \n\
679 MaterialSpecular= <g_black>; \n\
680 AlphaBlendEnable = false; \n\
682 // the DiffuseTexture texture 0 is in last stage \n\
683 TexCoordIndex[0] = 1; \n\
684 TexCoordIndex[1] = 0; \n\
685 Texture[0] = <texture1>; \n\
686 Texture[1] = <texture0>; \n\
687 TextureFactor = <color1>; \n\
688 ColorOp[0] = MULTIPLYADD; \n\
689 ColorArg0[0] = DIFFUSE; \n\
690 ColorArg1[0] = TFACTOR; \n\
691 ColorArg2[0] = TEXTURE; \n\
692 ColorOp[1] = MODULATE; \n\
693 ColorArg1[1] = CURRENT; \n\
694 ColorArg2[1] = TEXTURE; \n\
695 AlphaOp[0] = SELECTARG1; \n\
696 AlphaArg1[0] = TFACTOR; \n\
697 AlphaOp[1] = SELECTARG1; // for alpha test \n\
698 AlphaArg1[1] = TEXTURE; \n\
699 } \n\
700 }; \n\
704 static const char *Lightmap1blendFx =
705 " \n\
706 texture texture0; \n\
707 texture texture1; \n\
708 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
709 // Other colors are the lightmap Factors for each lightmap \n\
710 dword color0; \n\
711 dword color1; \n\
712 float4 factor0; \n\
713 float4 factor1; \n\
715 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
716 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
718 technique two_stages_2 \n\
719 { \n\
720 pass p0 \n\
721 { \n\
722 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
723 Lighting = true; \n\
724 MaterialEmissive= <factor0>; \n\
725 MaterialAmbient= <g_black>; \n\
726 MaterialDiffuse= <g_dyn_factor>; \n\
727 MaterialSpecular= <g_black>; \n\
728 AlphaBlendEnable = true; \n\
729 SrcBlend = SRCALPHA; \n\
730 DestBlend = INVSRCALPHA; \n\
732 // the DiffuseTexture texture 0 is in last stage \n\
733 TexCoordIndex[0] = 1; \n\
734 TexCoordIndex[1] = 0; \n\
735 Texture[0] = <texture1>; \n\
736 Texture[1] = <texture0>; \n\
737 TextureFactor = <color1>; \n\
738 ColorOp[0] = MULTIPLYADD; \n\
739 ColorArg0[0] = DIFFUSE; \n\
740 ColorArg1[0] = TFACTOR; \n\
741 ColorArg2[0] = TEXTURE; \n\
742 ColorOp[1] = MODULATE; \n\
743 ColorArg1[1] = CURRENT; \n\
744 ColorArg2[1] = TEXTURE; \n\
745 // Alpha stage 0 unused \n\
746 AlphaOp[0] = SELECTARG1; \n\
747 AlphaArg1[0] = TFACTOR; \n\
748 AlphaOp[1] = SELECTARG1; \n\
749 AlphaArg1[1] = TEXTURE; \n\
750 } \n\
751 }; \n\
755 static const char *Lightmap1blend_x2Fx =
756 " \n\
757 texture texture0; \n\
758 texture texture1; \n\
759 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
760 // Other colors are the lightmap Factors for each lightmap \n\
761 dword color0; \n\
762 dword color1; \n\
763 float4 factor0; \n\
764 float4 factor1; \n\
766 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
767 // modulate the dyn light by 0.5, because of MODULATE2X \n\
768 float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
770 technique two_stages_2 \n\
771 { \n\
772 pass p0 \n\
773 { \n\
774 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
775 Lighting = true; \n\
776 MaterialEmissive= <factor0>; \n\
777 MaterialAmbient= <g_black>; \n\
778 MaterialDiffuse= <g_dyn_factor>; \n\
779 MaterialSpecular= <g_black>; \n\
780 AlphaBlendEnable = true; \n\
781 SrcBlend = SRCALPHA; \n\
782 DestBlend = INVSRCALPHA; \n\
784 // the DiffuseTexture texture 0 is in last stage \n\
785 TexCoordIndex[0] = 1; \n\
786 TexCoordIndex[1] = 0; \n\
787 Texture[0] = <texture1>; \n\
788 Texture[1] = <texture0>; \n\
789 TextureFactor = <color1>; \n\
790 ColorOp[0] = MULTIPLYADD; \n\
791 ColorArg0[0] = DIFFUSE; \n\
792 ColorArg1[0] = TFACTOR; \n\
793 ColorArg2[0] = TEXTURE; \n\
794 ColorOp[1] = MODULATE2X; \n\
795 ColorArg1[1] = CURRENT; \n\
796 ColorArg2[1] = TEXTURE; \n\
797 // Alpha stage 0 unused \n\
798 AlphaOp[0] = SELECTARG1; \n\
799 AlphaArg1[0] = TFACTOR; \n\
800 AlphaOp[1] = SELECTARG1; \n\
801 AlphaArg1[1] = TEXTURE; \n\
802 } \n\
803 }; \n\
807 static const char *Lightmap1_x2Fx =
808 " \n\
809 texture texture0; \n\
810 texture texture1; \n\
811 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
812 // Other colors are the lightmap Factors for each lightmap \n\
813 dword color0; \n\
814 dword color1; \n\
815 float4 factor0; \n\
816 float4 factor1; \n\
818 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
819 // modulate the dyn light by 0.5, because of MODULATE2X \n\
820 float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
822 technique two_stages_2 \n\
823 { \n\
824 pass p0 \n\
825 { \n\
826 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
827 Lighting = true; \n\
828 MaterialEmissive= <factor0>; \n\
829 MaterialAmbient= <g_black>; \n\
830 MaterialDiffuse= <g_dyn_factor>; \n\
831 MaterialSpecular= <g_black>; \n\
832 AlphaBlendEnable = false; \n\
834 // the DiffuseTexture texture 0 is in last stage \n\
835 TexCoordIndex[0] = 1; \n\
836 TexCoordIndex[1] = 0; \n\
837 Texture[0] = <texture1>; \n\
838 Texture[1] = <texture0>; \n\
839 TextureFactor = <color1>; \n\
840 ColorOp[0] = MULTIPLYADD; \n\
841 ColorArg0[0] = DIFFUSE; \n\
842 ColorArg1[0] = TFACTOR; \n\
843 ColorArg2[0] = TEXTURE; \n\
844 ColorOp[1] = MODULATE2X; \n\
845 ColorArg1[1] = CURRENT; \n\
846 ColorArg2[1] = TEXTURE; \n\
847 AlphaOp[0] = SELECTARG1; \n\
848 AlphaArg1[0] = TFACTOR; \n\
849 AlphaOp[1] = SELECTARG1; // for alpha test \n\
850 AlphaArg1[1] = TEXTURE; \n\
851 } \n\
852 }; \n\
856 static const char *Lightmap2Fx =
857 " \n\
858 texture texture0; \n\
859 texture texture1; \n\
860 texture texture2; \n\
861 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
862 // Other colors are the lightmap Factors for each lightmap \n\
863 dword color0; \n\
864 dword color1; \n\
865 dword color2; \n\
866 float4 factor0; \n\
867 float4 factor1; \n\
868 float4 factor2; \n\
870 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
871 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
874 // **** 3 stages technique \n\
875 pixelshader three_stages_ps = asm \n\
876 { \n\
877 ps_1_1; \n\
878 tex t0; \n\
879 tex t1; \n\
880 tex t2; \n\
881 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
882 mad r0.xyz, c1, t1, v0; \n\
883 mad r0.xyz, c2, t2, r0; \n\
884 mul r0.xyz, r0, t0; \n\
885 +mov r0.w, t0; \n\
886 }; \n\
888 technique three_stages_3 \n\
889 { \n\
890 pass p0 \n\
891 { \n\
892 TexCoordIndex[2] = 1; \n\
894 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
895 Lighting = true; \n\
896 MaterialEmissive= <factor0>; \n\
897 MaterialAmbient= <g_black>; \n\
898 MaterialDiffuse= <g_dyn_factor>; \n\
899 MaterialSpecular= <g_black>; \n\
900 AlphaBlendEnable = false; \n\
902 Texture[0] = <texture0>; \n\
903 Texture[1] = <texture1>; \n\
904 Texture[2] = <texture2>; \n\
905 PixelShaderConstant[1] = <factor1>; \n\
906 PixelShaderConstant[2] = <factor2>; \n\
907 PixelShader = (three_stages_ps); \n\
908 } \n\
909 } \n\
911 // **** 2 stages, no pixel shader technique \n\
912 technique two_stages_2 \n\
913 { \n\
914 pass p0 \n\
915 { \n\
916 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
917 Lighting = true; \n\
918 MaterialEmissive= <factor0>; \n\
919 MaterialAmbient= <g_black>; \n\
920 MaterialDiffuse= <g_dyn_factor>; \n\
921 MaterialSpecular= <g_black>; \n\
922 AlphaBlendEnable = false; \n\
924 // the DiffuseTexture texture 0 is in last stage \n\
925 TexCoordIndex[0] = 1; \n\
926 TexCoordIndex[1] = 0; \n\
927 Texture[0] = <texture1>; \n\
928 Texture[1] = <texture0>; \n\
929 TextureFactor = <color1>; \n\
930 ColorOp[0] = MULTIPLYADD; \n\
931 ColorArg0[0] = DIFFUSE; \n\
932 ColorArg1[0] = TFACTOR; \n\
933 ColorArg2[0] = TEXTURE; \n\
934 ColorOp[1] = MODULATE; \n\
935 ColorArg1[1] = CURRENT; \n\
936 ColorArg2[1] = TEXTURE; \n\
937 // Alpha stage 0 unused \n\
938 AlphaOp[0] = SELECTARG1; \n\
939 AlphaArg1[0] = TFACTOR; \n\
940 AlphaOp[1] = SELECTARG1; // for alpha test \n\
941 AlphaArg1[1] = TEXTURE; \n\
942 } \n\
943 pass p1 \n\
944 { \n\
945 FogColor = 0x00000000; // don't accumulate fog several times\n\
946 Lighting = false; \n\
947 AlphaBlendEnable = true; \n\
948 SrcBlend = one; \n\
949 DestBlend = one; \n\
950 Texture[0] = <texture2>; \n\
951 TextureFactor = <color2>; \n\
952 ColorOp[0] = MODULATE; \n\
953 } \n\
954 } \n\
958 static const char *Lightmap2blendFx =
959 " \n\
960 texture texture0; \n\
961 texture texture1; \n\
962 texture texture2; \n\
963 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
964 // Other colors are the lightmap Factors for each lightmap \n\
965 dword color0; \n\
966 dword color1; \n\
967 dword color2; \n\
968 float4 factor0; \n\
969 float4 factor1; \n\
970 float4 factor2; \n\
972 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
973 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
976 // **** 3 stages technique \n\
977 pixelshader three_stages_ps = asm \n\
978 { \n\
979 ps_1_1; \n\
980 tex t0; \n\
981 tex t1; \n\
982 tex t2; \n\
983 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
984 mad r0.xyz, c1, t1, v0; \n\
985 mad r0.xyz, c2, t2, r0; \n\
986 mul r0.xyz, r0, t0; \n\
987 +mov r0.w, t0; \n\
988 }; \n\
990 technique three_stages_3 \n\
991 { \n\
992 pass p0 \n\
993 { \n\
994 TexCoordIndex[2] = 1; \n\
996 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
997 Lighting = true; \n\
998 MaterialEmissive= <factor0>; \n\
999 MaterialAmbient= <g_black>; \n\
1000 MaterialDiffuse= <g_dyn_factor>; \n\
1001 MaterialSpecular= <g_black>; \n\
1002 AlphaBlendEnable = true; \n\
1003 SrcBlend = srcalpha; \n\
1004 DestBlend = invsrcalpha; \n\
1006 Texture[0] = <texture0>; \n\
1007 Texture[1] = <texture1>; \n\
1008 Texture[2] = <texture2>; \n\
1009 PixelShaderConstant[1] = <factor1>; \n\
1010 PixelShaderConstant[2] = <factor2>; \n\
1011 PixelShader = (three_stages_ps); \n\
1012 } \n\
1013 } \n\
1015 // **** 2 stages, no pixel shader technique \n\
1016 technique two_stages_2 \n\
1017 { \n\
1018 pass p0 \n\
1019 { \n\
1020 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1021 Lighting = true; \n\
1022 MaterialEmissive= <factor0>; \n\
1023 MaterialAmbient= <g_black>; \n\
1024 MaterialDiffuse= <g_dyn_factor>; \n\
1025 MaterialSpecular= <g_black>; \n\
1026 AlphaBlendEnable = true; \n\
1027 SrcBlend = srcalpha; \n\
1028 DestBlend = invsrcalpha; \n\
1030 // the DiffuseTexture texture 0 is in last stage \n\
1031 TexCoordIndex[0] = 1; \n\
1032 TexCoordIndex[1] = 0; \n\
1033 Texture[0] = <texture1>; \n\
1034 Texture[1] = <texture0>; \n\
1035 TextureFactor = <color1>; \n\
1036 ColorOp[0] = MULTIPLYADD; \n\
1037 ColorArg0[0] = DIFFUSE; \n\
1038 ColorArg1[0] = TFACTOR; \n\
1039 ColorArg2[0] = TEXTURE; \n\
1040 ColorOp[1] = MODULATE; \n\
1041 ColorArg1[1] = CURRENT; \n\
1042 ColorArg2[1] = TEXTURE; \n\
1043 // Alpha stage 0 unused \n\
1044 AlphaOp[0] = SELECTARG1; \n\
1045 AlphaArg1[0] = TFACTOR; \n\
1046 AlphaOp[1] = SELECTARG1; \n\
1047 AlphaArg1[1] = TEXTURE; \n\
1048 } \n\
1049 pass p1 \n\
1050 { \n\
1051 FogColor = 0x00000000; // don't accumulate fog several times\n\
1052 Lighting = false; \n\
1053 DestBlend = one; \n\
1054 Texture[0] = <texture2>; \n\
1055 TextureFactor = <color2>; \n\
1056 ColorOp[0] = MODULATE; \n\
1057 } \n\
1058 } \n\
1063 static const char *Lightmap2blend_x2Fx =
1064 " \n\
1065 texture texture0; \n\
1066 texture texture1; \n\
1067 texture texture2; \n\
1068 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
1069 // Other colors are the lightmap Factors for each lightmap \n\
1070 dword color0; \n\
1071 dword color1; \n\
1072 dword color2; \n\
1073 float4 factor0; \n\
1074 float4 factor1; \n\
1075 float4 factor2; \n\
1077 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
1078 // modulate the dyn light by 0.5, because of MODULATE2X \n\
1079 float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
1082 // **** 3 stages technique \n\
1083 pixelshader three_stages_ps = asm \n\
1084 { \n\
1085 ps_1_1; \n\
1086 tex t0; \n\
1087 tex t1; \n\
1088 tex t2; \n\
1089 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1090 mad r0.xyz, c1, t1, v0; \n\
1091 mad r0.xyz, c2, t2, r0; \n\
1092 mul_x2 r0.xyz, r0, t0; \n\
1093 mov r0.w, t0; \n\
1094 }; \n\
1096 technique three_stages_3 \n\
1097 { \n\
1098 pass p0 \n\
1099 { \n\
1100 TexCoordIndex[2] = 1; \n\
1102 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1103 Lighting = true; \n\
1104 MaterialEmissive= <factor0>; \n\
1105 MaterialAmbient= <g_black>; \n\
1106 MaterialDiffuse= <g_dyn_factor>; \n\
1107 MaterialSpecular= <g_black>; \n\
1108 AlphaBlendEnable = true; \n\
1109 SrcBlend = srcalpha; \n\
1110 DestBlend = invsrcalpha; \n\
1112 Texture[0] = <texture0>; \n\
1113 Texture[1] = <texture1>; \n\
1114 Texture[2] = <texture2>; \n\
1115 PixelShaderConstant[1] = <factor1>; \n\
1116 PixelShaderConstant[2] = <factor2>; \n\
1117 PixelShader = (three_stages_ps); \n\
1118 } \n\
1119 } \n\
1121 // **** 2 stages, no pixel shader technique \n\
1122 technique two_stages_2 \n\
1123 { \n\
1124 pass p0 \n\
1125 { \n\
1126 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1127 Lighting = true; \n\
1128 MaterialEmissive= <factor0>; \n\
1129 MaterialAmbient= <g_black>; \n\
1130 MaterialDiffuse= <g_dyn_factor>; \n\
1131 MaterialSpecular= <g_black>; \n\
1132 AlphaBlendEnable = true; \n\
1133 SrcBlend = srcalpha; \n\
1134 DestBlend = invsrcalpha; \n\
1136 // the DiffuseTexture texture 0 is in last stage \n\
1137 TexCoordIndex[0] = 1; \n\
1138 TexCoordIndex[1] = 0; \n\
1139 Texture[0] = <texture1>; \n\
1140 Texture[1] = <texture0>; \n\
1141 TextureFactor = <color1>; \n\
1142 ColorOp[0] = MULTIPLYADD; \n\
1143 ColorArg0[0] = DIFFUSE; \n\
1144 ColorArg1[0] = TFACTOR; \n\
1145 ColorArg2[0] = TEXTURE; \n\
1146 ColorOp[1] = MODULATE2X; \n\
1147 ColorArg1[1] = CURRENT; \n\
1148 ColorArg2[1] = TEXTURE; \n\
1149 // Alpha stage 0 unused \n\
1150 AlphaOp[0] = SELECTARG1; \n\
1151 AlphaArg1[0] = TFACTOR; \n\
1152 AlphaOp[1] = SELECTARG1; \n\
1153 AlphaArg1[1] = TEXTURE; \n\
1154 } \n\
1155 pass p1 \n\
1156 { \n\
1157 FogColor = 0x00000000; // don't accumulate fog several times\n\
1158 Lighting = false; \n\
1159 DestBlend = one; \n\
1160 Texture[0] = <texture2>; \n\
1161 TextureFactor = <color2>; \n\
1162 ColorOp[0] = MODULATE; \n\
1163 } \n\
1164 } \n\
1169 static const char *Lightmap2_x2Fx =
1170 " \n\
1171 texture texture0; \n\
1172 texture texture1; \n\
1173 texture texture2; \n\
1174 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
1175 // Other colors are the lightmap Factors for each lightmap \n\
1176 dword color0; \n\
1177 dword color1; \n\
1178 dword color2; \n\
1179 float4 factor0; \n\
1180 float4 factor1; \n\
1181 float4 factor2; \n\
1183 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
1184 // modulate the dyn light by 0.5, because of MODULATE2X \n\
1185 float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
1188 // **** 3 stages technique \n\
1189 pixelshader three_stages_ps = asm \n\
1190 { \n\
1191 ps_1_1; \n\
1192 tex t0; \n\
1193 tex t1; \n\
1194 tex t2; \n\
1195 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1196 mad r0.xyz, c1, t1, v0; \n\
1197 mad r0.xyz, c2, t2, r0; \n\
1198 mul_x2 r0.xyz, r0, t0; \n\
1199 +mov r0.w, t0; \n\
1200 }; \n\
1202 technique three_stages_3 \n\
1203 { \n\
1204 pass p0 \n\
1205 { \n\
1206 TexCoordIndex[2] = 1; \n\
1208 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1209 Lighting = true; \n\
1210 MaterialEmissive= <factor0>; \n\
1211 MaterialAmbient= <g_black>; \n\
1212 MaterialDiffuse= <g_dyn_factor>; \n\
1213 MaterialSpecular= <g_black>; \n\
1214 AlphaBlendEnable = false; \n\
1216 Texture[0] = <texture0>; \n\
1217 Texture[1] = <texture1>; \n\
1218 Texture[2] = <texture2>; \n\
1219 PixelShaderConstant[1] = <factor1>; \n\
1220 PixelShaderConstant[2] = <factor2>; \n\
1221 PixelShader = (three_stages_ps); \n\
1222 } \n\
1223 } \n\
1225 // **** 2 stages, no pixel shader technique \n\
1226 technique two_stages_2 \n\
1227 { \n\
1228 pass p0 \n\
1229 { \n\
1230 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1231 Lighting = true; \n\
1232 MaterialEmissive= <factor0>; \n\
1233 MaterialAmbient= <g_black>; \n\
1234 MaterialDiffuse= <g_dyn_factor>; \n\
1235 MaterialSpecular= <g_black>; \n\
1236 AlphaBlendEnable = false; \n\
1238 // the DiffuseTexture texture 0 is in last stage \n\
1239 TexCoordIndex[0] = 1; \n\
1240 TexCoordIndex[1] = 0; \n\
1241 Texture[0] = <texture1>; \n\
1242 Texture[1] = <texture0>; \n\
1243 TextureFactor = <color1>; \n\
1244 ColorOp[0] = MULTIPLYADD; \n\
1245 ColorArg0[0] = DIFFUSE; \n\
1246 ColorArg1[0] = TFACTOR; \n\
1247 ColorArg2[0] = TEXTURE; \n\
1248 ColorOp[1] = MODULATE2X; \n\
1249 ColorArg1[1] = CURRENT; \n\
1250 ColorArg2[1] = TEXTURE; \n\
1251 // Alpha stage 0 unused \n\
1252 AlphaOp[0] = SELECTARG1; \n\
1253 AlphaArg1[0] = TFACTOR; \n\
1254 AlphaOp[1] = SELECTARG1; // for alpha test if enabled \n\
1255 AlphaArg1[1] = TEXTURE; \n\
1256 } \n\
1257 pass p1 \n\
1258 { \n\
1259 FogColor = 0x00000000; // don't accumulate fog several times\n\
1260 Lighting = false; \n\
1261 AlphaBlendEnable = true; \n\
1262 SrcBlend = one; \n\
1263 DestBlend = one; \n\
1264 Texture[0] = <texture2>; \n\
1265 TextureFactor = <color2>; \n\
1266 ColorOp[0] = MODULATE; \n\
1267 } \n\
1268 } \n\
1272 static const char *Lightmap3Fx =
1273 " \n\
1274 texture texture0; \n\
1275 texture texture1; \n\
1276 texture texture2; \n\
1277 texture texture3; \n\
1278 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
1279 // Other colors are the lightmap Factors for each lightmap \n\
1280 dword color0; \n\
1281 dword color1; \n\
1282 dword color2; \n\
1283 dword color3; \n\
1284 float4 factor0; \n\
1285 float4 factor1; \n\
1286 float4 factor2; \n\
1287 float4 factor3; \n\
1289 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
1290 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
1293 // **** 4 stages technique \n\
1294 pixelshader four_stages_ps = asm \n\
1295 { \n\
1296 ps_1_1; \n\
1297 tex t0; \n\
1298 tex t1; \n\
1299 tex t2; \n\
1300 tex t3; \n\
1301 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1302 mad r0.xyz, c1, t1, v0; \n\
1303 mad r0.xyz, c2, t2, r0; \n\
1304 mad r0.xyz, c3, t3, r0; \n\
1305 mul r0.xyz, r0, t0; \n\
1306 +mov r0.w, t0; \n\
1307 }; \n\
1309 technique four_stages_4 \n\
1310 { \n\
1311 pass p0 \n\
1312 { \n\
1313 TexCoordIndex[2] = 1; \n\
1314 TexCoordIndex[3] = 1; \n\
1316 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1317 Lighting = true; \n\
1318 MaterialEmissive= <factor0>; \n\
1319 MaterialAmbient= <g_black>; \n\
1320 MaterialDiffuse= <g_dyn_factor>; \n\
1321 MaterialSpecular= <g_black>; \n\
1322 AlphaBlendEnable = false; \n\
1324 Texture[0] = <texture0>; \n\
1325 Texture[1] = <texture1>; \n\
1326 Texture[2] = <texture2>; \n\
1327 Texture[3] = <texture3>; \n\
1328 PixelShaderConstant[1] = <factor1>; \n\
1329 PixelShaderConstant[2] = <factor2>; \n\
1330 PixelShaderConstant[3] = <factor3>; \n\
1331 PixelShader = (four_stages_ps); \n\
1332 } \n\
1333 } \n\
1335 // **** 3 stages technique \n\
1336 pixelshader three_stages_0_ps = asm \n\
1337 { \n\
1338 ps_1_1; \n\
1339 tex t0; \n\
1340 tex t1; \n\
1341 tex t2; \n\
1342 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1343 mad r0.xyz, c1, t1, v0; \n\
1344 mad r0.xyz, c2, t2, r0; \n\
1345 mul r0.xyz, r0, t0; \n\
1346 +mov r0.w, t0; \n\
1347 }; \n\
1349 technique three_stages_3 \n\
1350 { \n\
1351 pass p0 \n\
1352 { \n\
1353 TexCoordIndex[2] = 1; \n\
1355 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1356 Lighting = true; \n\
1357 MaterialEmissive= <factor0>; \n\
1358 MaterialAmbient= <g_black>; \n\
1359 MaterialDiffuse= <g_dyn_factor>; \n\
1360 MaterialSpecular= <g_black>; \n\
1361 AlphaBlendEnable = false; \n\
1363 Texture[0] = <texture0>; \n\
1364 Texture[1] = <texture1>; \n\
1365 Texture[2] = <texture2>; \n\
1366 PixelShaderConstant[1] = <factor1>; \n\
1367 PixelShaderConstant[2] = <factor2>; \n\
1368 PixelShader = (three_stages_0_ps); \n\
1369 } \n\
1370 pass p1 \n\
1371 { \n\
1372 FogColor = 0x00000000; // don't accumulate fog several times\n\
1373 AlphaBlendEnable = true; \n\
1374 SrcBlend = one; \n\
1375 DestBlend = one; \n\
1376 Lighting = false; \n\
1378 // the DiffuseTexture texture 0 is in last stage \n\
1379 TexCoordIndex[0] = 1; \n\
1380 TexCoordIndex[1] = 0; \n\
1381 Texture[0] = <texture3>; \n\
1382 Texture[1] = <texture0>; \n\
1383 TextureFactor = <color3>; \n\
1384 ColorOp[0] = MODULATE; \n\
1385 ColorArg1[0] = TFACTOR; \n\
1386 ColorArg2[0] = TEXTURE; \n\
1387 ColorOp[1] = MODULATE; \n\
1388 ColorArg1[1] = CURRENT; \n\
1389 ColorArg2[1] = TEXTURE; \n\
1390 ColorOp[2] = DISABLE; \n\
1391 // Alpha stage 0 unused \n\
1392 AlphaOp[0] = SELECTARG1; \n\
1393 AlphaArg1[0] = TFACTOR; \n\
1394 AlphaOp[1] = SELECTARG1; \n\
1395 AlphaArg1[1] = TEXTURE; // for case when there's alpha test \n\
1396 AlphaOp[2] = DISABLE; \n\
1397 PixelShader = NULL; \n\
1398 } \n\
1399 } \n\
1401 // **** 2 stages, no pixel shader technique \n\
1402 technique two_stages_2 \n\
1403 { \n\
1404 pass p0 \n\
1405 { \n\
1406 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1407 Lighting = true; \n\
1408 MaterialEmissive= <factor0>; \n\
1409 MaterialAmbient= <g_black>; \n\
1410 MaterialDiffuse= <g_dyn_factor>; \n\
1411 MaterialSpecular= <g_black>; \n\
1412 AlphaBlendEnable = false; \n\
1414 // the DiffuseTexture texture 0 is in last stage \n\
1415 TexCoordIndex[0] = 1; \n\
1416 TexCoordIndex[1] = 0; \n\
1417 Texture[0] = <texture1>; \n\
1418 Texture[1] = <texture0>; \n\
1419 TextureFactor = <color1>; \n\
1420 ColorOp[0] = MULTIPLYADD; \n\
1421 ColorArg0[0] = DIFFUSE; \n\
1422 ColorArg1[0] = TFACTOR; \n\
1423 ColorArg2[0] = TEXTURE; \n\
1424 ColorOp[1] = MODULATE; \n\
1425 ColorArg1[1] = CURRENT; \n\
1426 ColorArg2[1] = TEXTURE; \n\
1427 // Alpha stage 0 unused \n\
1428 AlphaOp[0] = SELECTARG1; \n\
1429 AlphaArg1[0] = TFACTOR; \n\
1430 AlphaOp[1] = SELECTARG1; // alpha in case were alpha test is used\n\
1431 AlphaArg1[1] = TEXTURE; \n\
1432 } \n\
1433 pass p1 \n\
1434 { \n\
1435 FogColor = 0x00000000; // don't accumulate fog several times\n\
1436 Lighting = false; \n\
1437 AlphaBlendEnable = true; \n\
1438 SrcBlend = one; \n\
1439 DestBlend = one; \n\
1440 Texture[0] = <texture2>; \n\
1441 TextureFactor = <color2>; \n\
1442 ColorOp[0] = MODULATE; \n\
1443 } \n\
1444 pass p2 \n\
1445 { \n\
1446 Texture[0] = <texture3>; \n\
1447 TextureFactor = <color3>; \n\
1448 } \n\
1449 } \n\
1455 static const char *Lightmap3blendFx =
1456 " \n\
1457 texture texture0; \n\
1458 texture texture1; \n\
1459 texture texture2; \n\
1460 texture texture3; \n\
1461 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
1462 // Other colors are the lightmap Factors for each lightmap \n\
1463 dword color0; \n\
1464 dword color1; \n\
1465 dword color2; \n\
1466 dword color3; \n\
1467 float4 factor0; \n\
1468 float4 factor1; \n\
1469 float4 factor2; \n\
1470 float4 factor3; \n\
1472 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
1473 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
1476 // **** 4 stages technique \n\
1477 pixelshader four_stages_ps = asm \n\
1478 { \n\
1479 ps_1_1; \n\
1480 tex t0; \n\
1481 tex t1; \n\
1482 tex t2; \n\
1483 tex t3; \n\
1484 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1485 mad r0.xyz, c1, t1, v0; \n\
1486 mad r0.xyz, c2, t2, r0; \n\
1487 mad r0.xyz, c3, t3, r0; \n\
1488 mul r0.xyz, r0, t0; \n\
1489 +mov r0.w, t0; \n\
1490 }; \n\
1492 technique four_stages_4 \n\
1493 { \n\
1494 pass p0 \n\
1495 { \n\
1496 TexCoordIndex[2] = 1; \n\
1497 TexCoordIndex[3] = 1; \n\
1499 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1500 Lighting = true; \n\
1501 MaterialEmissive= <factor0>; \n\
1502 MaterialAmbient= <g_black>; \n\
1503 MaterialDiffuse= <g_dyn_factor>; \n\
1504 MaterialSpecular= <g_black>; \n\
1505 AlphaBlendEnable = true; \n\
1506 SrcBlend = srcalpha; \n\
1507 DestBlend = invsrcalpha; \n\
1509 Texture[0] = <texture0>; \n\
1510 Texture[1] = <texture1>; \n\
1511 Texture[2] = <texture2>; \n\
1512 Texture[3] = <texture3>; \n\
1513 PixelShaderConstant[1] = <factor1>; \n\
1514 PixelShaderConstant[2] = <factor2>; \n\
1515 PixelShaderConstant[3] = <factor3>; \n\
1516 PixelShader = (four_stages_ps); \n\
1517 } \n\
1518 } \n\
1520 // **** 3 stages technique \n\
1521 pixelshader three_stages_0_ps = asm \n\
1522 { \n\
1523 ps_1_1; \n\
1524 tex t0; \n\
1525 tex t1; \n\
1526 tex t2; \n\
1527 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1528 mad r0.xyz, c1, t1, v0; \n\
1529 mad r0.xyz, c2, t2, r0; \n\
1530 mul r0.xyz, r0, t0; \n\
1531 +mov r0.w, t0; \n\
1532 }; \n\
1534 technique three_stages_3 \n\
1535 { \n\
1536 pass p0 \n\
1537 { \n\
1538 TexCoordIndex[2] = 1; \n\
1540 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1541 Lighting = true; \n\
1542 MaterialEmissive= <factor0>; \n\
1543 MaterialAmbient= <g_black>; \n\
1544 MaterialDiffuse= <g_dyn_factor>; \n\
1545 MaterialSpecular= <g_black>; \n\
1546 AlphaBlendEnable = true; \n\
1547 SrcBlend = srcalpha; \n\
1548 DestBlend = invsrcalpha; \n\
1550 Texture[0] = <texture0>; \n\
1551 Texture[1] = <texture1>; \n\
1552 Texture[2] = <texture2>; \n\
1553 PixelShaderConstant[1] = <factor1>; \n\
1554 PixelShaderConstant[2] = <factor2>; \n\
1555 PixelShader = (three_stages_0_ps); \n\
1556 } \n\
1557 pass p1 \n\
1558 { \n\
1559 FogColor = 0x00000000; // don't accumulate fog several times\n\
1560 DestBlend = one; \n\
1561 Lighting = false; \n\
1563 // the DiffuseTexture texture 0 is in last stage \n\
1564 TexCoordIndex[0] = 1; \n\
1565 TexCoordIndex[1] = 0; \n\
1566 Texture[0] = <texture3>; \n\
1567 Texture[1] = <texture0>; \n\
1568 TextureFactor = <color3>; \n\
1569 ColorOp[0] = MODULATE; \n\
1570 ColorArg1[0] = TFACTOR; \n\
1571 ColorArg2[0] = TEXTURE; \n\
1572 ColorOp[1] = MODULATE; \n\
1573 ColorArg1[1] = CURRENT; \n\
1574 ColorArg2[1] = TEXTURE; \n\
1575 ColorOp[2] = DISABLE; \n\
1576 // Alpha stage 0 unused \n\
1577 AlphaOp[0] = SELECTARG1; \n\
1578 AlphaArg1[0] = TFACTOR; \n\
1579 AlphaOp[1] = SELECTARG1; \n\
1580 AlphaArg1[1] = TEXTURE; \n\
1581 AlphaOp[2] = DISABLE; \n\
1582 PixelShader = NULL; \n\
1583 } \n\
1584 } \n\
1586 // **** 2 stages, no pixel shader technique \n\
1587 technique two_stages_2 \n\
1588 { \n\
1589 pass p0 \n\
1590 { \n\
1591 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1592 Lighting = true; \n\
1593 MaterialEmissive= <factor0>; \n\
1594 MaterialAmbient= <g_black>; \n\
1595 MaterialDiffuse= <g_dyn_factor>; \n\
1596 MaterialSpecular= <g_black>; \n\
1597 AlphaBlendEnable = true; \n\
1598 SrcBlend = srcalpha; \n\
1599 DestBlend = invsrcalpha; \n\
1601 // the DiffuseTexture texture 0 is in last stage \n\
1602 TexCoordIndex[0] = 1; \n\
1603 TexCoordIndex[1] = 0; \n\
1604 Texture[0] = <texture1>; \n\
1605 Texture[1] = <texture0>; \n\
1606 TextureFactor = <color1>; \n\
1607 ColorOp[0] = MULTIPLYADD; \n\
1608 ColorArg0[0] = DIFFUSE; \n\
1609 ColorArg1[0] = TFACTOR; \n\
1610 ColorArg2[0] = TEXTURE; \n\
1611 ColorOp[1] = MODULATE; \n\
1612 ColorArg1[1] = CURRENT; \n\
1613 ColorArg2[1] = TEXTURE; \n\
1614 // Alpha stage 0 unused \n\
1615 AlphaOp[0] = SELECTARG1; \n\
1616 AlphaArg1[0] = TFACTOR; \n\
1617 AlphaOp[1] = SELECTARG1; \n\
1618 AlphaArg1[1] = TEXTURE; \n\
1619 } \n\
1620 pass p1 \n\
1621 { \n\
1622 FogColor = 0x00000000; // don't accumulate fog several times\n\
1623 Lighting = false; \n\
1624 DestBlend = one; \n\
1625 Texture[0] = <texture2>; \n\
1626 TextureFactor = <color2>; \n\
1627 ColorOp[0] = MODULATE; \n\
1628 } \n\
1629 pass p2 \n\
1630 { \n\
1631 Texture[0] = <texture3>; \n\
1632 TextureFactor = <color3>; \n\
1633 } \n\
1634 } \n\
1638 static const char *Lightmap3blend_x2Fx =
1639 " \n\
1640 texture texture0; \n\
1641 texture texture1; \n\
1642 texture texture2; \n\
1643 texture texture3; \n\
1644 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
1645 // Other colors are the lightmap Factors for each lightmap \n\
1646 dword color0; \n\
1647 dword color1; \n\
1648 dword color2; \n\
1649 dword color3; \n\
1650 float4 factor0; \n\
1651 float4 factor1; \n\
1652 float4 factor2; \n\
1653 float4 factor3; \n\
1655 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
1656 // modulate the dyn light by 0.5, because of MODULATE2X \n\
1657 float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
1660 // **** 4 stages technique \n\
1661 pixelshader four_stages_ps = asm \n\
1662 { \n\
1663 ps_1_1; \n\
1664 tex t0; \n\
1665 tex t1; \n\
1666 tex t2; \n\
1667 tex t3; \n\
1668 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1669 mad r0.xyz, c1, t1, v0; \n\
1670 mad r0.xyz, c2, t2, r0; \n\
1671 mad r0.xyz, c3, t3, r0; \n\
1672 mul_x2 r0.xyz, r0, t0; \n\
1673 +mov r0.w, t0; \n\
1674 }; \n\
1676 technique four_stages_4 \n\
1677 { \n\
1678 pass p0 \n\
1679 { \n\
1680 TexCoordIndex[2] = 1; \n\
1681 TexCoordIndex[3] = 1; \n\
1683 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1684 Lighting = true; \n\
1685 MaterialEmissive= <factor0>; \n\
1686 MaterialAmbient= <g_black>; \n\
1687 MaterialDiffuse= <g_dyn_factor>; \n\
1688 MaterialSpecular= <g_black>; \n\
1689 AlphaBlendEnable = true; \n\
1690 SrcBlend = srcalpha; \n\
1691 DestBlend = invsrcalpha; \n\
1693 Texture[0] = <texture0>; \n\
1694 Texture[1] = <texture1>; \n\
1695 Texture[2] = <texture2>; \n\
1696 Texture[3] = <texture3>; \n\
1697 PixelShaderConstant[1] = <factor1>; \n\
1698 PixelShaderConstant[2] = <factor2>; \n\
1699 PixelShaderConstant[3] = <factor3>; \n\
1700 PixelShader = (four_stages_ps); \n\
1701 } \n\
1702 } \n\
1704 // **** 3 stages technique \n\
1705 pixelshader three_stages_0_ps = asm \n\
1706 { \n\
1707 ps_1_1; \n\
1708 tex t0; \n\
1709 tex t1; \n\
1710 tex t2; \n\
1711 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1712 mad r0.xyz, c1, t1, v0; \n\
1713 mad r0.xyz, c2, t2, r0; \n\
1714 mul_x2 r0.xyz, r0, t0; \n\
1715 +mov r0.w, t0; \n\
1716 }; \n\
1718 technique three_stages_3 \n\
1719 { \n\
1720 pass p0 \n\
1721 { \n\
1722 TexCoordIndex[2] = 1; \n\
1724 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1725 Lighting = true; \n\
1726 MaterialEmissive= <factor0>; \n\
1727 MaterialAmbient= <g_black>; \n\
1728 MaterialDiffuse= <g_dyn_factor>; \n\
1729 MaterialSpecular= <g_black>; \n\
1730 AlphaBlendEnable = true; \n\
1731 SrcBlend = srcalpha; \n\
1732 DestBlend = invsrcalpha; \n\
1734 Texture[0] = <texture0>; \n\
1735 Texture[1] = <texture1>; \n\
1736 Texture[2] = <texture2>; \n\
1737 PixelShaderConstant[1] = <factor1>; \n\
1738 PixelShaderConstant[2] = <factor2>; \n\
1739 PixelShader = (three_stages_0_ps); \n\
1740 } \n\
1741 pass p1 \n\
1742 { \n\
1743 FogColor = 0x00000000; // don't accumulate fog several times\n\
1744 DestBlend = one; \n\
1745 Lighting = false; \n\
1747 // the DiffuseTexture texture 0 is in last stage \n\
1748 TexCoordIndex[0] = 1; \n\
1749 TexCoordIndex[1] = 0; \n\
1750 Texture[0] = <texture3>; \n\
1751 Texture[1] = <texture0>; \n\
1752 TextureFactor = <color3>; \n\
1753 ColorOp[0] = MODULATE; \n\
1754 ColorArg1[0] = TFACTOR; \n\
1755 ColorArg2[0] = TEXTURE; \n\
1756 ColorOp[1] = MODULATE2X; \n\
1757 ColorArg1[1] = CURRENT; \n\
1758 ColorArg2[1] = TEXTURE; \n\
1759 ColorOp[2] = DISABLE; \n\
1760 // Alpha stage 0 unused \n\
1761 AlphaOp[0] = SELECTARG1; \n\
1762 AlphaArg1[0] = TFACTOR; \n\
1763 AlphaOp[1] = SELECTARG1; \n\
1764 AlphaArg1[1] = TEXTURE; \n\
1765 AlphaOp[2] = DISABLE; \n\
1766 PixelShader = NULL; \n\
1767 } \n\
1768 } \n\
1770 // **** 2 stages, no pixel shader technique \n\
1771 technique two_stages_2 \n\
1772 { \n\
1773 pass p0 \n\
1774 { \n\
1775 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1776 Lighting = true; \n\
1777 MaterialEmissive= <factor0>; \n\
1778 MaterialAmbient= <g_black>; \n\
1779 MaterialDiffuse= <g_dyn_factor>; \n\
1780 MaterialSpecular= <g_black>; \n\
1781 AlphaBlendEnable = true; \n\
1782 SrcBlend = srcalpha; \n\
1783 DestBlend = invsrcalpha; \n\
1785 // the DiffuseTexture texture 0 is in last stage \n\
1786 TexCoordIndex[0] = 1; \n\
1787 TexCoordIndex[1] = 0; \n\
1788 Texture[0] = <texture1>; \n\
1789 Texture[1] = <texture0>; \n\
1790 TextureFactor = <color1>; \n\
1791 ColorOp[0] = MULTIPLYADD; \n\
1792 ColorArg0[0] = DIFFUSE; \n\
1793 ColorArg1[0] = TFACTOR; \n\
1794 ColorArg2[0] = TEXTURE; \n\
1795 ColorOp[1] = MODULATE2X; \n\
1796 ColorArg1[1] = CURRENT; \n\
1797 ColorArg2[1] = TEXTURE; \n\
1798 // Alpha stage 0 unused \n\
1799 AlphaOp[0] = SELECTARG1; \n\
1800 AlphaArg1[0] = TFACTOR; \n\
1801 AlphaOp[1] = SELECTARG1; \n\
1802 AlphaArg1[1] = TEXTURE; \n\
1803 } \n\
1804 pass p1 \n\
1805 { \n\
1806 FogColor = 0x00000000; // don't accumulate fog several times\n\
1807 Lighting = false; \n\
1808 DestBlend = one; \n\
1809 Texture[0] = <texture2>; \n\
1810 TextureFactor = <color2>; \n\
1811 ColorOp[0] = MODULATE; \n\
1812 } \n\
1813 pass p2 \n\
1814 { \n\
1815 Texture[0] = <texture3>; \n\
1816 TextureFactor = <color3>; \n\
1817 } \n\
1818 } \n\
1822 static const char *Lightmap3_x2Fx =
1823 " \n\
1824 texture texture0; \n\
1825 texture texture1; \n\
1826 texture texture2; \n\
1827 texture texture3; \n\
1828 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
1829 // Other colors are the lightmap Factors for each lightmap \n\
1830 dword color0; \n\
1831 dword color1; \n\
1832 dword color2; \n\
1833 dword color3; \n\
1834 float4 factor0; \n\
1835 float4 factor1; \n\
1836 float4 factor2; \n\
1837 float4 factor3; \n\
1839 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
1840 // modulate the dyn light by 0.5, because of MODULATE2X \n\
1841 float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
1844 // **** 4 stages technique \n\
1845 pixelshader four_stages_ps = asm \n\
1846 { \n\
1847 ps_1_1; \n\
1848 tex t0; \n\
1849 tex t1; \n\
1850 tex t2; \n\
1851 tex t3; \n\
1852 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1853 mad r0.xyz, c1, t1, v0; \n\
1854 mad r0.xyz, c2, t2, r0; \n\
1855 mad r0.xyz, c3, t3, r0; \n\
1856 mul_x2 r0.xyz, r0, t0; \n\
1857 +mov r0.w, t0; \n\
1858 }; \n\
1860 technique four_stages_4 \n\
1861 { \n\
1862 pass p0 \n\
1863 { \n\
1864 TexCoordIndex[2] = 1; \n\
1865 TexCoordIndex[3] = 1; \n\
1867 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1868 Lighting = true; \n\
1869 MaterialEmissive= <factor0>; \n\
1870 MaterialAmbient= <g_black>; \n\
1871 MaterialDiffuse= <g_dyn_factor>; \n\
1872 MaterialSpecular= <g_black>; \n\
1873 AlphaBlendEnable = false; \n\
1875 Texture[0] = <texture0>; \n\
1876 Texture[1] = <texture1>; \n\
1877 Texture[2] = <texture2>; \n\
1878 Texture[3] = <texture3>; \n\
1879 PixelShaderConstant[1] = <factor1>; \n\
1880 PixelShaderConstant[2] = <factor2>; \n\
1881 PixelShaderConstant[3] = <factor3>; \n\
1882 PixelShader = (four_stages_ps); \n\
1883 } \n\
1884 } \n\
1886 // **** 3 stages technique \n\
1887 pixelshader three_stages_0_ps = asm \n\
1888 { \n\
1889 ps_1_1; \n\
1890 tex t0; \n\
1891 tex t1; \n\
1892 tex t2; \n\
1893 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
1894 mad r0.xyz, c1, t1, v0; \n\
1895 mad r0.xyz, c2, t2, r0; \n\
1896 mul_x2 r0.xyz, r0, t0; \n\
1897 +mov r0.w, t0; \n\
1898 }; \n\
1900 technique three_stages_3 \n\
1901 { \n\
1902 pass p0 \n\
1903 { \n\
1904 TexCoordIndex[2] = 1; \n\
1906 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1907 Lighting = true; \n\
1908 MaterialEmissive= <factor0>; \n\
1909 MaterialAmbient= <g_black>; \n\
1910 MaterialDiffuse= <g_dyn_factor>; \n\
1911 MaterialSpecular= <g_black>; \n\
1912 AlphaBlendEnable = false; \n\
1914 Texture[0] = <texture0>; \n\
1915 Texture[1] = <texture1>; \n\
1916 Texture[2] = <texture2>; \n\
1917 PixelShaderConstant[1] = <factor1>; \n\
1918 PixelShaderConstant[2] = <factor2>; \n\
1919 PixelShader = (three_stages_0_ps); \n\
1920 } \n\
1921 pass p1 \n\
1922 { \n\
1923 FogColor = 0x00000000; // don't accumulate fog several times\n\
1924 AlphaBlendEnable = true; \n\
1925 SrcBlend = one; \n\
1926 DestBlend = one; \n\
1927 Lighting = false; \n\
1929 // the DiffuseTexture texture 0 is in last stage \n\
1930 TexCoordIndex[0] = 1; \n\
1931 TexCoordIndex[1] = 0; \n\
1932 Texture[0] = <texture3>; \n\
1933 Texture[1] = <texture0>; \n\
1934 TextureFactor = <color3>; \n\
1935 ColorOp[0] = MODULATE; \n\
1936 ColorArg1[0] = TFACTOR; \n\
1937 ColorArg2[0] = TEXTURE; \n\
1938 ColorOp[1] = MODULATE2X; \n\
1939 ColorArg1[1] = CURRENT; \n\
1940 ColorArg2[1] = TEXTURE; \n\
1941 ColorOp[2] = DISABLE; \n\
1942 // Alpha stage 0 unused \n\
1943 AlphaOp[0] = SELECTARG1; \n\
1944 AlphaArg1[0] = TFACTOR; \n\
1945 AlphaOp[1] = SELECTARG1; \n\
1946 AlphaArg1[1] = TEXTURE; // for case when there's alpha test \n\
1947 AlphaOp[2] = DISABLE; \n\
1948 PixelShader = NULL; \n\
1949 } \n\
1950 } \n\
1952 // **** 2 stages, no pixel shader technique \n\
1953 technique two_stages_2 \n\
1954 { \n\
1955 pass p0 \n\
1956 { \n\
1957 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
1958 Lighting = true; \n\
1959 MaterialEmissive= <factor0>; \n\
1960 MaterialAmbient= <g_black>; \n\
1961 MaterialDiffuse= <g_dyn_factor>; \n\
1962 MaterialSpecular= <g_black>; \n\
1963 AlphaBlendEnable = false; \n\
1965 // the DiffuseTexture texture 0 is in last stage \n\
1966 TexCoordIndex[0] = 1; \n\
1967 TexCoordIndex[1] = 0; \n\
1968 Texture[0] = <texture1>; \n\
1969 Texture[1] = <texture0>; \n\
1970 TextureFactor = <color1>; \n\
1971 ColorOp[0] = MULTIPLYADD; \n\
1972 ColorArg0[0] = DIFFUSE; \n\
1973 ColorArg1[0] = TFACTOR; \n\
1974 ColorArg2[0] = TEXTURE; \n\
1975 ColorOp[1] = MODULATE2X; \n\
1976 ColorArg1[1] = CURRENT; \n\
1977 ColorArg2[1] = TEXTURE; \n\
1978 // Alpha stage 0 unused \n\
1979 AlphaOp[0] = SELECTARG1; \n\
1980 AlphaArg1[0] = TFACTOR; \n\
1981 AlphaOp[1] = SELECTARG1; // alpha in case were alpha test is used\n\
1982 AlphaArg1[1] = TEXTURE; \n\
1983 } \n\
1984 pass p1 \n\
1985 { \n\
1986 FogColor = 0x00000000; // don't accumulate fog several times\n\
1987 Lighting = false; \n\
1988 AlphaBlendEnable = true; \n\
1989 SrcBlend = one; \n\
1990 DestBlend = one; \n\
1991 Texture[0] = <texture2>; \n\
1992 TextureFactor = <color2>; \n\
1993 ColorOp[0] = MODULATE; \n\
1994 } \n\
1995 pass p2 \n\
1996 { \n\
1997 Texture[0] = <texture3>; \n\
1998 TextureFactor = <color3>; \n\
1999 } \n\
2000 } \n\
2006 static const char *Lightmap4Fx =
2007 " \n\
2008 texture texture0; \n\
2009 texture texture1; \n\
2010 texture texture2; \n\
2011 texture texture3; \n\
2012 texture texture4; \n\
2013 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
2014 // Other colors are the lightmap Factors for each lightmap \n\
2015 dword color0; \n\
2016 dword color1; \n\
2017 dword color2; \n\
2018 dword color3; \n\
2019 dword color4; \n\
2020 float4 factor0; \n\
2021 float4 factor1; \n\
2022 float4 factor2; \n\
2023 float4 factor3; \n\
2024 float4 factor4; \n\
2026 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
2027 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
2030 // **** 5 stages technique \n\
2031 pixelshader five_stages_ps = asm \n\
2032 { \n\
2033 ps_1_4; \n\
2034 texld r0, t0; \n\
2035 texld r1, t1; \n\
2036 texld r2, t2; \n\
2037 texld r3, t3; \n\
2038 texld r4, t4; \n\
2039 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2040 mad r1.xyz, c1, r1, v0; \n\
2041 mad r1.xyz, c2, r2, r1; \n\
2042 mad r1.xyz, c3, r3, r1; \n\
2043 mad r1.xyz, c4, r4, r1; \n\
2044 mul r0.xyz, r1, r0; \n\
2045 }; \n\
2047 technique five_stages_5 \n\
2048 { \n\
2049 pass p0 \n\
2050 { \n\
2051 TexCoordIndex[2] = 1; \n\
2052 TexCoordIndex[3] = 1; \n\
2053 TexCoordIndex[4] = 1; \n\
2055 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2056 Lighting = true; \n\
2057 MaterialEmissive= <factor0>; \n\
2058 MaterialAmbient= <g_black>; \n\
2059 MaterialDiffuse= <g_dyn_factor>; \n\
2060 MaterialSpecular= <g_black>; \n\
2061 AlphaBlendEnable = false; \n\
2063 Texture[0] = <texture0>; \n\
2064 Texture[1] = <texture1>; \n\
2065 Texture[2] = <texture2>; \n\
2066 Texture[3] = <texture3>; \n\
2067 Texture[4] = <texture4>; \n\
2068 PixelShaderConstant[1] = <factor1>; \n\
2069 PixelShaderConstant[2] = <factor2>; \n\
2070 PixelShaderConstant[3] = <factor3>; \n\
2071 PixelShaderConstant[4] = <factor4>; \n\
2072 PixelShader = (five_stages_ps); \n\
2073 } \n\
2074 } \n\
2076 // **** 4 stages technique \n\
2077 pixelshader four_stages_ps = asm \n\
2078 { \n\
2079 ps_1_1; \n\
2080 tex t0; \n\
2081 tex t1; \n\
2082 tex t2; \n\
2083 tex t3; \n\
2084 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2085 mad r0.xyz, c1, t1, v0; \n\
2086 mad r0.xyz, c2, t2, r0; \n\
2087 mad r0.xyz, c3, t3, r0; \n\
2088 mul r0.xyz, r0, t0; \n\
2089 +mov r0.w, t0; \n\
2090 }; \n\
2092 technique four_stages_4 \n\
2093 { \n\
2094 pass p0 \n\
2095 { \n\
2096 TexCoordIndex[2] = 1; \n\
2097 TexCoordIndex[3] = 1; \n\
2099 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2100 Lighting = true; \n\
2101 MaterialEmissive= <factor0>; \n\
2102 MaterialAmbient= <g_black>; \n\
2103 MaterialDiffuse= <g_dyn_factor>; \n\
2104 MaterialSpecular= <g_black>; \n\
2105 AlphaBlendEnable = false; \n\
2107 Texture[0] = <texture0>; \n\
2108 Texture[1] = <texture1>; \n\
2109 Texture[2] = <texture2>; \n\
2110 Texture[3] = <texture3>; \n\
2111 PixelShaderConstant[1] = <factor1>; \n\
2112 PixelShaderConstant[2] = <factor2>; \n\
2113 PixelShaderConstant[3] = <factor3>; \n\
2114 PixelShader = (four_stages_ps); \n\
2115 } \n\
2116 pass p1 \n\
2117 { \n\
2118 FogColor = 0x00000000; // don't accumulate fog several times\n\
2119 Lighting = false; \n\
2120 AlphaBlendEnable = true; \n\
2121 SrcBlend = one; \n\
2122 DestBlend = one; \n\
2124 // the DiffuseTexture texture 0 is in last stage \n\
2125 TexCoordIndex[0] = 1; \n\
2126 TexCoordIndex[1] = 0; \n\
2127 Texture[0] = <texture4>; \n\
2128 Texture[1] = <texture0>; \n\
2129 TextureFactor = <color4>; \n\
2130 ColorOp[0] = MODULATE; \n\
2131 ColorArg1[0] = TFACTOR; \n\
2132 ColorArg2[0] = TEXTURE; \n\
2133 ColorOp[1] = MODULATE; \n\
2134 ColorArg1[1] = CURRENT; \n\
2135 ColorArg2[1] = TEXTURE; \n\
2136 ColorOp[2] = DISABLE; \n\
2137 ColorOp[3] = DISABLE; \n\
2138 // Alpha stage 0 unused \n\
2139 AlphaOp[0] = SELECTARG1; \n\
2140 AlphaArg1[0] = TFACTOR; \n\
2141 AlphaOp[1] = SELECTARG1; \n\
2142 AlphaArg1[1] = TEXTURE; \n\
2143 AlphaOp[2] = DISABLE; \n\
2144 AlphaOp[3] = DISABLE; \n\
2145 PixelShader = NULL; \n\
2146 } \n\
2147 } \n\
2149 // **** 3 stages technique \n\
2150 pixelshader three_stages_0_ps = asm \n\
2151 { \n\
2152 ps_1_1; \n\
2153 tex t0; \n\
2154 tex t1; \n\
2155 tex t2; \n\
2156 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2157 mad r0.xyz, c1, t1, v0; \n\
2158 mad r0.xyz, c2, t2, r0; \n\
2159 mul r0.xyz, r0, t0; \n\
2160 +mov r0.w, t0; \n\
2161 }; \n\
2163 technique three_stages_3 \n\
2164 { \n\
2165 // 2 pass with the same pixel shader \n\
2166 pass p0 \n\
2167 { \n\
2168 TexCoordIndex[2] = 1; \n\
2170 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2171 Lighting = true; \n\
2172 MaterialEmissive= <factor0>; \n\
2173 MaterialAmbient= <g_black>; \n\
2174 MaterialDiffuse= <g_dyn_factor>; \n\
2175 MaterialSpecular= <g_black>; \n\
2176 AlphaBlendEnable = false; \n\
2178 Texture[0] = <texture0>; \n\
2179 Texture[1] = <texture1>; \n\
2180 Texture[2] = <texture2>; \n\
2181 PixelShaderConstant[1] = <factor1>; \n\
2182 PixelShaderConstant[2] = <factor2>; \n\
2183 PixelShader = (three_stages_0_ps); \n\
2184 } \n\
2185 pass p1 \n\
2186 { \n\
2187 FogColor = 0x00000000; // don't accumulate fog several times\n\
2188 // second pass: shut down all lighting (lmc ambient term and dynamic lighting already added in first pass)\n\
2189 MaterialEmissive= <g_black>; \n\
2190 MaterialDiffuse= <g_black>; \n\
2192 AlphaBlendEnable = true; \n\
2193 SrcBlend = one; \n\
2194 DestBlend = one; \n\
2195 Texture[1] = <texture3>; \n\
2196 Texture[2] = <texture4>; \n\
2197 PixelShaderConstant[1] = <factor3>; \n\
2198 PixelShaderConstant[2] = <factor4>; \n\
2199 } \n\
2200 } \n\
2202 // **** 2 stages, no pixel shader technique \n\
2203 technique two_stages_2 \n\
2204 { \n\
2205 pass p0 \n\
2206 { \n\
2207 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2208 Lighting = true; \n\
2209 MaterialEmissive= <factor0>; \n\
2210 MaterialAmbient= <g_black>; \n\
2211 MaterialDiffuse= <g_dyn_factor>; \n\
2212 MaterialSpecular= <g_black>; \n\
2213 AlphaBlendEnable = false; \n\
2215 // the DiffuseTexture texture 0 is in last stage \n\
2216 TexCoordIndex[0] = 1; \n\
2217 TexCoordIndex[1] = 0; \n\
2218 Texture[0] = <texture1>; \n\
2219 Texture[1] = <texture0>; \n\
2220 TextureFactor = <color1>; \n\
2221 ColorOp[0] = MULTIPLYADD; \n\
2222 ColorArg0[0] = DIFFUSE; \n\
2223 ColorArg1[0] = TFACTOR; \n\
2224 ColorArg2[0] = TEXTURE; \n\
2225 ColorOp[1] = MODULATE; \n\
2226 ColorArg1[1] = CURRENT; \n\
2227 ColorArg2[1] = TEXTURE; \n\
2228 // Alpha stage 0 unused \n\
2229 AlphaOp[0] = SELECTARG1; \n\
2230 AlphaArg1[0] = TFACTOR; \n\
2231 AlphaOp[1] = SELECTARG1; \n\
2232 AlphaArg1[1] = TEXTURE; \n\
2233 } \n\
2234 pass p1 \n\
2235 { \n\
2236 FogColor = 0x00000000; // don't accumulate fog several times\n\
2237 Lighting = false; \n\
2238 AlphaBlendEnable = true; \n\
2239 SrcBlend = one; \n\
2240 DestBlend = one; \n\
2241 Texture[0] = <texture2>; \n\
2242 TextureFactor = <color2>; \n\
2243 ColorOp[0] = MODULATE; \n\
2244 } \n\
2245 pass p2 \n\
2246 { \n\
2247 Texture[0] = <texture3>; \n\
2248 TextureFactor = <color3>; \n\
2249 } \n\
2250 pass p3 \n\
2251 { \n\
2252 Texture[0] = <texture4>; \n\
2253 TextureFactor = <color4>; \n\
2254 } \n\
2255 } \n\
2260 static const char *Lightmap4blendFx =
2261 " \n\
2262 texture texture0; \n\
2263 texture texture1; \n\
2264 texture texture2; \n\
2265 texture texture3; \n\
2266 texture texture4; \n\
2267 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
2268 // Other colors are the lightmap Factors for each lightmap \n\
2269 dword color0; \n\
2270 dword color1; \n\
2271 dword color2; \n\
2272 dword color3; \n\
2273 dword color4; \n\
2274 float4 factor0; \n\
2275 float4 factor1; \n\
2276 float4 factor2; \n\
2277 float4 factor3; \n\
2278 float4 factor4; \n\
2280 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
2281 float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
2284 // **** 5 stages technique \n\
2285 pixelshader five_stages_ps = asm \n\
2286 { \n\
2287 ps_1_4; \n\
2288 texld r0, t0; \n\
2289 texld r1, t1; \n\
2290 texld r2, t2; \n\
2291 texld r3, t3; \n\
2292 texld r4, t4; \n\
2293 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2294 mad r1.xyz, c1, r1, v0; \n\
2295 mad r1.xyz, c2, r2, r1; \n\
2296 mad r1.xyz, c3, r3, r1; \n\
2297 mad r1.xyz, c4, r4, r1; \n\
2298 mul r0.xyz, r1, r0; \n\
2299 mov r0.w, r0; \n\
2300 }; \n\
2302 technique five_stages_5 \n\
2303 { \n\
2304 pass p0 \n\
2305 { \n\
2306 TexCoordIndex[2] = 1; \n\
2307 TexCoordIndex[3] = 1; \n\
2308 TexCoordIndex[4] = 1; \n\
2310 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2311 Lighting = true; \n\
2312 MaterialEmissive= <factor0>; \n\
2313 MaterialAmbient= <g_black>; \n\
2314 MaterialDiffuse= <g_dyn_factor>; \n\
2315 MaterialSpecular= <g_black>; \n\
2316 AlphaBlendEnable = true; \n\
2317 SrcBlend = srcalpha; \n\
2318 DestBlend = invsrcalpha; \n\
2320 Texture[0] = <texture0>; \n\
2321 Texture[1] = <texture1>; \n\
2322 Texture[2] = <texture2>; \n\
2323 Texture[3] = <texture3>; \n\
2324 Texture[4] = <texture4>; \n\
2325 PixelShaderConstant[1] = <factor1>; \n\
2326 PixelShaderConstant[2] = <factor2>; \n\
2327 PixelShaderConstant[3] = <factor3>; \n\
2328 PixelShaderConstant[4] = <factor4>; \n\
2329 PixelShader = (five_stages_ps); \n\
2330 } \n\
2331 } \n\
2333 // **** 4 stages technique \n\
2334 pixelshader four_stages_ps = asm \n\
2335 { \n\
2336 ps_1_1; \n\
2337 tex t0; \n\
2338 tex t1; \n\
2339 tex t2; \n\
2340 tex t3; \n\
2341 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2342 mad r0.xyz, c1, t1, v0; \n\
2343 mad r0.xyz, c2, t2, r0; \n\
2344 mad r0.xyz, c3, t3, r0; \n\
2345 mul r0.xyz, r0, t0; \n\
2346 mov r0.w, t0; \n\
2347 }; \n\
2349 technique four_stages_4 \n\
2350 { \n\
2351 pass p0 \n\
2352 { \n\
2353 TexCoordIndex[2] = 1; \n\
2354 TexCoordIndex[3] = 1; \n\
2356 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2357 Lighting = true; \n\
2358 MaterialEmissive= <factor0>; \n\
2359 MaterialAmbient= <g_black>; \n\
2360 MaterialDiffuse= <g_dyn_factor>; \n\
2361 MaterialSpecular= <g_black>; \n\
2362 AlphaBlendEnable = true; \n\
2363 SrcBlend = srcalpha; \n\
2364 DestBlend = invsrcalpha; \n\
2366 Texture[0] = <texture0>; \n\
2367 Texture[1] = <texture1>; \n\
2368 Texture[2] = <texture2>; \n\
2369 Texture[3] = <texture3>; \n\
2370 PixelShaderConstant[1] = <factor1>; \n\
2371 PixelShaderConstant[2] = <factor2>; \n\
2372 PixelShaderConstant[3] = <factor3>; \n\
2373 PixelShader = (four_stages_ps); \n\
2374 } \n\
2375 pass p1 \n\
2376 { \n\
2377 FogColor = 0x00000000; // don't accumulate fog several times\n\
2378 Lighting = false; \n\
2379 DestBlend = one; \n\
2381 // the DiffuseTexture texture 0 is in last stage \n\
2382 TexCoordIndex[0] = 1; \n\
2383 TexCoordIndex[1] = 0; \n\
2384 Texture[0] = <texture4>; \n\
2385 Texture[1] = <texture0>; \n\
2386 TextureFactor = <color4>; \n\
2387 ColorOp[0] = MODULATE; \n\
2388 ColorArg1[0] = TFACTOR; \n\
2389 ColorArg2[0] = TEXTURE; \n\
2390 ColorOp[1] = MODULATE; \n\
2391 ColorArg1[1] = CURRENT; \n\
2392 ColorArg2[1] = TEXTURE; \n\
2393 ColorOp[2] = DISABLE; \n\
2394 ColorOp[3] = DISABLE; \n\
2395 // Alpha stage 0 unused \n\
2396 AlphaOp[0] = SELECTARG1; \n\
2397 AlphaArg1[0] = TFACTOR; \n\
2398 AlphaOp[1] = SELECTARG1; \n\
2399 AlphaArg1[1] = TEXTURE; \n\
2400 AlphaOp[2] = DISABLE; \n\
2401 AlphaOp[3] = DISABLE; \n\
2402 PixelShader = NULL; \n\
2403 } \n\
2404 } \n\
2406 // **** 3 stages technique \n\
2407 pixelshader three_stages_0_ps = asm \n\
2408 { \n\
2409 ps_1_1; \n\
2410 tex t0; \n\
2411 tex t1; \n\
2412 tex t2; \n\
2413 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2414 mad r0.xyz, c1, t1, v0; \n\
2415 mad r0.xyz, c2, t2, r0; \n\
2416 mul r0.xyz, r0, t0; \n\
2417 mov r0.w, t0; \n\
2418 }; \n\
2420 technique three_stages_3 \n\
2421 { \n\
2422 // 2 pass with the same pixel shader \n\
2423 pass p0 \n\
2424 { \n\
2425 TexCoordIndex[2] = 1; \n\
2427 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2428 Lighting = true; \n\
2429 MaterialEmissive= <factor0>; \n\
2430 MaterialAmbient= <g_black>; \n\
2431 MaterialDiffuse= <g_dyn_factor>; \n\
2432 MaterialSpecular= <g_black>; \n\
2433 AlphaBlendEnable = true; \n\
2434 SrcBlend = srcalpha; \n\
2435 DestBlend = invsrcalpha; \n\
2437 Texture[0] = <texture0>; \n\
2438 Texture[1] = <texture1>; \n\
2439 Texture[2] = <texture2>; \n\
2440 PixelShaderConstant[1] = <factor1>; \n\
2441 PixelShaderConstant[2] = <factor2>; \n\
2442 PixelShader = (three_stages_0_ps); \n\
2443 } \n\
2444 pass p1 \n\
2445 { \n\
2446 FogColor = 0x00000000; // don't accumulate fog several times\n\
2447 // second pass: shut down all lighting (lmc ambient term and dynamic lighting already added in first pass)\n\
2448 MaterialEmissive= <g_black>; \n\
2449 MaterialDiffuse= <g_black>; \n\
2451 DestBlend = one; \n\
2452 Texture[1] = <texture3>; \n\
2453 Texture[2] = <texture4>; \n\
2454 PixelShaderConstant[1] = <factor3>; \n\
2455 PixelShaderConstant[2] = <factor4>; \n\
2456 } \n\
2457 } \n\
2459 // **** 2 stages, no pixel shader technique \n\
2460 technique two_stages_2 \n\
2461 { \n\
2462 pass p0 \n\
2463 { \n\
2464 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2465 Lighting = true; \n\
2466 MaterialEmissive= <factor0>; \n\
2467 MaterialAmbient= <g_black>; \n\
2468 MaterialDiffuse= <g_dyn_factor>; \n\
2469 MaterialSpecular= <g_black>; \n\
2470 AlphaBlendEnable = true; \n\
2471 SrcBlend = srcalpha; \n\
2472 DestBlend = invsrcalpha; \n\
2474 // the DiffuseTexture texture 0 is in last stage \n\
2475 TexCoordIndex[0] = 1; \n\
2476 TexCoordIndex[1] = 0; \n\
2477 Texture[0] = <texture1>; \n\
2478 Texture[1] = <texture0>; \n\
2479 TextureFactor = <color1>; \n\
2480 ColorOp[0] = MULTIPLYADD; \n\
2481 ColorArg0[0] = DIFFUSE; \n\
2482 ColorArg1[0] = TFACTOR; \n\
2483 ColorArg2[0] = TEXTURE; \n\
2484 ColorOp[1] = MODULATE; \n\
2485 ColorArg1[1] = CURRENT; \n\
2486 ColorArg2[1] = TEXTURE; \n\
2487 // Alpha stage 0 unused \n\
2488 AlphaOp[0] = SELECTARG1; \n\
2489 AlphaArg1[0] = TFACTOR; \n\
2490 AlphaOp[1] = SELECTARG1; \n\
2491 AlphaArg1[1] = TEXTURE; \n\
2492 } \n\
2493 pass p1 \n\
2494 { \n\
2495 FogColor = 0x00000000; // don't accumulate fog several times\n\
2496 Lighting = false; \n\
2497 DestBlend = one; \n\
2498 Texture[0] = <texture2>; \n\
2499 TextureFactor = <color2>; \n\
2500 ColorOp[0] = MODULATE; \n\
2501 } \n\
2502 pass p2 \n\
2503 { \n\
2504 Texture[0] = <texture3>; \n\
2505 TextureFactor = <color3>; \n\
2506 } \n\
2507 pass p3 \n\
2508 { \n\
2509 Texture[0] = <texture4>; \n\
2510 TextureFactor = <color4>; \n\
2511 } \n\
2512 } \n\
2518 static const char *Lightmap4blend_x2Fx =
2519 " \n\
2520 texture texture0; \n\
2521 texture texture1; \n\
2522 texture texture2; \n\
2523 texture texture3; \n\
2524 texture texture4; \n\
2525 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
2526 // Other colors are the lightmap Factors for each lightmap \n\
2527 dword color0; \n\
2528 dword color1; \n\
2529 dword color2; \n\
2530 dword color3; \n\
2531 dword color4; \n\
2532 float4 factor0; \n\
2533 float4 factor1; \n\
2534 float4 factor2; \n\
2535 float4 factor3; \n\
2536 float4 factor4; \n\
2538 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
2539 // modulate the dyn light by 0.5, because of MODULATE2X \n\
2540 float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
2543 // **** 5 stages technique \n\
2544 pixelshader five_stages_ps = asm \n\
2545 { \n\
2546 ps_1_4; \n\
2547 texld r0, t0; \n\
2548 texld r1, t1; \n\
2549 texld r2, t2; \n\
2550 texld r3, t3; \n\
2551 texld r4, t4; \n\
2552 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2553 mad r1.xyz, c1, r1, v0; \n\
2554 mad r1.xyz, c2, r2, r1; \n\
2555 mad r1.xyz, c3, r3, r1; \n\
2556 mad r1.xyz, c4, r4, r1; \n\
2557 mul_x2 r0.xyz, r1, r0; \n\
2558 }; \n\
2560 technique five_stages_5 \n\
2561 { \n\
2562 pass p0 \n\
2563 { \n\
2564 TexCoordIndex[2] = 1; \n\
2565 TexCoordIndex[3] = 1; \n\
2566 TexCoordIndex[4] = 1; \n\
2568 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2569 Lighting = true; \n\
2570 MaterialEmissive= <factor0>; \n\
2571 MaterialAmbient= <g_black>; \n\
2572 MaterialDiffuse= <g_dyn_factor>; \n\
2573 MaterialSpecular= <g_black>; \n\
2574 AlphaBlendEnable = true; \n\
2575 SrcBlend = srcalpha; \n\
2576 DestBlend = invsrcalpha; \n\
2578 Texture[0] = <texture0>; \n\
2579 Texture[1] = <texture1>; \n\
2580 Texture[2] = <texture2>; \n\
2581 Texture[3] = <texture3>; \n\
2582 Texture[4] = <texture4>; \n\
2583 PixelShaderConstant[1] = <factor1>; \n\
2584 PixelShaderConstant[2] = <factor2>; \n\
2585 PixelShaderConstant[3] = <factor3>; \n\
2586 PixelShaderConstant[4] = <factor4>; \n\
2587 PixelShader = (five_stages_ps); \n\
2588 } \n\
2589 } \n\
2591 // **** 4 stages technique \n\
2592 pixelshader four_stages_ps = asm \n\
2593 { \n\
2594 ps_1_1; \n\
2595 tex t0; \n\
2596 tex t1; \n\
2597 tex t2; \n\
2598 tex t3; \n\
2599 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2600 mad r0.xyz, c1, t1, v0; \n\
2601 mad r0.xyz, c2, t2, r0; \n\
2602 mad r0.xyz, c3, t3, r0; \n\
2603 mul_x2 r0.xyz, r0, t0; \n\
2604 +mov r0.w, t0; \n\
2605 }; \n\
2607 technique four_stages_4 \n\
2608 { \n\
2609 pass p0 \n\
2610 { \n\
2611 TexCoordIndex[2] = 1; \n\
2612 TexCoordIndex[3] = 1; \n\
2614 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2615 Lighting = true; \n\
2616 MaterialEmissive= <factor0>; \n\
2617 MaterialAmbient= <g_black>; \n\
2618 MaterialDiffuse= <g_dyn_factor>; \n\
2619 MaterialSpecular= <g_black>; \n\
2620 AlphaBlendEnable = true; \n\
2621 SrcBlend = srcalpha; \n\
2622 DestBlend = invsrcalpha; \n\
2624 Texture[0] = <texture0>; \n\
2625 Texture[1] = <texture1>; \n\
2626 Texture[2] = <texture2>; \n\
2627 Texture[3] = <texture3>; \n\
2628 PixelShaderConstant[1] = <factor1>; \n\
2629 PixelShaderConstant[2] = <factor2>; \n\
2630 PixelShaderConstant[3] = <factor3>; \n\
2631 PixelShader = (four_stages_ps); \n\
2632 } \n\
2633 pass p1 \n\
2634 { \n\
2635 FogColor = 0x00000000; // don't accumulate fog several times\n\
2636 Lighting = false; \n\
2637 DestBlend = one; \n\
2639 // the DiffuseTexture texture 0 is in last stage \n\
2640 TexCoordIndex[0] = 1; \n\
2641 TexCoordIndex[1] = 0; \n\
2642 Texture[0] = <texture4>; \n\
2643 Texture[1] = <texture0>; \n\
2644 TextureFactor = <color4>; \n\
2645 ColorOp[0] = MODULATE; \n\
2646 ColorArg1[0] = TFACTOR; \n\
2647 ColorArg2[0] = TEXTURE; \n\
2648 ColorOp[1] = MODULATE2X; \n\
2649 ColorArg1[1] = CURRENT; \n\
2650 ColorArg2[1] = TEXTURE; \n\
2651 ColorOp[2] = DISABLE; \n\
2652 ColorOp[3] = DISABLE; \n\
2653 // Alpha stage 0 unused \n\
2654 AlphaOp[0] = SELECTARG1; \n\
2655 AlphaArg1[0] = TFACTOR; \n\
2656 AlphaOp[1] = SELECTARG1; \n\
2657 AlphaArg1[1] = TEXTURE; \n\
2658 AlphaOp[2] = DISABLE; \n\
2659 AlphaOp[3] = DISABLE; \n\
2660 PixelShader = NULL; \n\
2661 } \n\
2662 } \n\
2664 // **** 3 stages technique \n\
2665 pixelshader three_stages_0_ps = asm \n\
2666 { \n\
2667 ps_1_1; \n\
2668 tex t0; \n\
2669 tex t1; \n\
2670 tex t2; \n\
2671 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2672 mad r0.xyz, c1, t1, v0; \n\
2673 mad r0.xyz, c2, t2, r0; \n\
2674 mul_x2 r0.xyz, r0, t0; \n\
2675 +mov r0.w, t0; \n\
2676 }; \n\
2678 technique three_stages_3 \n\
2679 { \n\
2680 // 2 pass with the same pixel shader \n\
2681 pass p0 \n\
2682 { \n\
2683 TexCoordIndex[2] = 1; \n\
2685 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2686 Lighting = true; \n\
2687 MaterialEmissive= <factor0>; \n\
2688 MaterialAmbient= <g_black>; \n\
2689 MaterialDiffuse= <g_dyn_factor>; \n\
2690 MaterialSpecular= <g_black>; \n\
2691 AlphaBlendEnable = true; \n\
2692 SrcBlend = srcalpha; \n\
2693 DestBlend = invsrcalpha; \n\
2695 Texture[0] = <texture0>; \n\
2696 Texture[1] = <texture1>; \n\
2697 Texture[2] = <texture2>; \n\
2698 PixelShaderConstant[1] = <factor1>; \n\
2699 PixelShaderConstant[2] = <factor2>; \n\
2700 PixelShader = (three_stages_0_ps); \n\
2701 } \n\
2702 pass p1 \n\
2703 { \n\
2704 FogColor = 0x00000000; // don't accumulate fog several times\n\
2705 // second pass: shut down all lighting (lmc ambient term and dynamic lighting already added in first pass)\n\
2706 MaterialEmissive= <g_black>; \n\
2707 MaterialDiffuse= <g_black>; \n\
2709 DestBlend = one; \n\
2710 Texture[1] = <texture3>; \n\
2711 Texture[2] = <texture4>; \n\
2712 PixelShaderConstant[1] = <factor3>; \n\
2713 PixelShaderConstant[2] = <factor4>; \n\
2714 } \n\
2715 } \n\
2717 // **** 2 stages, no pixel shader technique \n\
2718 technique two_stages_2 \n\
2719 { \n\
2720 pass p0 \n\
2721 { \n\
2722 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2723 Lighting = true; \n\
2724 MaterialEmissive= <factor0>; \n\
2725 MaterialAmbient= <g_black>; \n\
2726 MaterialDiffuse= <g_dyn_factor>; \n\
2727 MaterialSpecular= <g_black>; \n\
2728 AlphaBlendEnable = true; \n\
2729 SrcBlend = srcalpha; \n\
2730 DestBlend = invsrcalpha; \n\
2732 // the DiffuseTexture texture 0 is in last stage \n\
2733 TexCoordIndex[0] = 1; \n\
2734 TexCoordIndex[1] = 0; \n\
2735 Texture[0] = <texture1>; \n\
2736 Texture[1] = <texture0>; \n\
2737 TextureFactor = <color1>; \n\
2738 ColorOp[0] = MULTIPLYADD; \n\
2739 ColorArg0[0] = DIFFUSE; \n\
2740 ColorArg1[0] = TFACTOR; \n\
2741 ColorArg2[0] = TEXTURE; \n\
2742 ColorOp[1] = MODULATE2X; \n\
2743 ColorArg1[1] = CURRENT; \n\
2744 ColorArg2[1] = TEXTURE; \n\
2745 // Alpha stage 0 unused \n\
2746 AlphaOp[0] = SELECTARG1; \n\
2747 AlphaArg1[0] = TFACTOR; \n\
2748 AlphaOp[1] = SELECTARG1; \n\
2749 AlphaArg1[1] = TEXTURE; \n\
2750 } \n\
2751 pass p1 \n\
2752 { \n\
2753 FogColor = 0x00000000; // don't accumulate fog several times\n\
2754 Lighting = false; \n\
2755 DestBlend = one; \n\
2756 Texture[0] = <texture2>; \n\
2757 TextureFactor = <color2>; \n\
2758 ColorOp[0] = MODULATE; \n\
2759 } \n\
2760 pass p2 \n\
2761 { \n\
2762 Texture[0] = <texture3>; \n\
2763 TextureFactor = <color3>; \n\
2764 } \n\
2765 pass p3 \n\
2766 { \n\
2767 Texture[0] = <texture4>; \n\
2768 TextureFactor = <color4>; \n\
2769 } \n\
2770 } \n\
2776 static const char *Lightmap4_x2Fx =
2777 " \n\
2778 texture texture0; \n\
2779 texture texture1; \n\
2780 texture texture2; \n\
2781 texture texture3; \n\
2782 texture texture4; \n\
2783 // Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
2784 // Other colors are the lightmap Factors for each lightmap \n\
2785 dword color0; \n\
2786 dword color1; \n\
2787 dword color2; \n\
2788 dword color3; \n\
2789 dword color4; \n\
2790 float4 factor0; \n\
2791 float4 factor1; \n\
2792 float4 factor2; \n\
2793 float4 factor3; \n\
2794 float4 factor4; \n\
2796 float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
2797 // modulate the dyn light by 0.5, because of MODULATE2X \n\
2798 float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
2801 // **** 5 stages technique \n\
2802 pixelshader five_stages_ps = asm \n\
2803 { \n\
2804 ps_1_4; \n\
2805 texld r0, t0; \n\
2806 texld r1, t1; \n\
2807 texld r2, t2; \n\
2808 texld r3, t3; \n\
2809 texld r4, t4; \n\
2810 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2811 mad r1.xyz, c1, r1, v0; \n\
2812 mad r1.xyz, c2, r2, r1; \n\
2813 mad r1.xyz, c3, r3, r1; \n\
2814 mad r1.xyz, c4, r4, r1; \n\
2815 mul_x2 r0.xyz, r1, r0; \n\
2816 }; \n\
2818 technique five_stages_5 \n\
2819 { \n\
2820 pass p0 \n\
2821 { \n\
2822 TexCoordIndex[2] = 1; \n\
2823 TexCoordIndex[3] = 1; \n\
2824 TexCoordIndex[4] = 1; \n\
2826 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2827 Lighting = true; \n\
2828 MaterialEmissive= <factor0>; \n\
2829 MaterialAmbient= <g_black>; \n\
2830 MaterialDiffuse= <g_dyn_factor>; \n\
2831 MaterialSpecular= <g_black>; \n\
2832 AlphaBlendEnable = false; \n\
2834 Texture[0] = <texture0>; \n\
2835 Texture[1] = <texture1>; \n\
2836 Texture[2] = <texture2>; \n\
2837 Texture[3] = <texture3>; \n\
2838 Texture[4] = <texture4>; \n\
2839 PixelShaderConstant[1] = <factor1>; \n\
2840 PixelShaderConstant[2] = <factor2>; \n\
2841 PixelShaderConstant[3] = <factor3>; \n\
2842 PixelShaderConstant[4] = <factor4>; \n\
2843 PixelShader = (five_stages_ps); \n\
2844 } \n\
2845 } \n\
2847 // **** 4 stages technique \n\
2848 pixelshader four_stages_ps = asm \n\
2849 { \n\
2850 ps_1_1; \n\
2851 tex t0; \n\
2852 tex t1; \n\
2853 tex t2; \n\
2854 tex t3; \n\
2855 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2856 mad r0.xyz, c1, t1, v0; \n\
2857 mad r0.xyz, c2, t2, r0; \n\
2858 mad r0.xyz, c3, t3, r0; \n\
2859 mul_x2 r0.xyz, r0, t0; \n\
2860 +mov r0.w, t0; \n\
2861 }; \n\
2863 technique four_stages_4 \n\
2864 { \n\
2865 pass p0 \n\
2866 { \n\
2867 TexCoordIndex[2] = 1; \n\
2868 TexCoordIndex[3] = 1; \n\
2870 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2871 Lighting = true; \n\
2872 MaterialEmissive= <factor0>; \n\
2873 MaterialAmbient= <g_black>; \n\
2874 MaterialDiffuse= <g_dyn_factor>; \n\
2875 MaterialSpecular= <g_black>; \n\
2876 AlphaBlendEnable = false; \n\
2878 Texture[0] = <texture0>; \n\
2879 Texture[1] = <texture1>; \n\
2880 Texture[2] = <texture2>; \n\
2881 Texture[3] = <texture3>; \n\
2882 PixelShaderConstant[1] = <factor1>; \n\
2883 PixelShaderConstant[2] = <factor2>; \n\
2884 PixelShaderConstant[3] = <factor3>; \n\
2885 PixelShader = (four_stages_ps); \n\
2886 } \n\
2887 pass p1 \n\
2888 { \n\
2889 FogColor = 0x00000000; // don't accumulate fog several times\n\
2890 Lighting = false; \n\
2891 AlphaBlendEnable = true; \n\
2892 SrcBlend = one; \n\
2893 DestBlend = one; \n\
2895 // the DiffuseTexture texture 0 is in last stage \n\
2896 TexCoordIndex[0] = 1; \n\
2897 TexCoordIndex[1] = 0; \n\
2898 Texture[0] = <texture4>; \n\
2899 Texture[1] = <texture0>; \n\
2900 TextureFactor = <color4>; \n\
2901 ColorOp[0] = MODULATE; \n\
2902 ColorArg1[0] = TFACTOR; \n\
2903 ColorArg2[0] = TEXTURE; \n\
2904 ColorOp[1] = MODULATE2X; \n\
2905 ColorArg1[1] = CURRENT; \n\
2906 ColorArg2[1] = TEXTURE; \n\
2907 ColorOp[2] = DISABLE; \n\
2908 ColorOp[3] = DISABLE; \n\
2909 // Alpha stage 0 unused \n\
2910 AlphaOp[0] = SELECTARG1; \n\
2911 AlphaArg1[0] = TFACTOR; \n\
2912 AlphaOp[1] = SELECTARG1; \n\
2913 AlphaArg1[1] = TEXTURE; \n\
2914 AlphaOp[2] = DISABLE; \n\
2915 AlphaOp[3] = DISABLE; \n\
2916 PixelShader = NULL; \n\
2917 } \n\
2918 } \n\
2920 // **** 3 stages technique \n\
2921 pixelshader three_stages_0_ps = asm \n\
2922 { \n\
2923 ps_1_1; \n\
2924 tex t0; \n\
2925 tex t1; \n\
2926 tex t2; \n\
2927 // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
2928 mad r0.xyz, c1, t1, v0; \n\
2929 mad r0.xyz, c2, t2, r0; \n\
2930 mul_x2 r0.xyz, r0, t0; \n\
2931 +mov r0.w, t0; \n\
2932 }; \n\
2934 technique three_stages_3 \n\
2935 { \n\
2936 // 2 pass with the same pixel shader \n\
2937 pass p0 \n\
2938 { \n\
2939 TexCoordIndex[2] = 1; \n\
2941 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2942 Lighting = true; \n\
2943 MaterialEmissive= <factor0>; \n\
2944 MaterialAmbient= <g_black>; \n\
2945 MaterialDiffuse= <g_dyn_factor>; \n\
2946 MaterialSpecular= <g_black>; \n\
2947 AlphaBlendEnable = false; \n\
2949 Texture[0] = <texture0>; \n\
2950 Texture[1] = <texture1>; \n\
2951 Texture[2] = <texture2>; \n\
2952 PixelShaderConstant[1] = <factor1>; \n\
2953 PixelShaderConstant[2] = <factor2>; \n\
2954 PixelShader = (three_stages_0_ps); \n\
2955 } \n\
2956 pass p1 \n\
2957 { \n\
2958 FogColor = 0x00000000; // don't accumulate fog several times\n\
2959 // second pass: shut down all lighting (lmc ambient term and dynamic lighting already added in first pass)\n\
2960 MaterialEmissive= <g_black>; \n\
2961 MaterialDiffuse= <g_black>; \n\
2963 AlphaBlendEnable = true; \n\
2964 SrcBlend = one; \n\
2965 DestBlend = one; \n\
2966 Texture[1] = <texture3>; \n\
2967 Texture[2] = <texture4>; \n\
2968 PixelShaderConstant[1] = <factor3>; \n\
2969 PixelShaderConstant[2] = <factor4>; \n\
2970 } \n\
2971 } \n\
2973 // **** 2 stages, no pixel shader technique \n\
2974 technique two_stages_2 \n\
2975 { \n\
2976 pass p0 \n\
2977 { \n\
2978 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
2979 Lighting = true; \n\
2980 MaterialEmissive= <factor0>; \n\
2981 MaterialAmbient= <g_black>; \n\
2982 MaterialDiffuse= <g_dyn_factor>; \n\
2983 MaterialSpecular= <g_black>; \n\
2984 AlphaBlendEnable = false; \n\
2986 // the DiffuseTexture texture 0 is in last stage \n\
2987 TexCoordIndex[0] = 1; \n\
2988 TexCoordIndex[1] = 0; \n\
2989 Texture[0] = <texture1>; \n\
2990 Texture[1] = <texture0>; \n\
2991 TextureFactor = <color1>; \n\
2992 ColorOp[0] = MULTIPLYADD; \n\
2993 ColorArg0[0] = DIFFUSE; \n\
2994 ColorArg1[0] = TFACTOR; \n\
2995 ColorArg2[0] = TEXTURE; \n\
2996 ColorOp[1] = MODULATE2X; \n\
2997 ColorArg1[1] = CURRENT; \n\
2998 ColorArg2[1] = TEXTURE; \n\
2999 // Alpha stage 0 unused \n\
3000 AlphaOp[0] = SELECTARG1; \n\
3001 AlphaArg1[0] = TFACTOR; \n\
3002 AlphaOp[1] = SELECTARG1; \n\
3003 AlphaArg1[1] = TEXTURE; \n\
3004 } \n\
3005 pass p1 \n\
3006 { \n\
3007 FogColor = 0x00000000; // don't accumulate fog several times\n\
3008 Lighting = false; \n\
3009 AlphaBlendEnable = true; \n\
3010 SrcBlend = one; \n\
3011 DestBlend = one; \n\
3012 Texture[0] = <texture2>; \n\
3013 TextureFactor = <color2>; \n\
3014 ColorOp[0] = MODULATE; \n\
3015 } \n\
3016 pass p2 \n\
3017 { \n\
3018 Texture[0] = <texture3>; \n\
3019 TextureFactor = <color3>; \n\
3020 } \n\
3021 pass p3 \n\
3022 { \n\
3023 Texture[0] = <texture4>; \n\
3024 TextureFactor = <color4>; \n\
3025 } \n\
3026 } \n\
3031 static const char *Water_diffuseFx =
3032 " \n\
3033 texture texture0; // bumpmap0 \n\
3034 texture texture1; // bumpmap1 \n\
3035 texture texture2; // envmap \n\
3036 texture texture3; // diffuse \n\
3038 float4 factor0; // bumpmap0 scale \n\
3039 float4 factor1; // bumpmap1 scale \n\
3040 float scalarFloat0; // bump scale for 1_1 version \n\
3042 pixelshader water_diffuse_2_0 = asm \n\
3043 { \n\
3044 ps_2_0; \n\
3045 dcl t0.xy; \n\
3046 dcl t1.xy; \n\
3047 dcl t2.xy; \n\
3048 dcl t3.xy; \n\
3049 dcl_2d s0; \n\
3050 dcl_2d s1; \n\
3051 dcl_2d s2; \n\
3052 dcl_2d s3; \n\
3053 //read bump map 0 \n\
3054 texld r0, t0, s0; \n\
3055 //bias result (include scaling) \n\
3056 mad r0.xy, r0, c0.z, c0; \n\
3057 add r0.xy, r0, t1; \n\
3058 //read bump map 1 \n\
3059 texld r0, r0, s1; \n\
3060 //bias result (include scaling) \n\
3061 mad r0.xy, r0, c1.z, c1; \n\
3062 //add envmap coord \n\
3063 add r0.xy, r0, t2; \n\
3064 // read envmap \n\
3065 texld r0, r0, s2; \n\
3066 // read diffuse \n\
3067 texld r1, t3, s3; \n\
3068 mul r0, r0, r1; \n\
3069 mov oC0, r0 \n\
3070 }; \n\
3072 technique technique_water_diffuse_2_0 \n\
3073 { \n\
3074 pass p0 \n\
3075 { \n\
3076 Texture[0] = <texture0>; \n\
3077 Texture[1] = <texture1>; \n\
3078 Texture[2] = <texture2>; \n\
3079 Texture[3] = <texture3>; \n\
3080 PixelShaderConstant[0] = <factor0>; \n\
3081 PixelShaderConstant[1] = <factor1>; \n\
3082 PixelShader = (water_diffuse_2_0); \n\
3083 } \n\
3084 }; \n\
3086 pixelshader water_diffuse_1_4 = asm \n\
3087 { \n\
3088 ps_1_4; \n\
3089 texld r0, t0; \n\
3090 texld r1, t1; \n\
3091 texcrd r2.xyz, t2; \n\
3092 mad r2.xy, r0_bx2, c0, r2; \n\
3093 mad r2.xy, r1_bx2, c1, r2; \n\
3094 phase \n\
3095 texld r2, r2; \n\
3096 texld r3, t3; \n\
3097 mul r0, r2, r3; \n\
3098 }; \n\
3100 technique technique_water_diffuse_1_4 \n\
3101 { \n\
3102 pass p0 \n\
3103 { \n\
3104 Texture[0] = <texture0>; \n\
3105 Texture[1] = <texture1>; \n\
3106 Texture[2] = <texture2>; \n\
3107 Texture[3] = <texture3>; \n\
3108 PixelShaderConstant[0] = <factor0>; \n\
3109 PixelShaderConstant[1] = <factor1>; \n\
3110 PixelShader = (water_diffuse_1_4); \n\
3111 } \n\
3112 }; \n\
3114 pixelshader water_diffuse_1_1 = asm \n\
3115 { \n\
3116 // note in OpenGL on nVidia cards, it is permitted to chain 2 texbem so the effect is less nice there (no bumpmap animation)\n\
3117 ps_1_1; \n\
3118 tex t1; \n\
3119 texbem t2, t1; \n\
3120 tex t3; \n\
3121 mul r0, t3, t2; \n\
3122 }; \n\
3124 technique technique_water_diffuse_1_1 \n\
3125 { \n\
3126 pass p0 \n\
3127 { \n\
3128 Texture[1] = <texture1>; \n\
3129 Texture[2] = <texture2>; \n\
3130 Texture[3] = <texture3>; \n\
3131 PixelShaderConstant[0] = <factor0>; \n\
3132 PixelShaderConstant[1] = <factor1>; \n\
3133 PixelShader = (water_diffuse_1_1); \n\
3134 BumpEnvMat00[2] = <scalarFloat0>; \n\
3135 BumpEnvMat01[0] = 0; \n\
3136 BumpEnvMat10[0] = 0; \n\
3137 BumpEnvMat11[2] = <scalarFloat0>; \n\
3138 } \n\
3139 }; \n\
3143 static const char *Water_no_diffuseFx =
3144 " \n\
3145 texture texture0; // bumpmap0 \n\
3146 texture texture1; // bumpmap1 \n\
3147 texture texture2; // envmap \n\
3149 float4 factor0; // bumpmap0 scale \n\
3150 float4 factor1; // bumpmap1 scale \n\
3151 float scalarFloat0; // bump scale for 1_1 version \n\
3153 pixelshader water_no_diffuse_2_0 = asm \n\
3154 { \n\
3155 ps_2_0; \n\
3156 dcl t0.xy; \n\
3157 dcl t1.xy; \n\
3158 dcl t2.xy; \n\
3159 dcl_2d s0; \n\
3160 dcl_2d s1; \n\
3161 dcl_2d s2; \n\
3162 //read bump map 0 \n\
3163 texld r0, t0, s0; \n\
3164 //bias result (include scaling) \n\
3165 mad r0.xy, r0, c0.z, c0; \n\
3166 add r0.xy, r0, t1; \n\
3167 //read bump map 1 \n\
3168 texld r0, r0, s1; \n\
3169 //bias result (include scaling) \n\
3170 mad r0.xy, r0, c1.z, c1; \n\
3171 //add envmap coord \n\
3172 add r0.xy, r0, t2; \n\
3173 //read envmap \n\
3174 texld r0, r0, s2; \n\
3175 mov oC0, r0; \n\
3176 }; \n\
3178 technique technique_water_no_diffuse_2_0 \n\
3179 { \n\
3180 pass p0 \n\
3181 { \n\
3182 Texture[0] = <texture0>; \n\
3183 Texture[1] = <texture1>; \n\
3184 Texture[2] = <texture2>; \n\
3185 PixelShaderConstant[0] = <factor0>; \n\
3186 PixelShaderConstant[1] = <factor1>; \n\
3187 PixelShader = (water_no_diffuse_2_0); \n\
3188 } \n\
3189 }; \n\
3191 pixelshader water_no_diffuse_1_4 = asm \n\
3192 { \n\
3193 ps_1_4; \n\
3194 texld r0, t0; \n\
3195 texld r1, t1; \n\
3196 texcrd r2.xyz, t2; \n\
3197 mad r2.xy, r0_bx2, c0, r2; \n\
3198 mad r2.xy, r1_bx2, c1, r2; \n\
3199 phase \n\
3200 texld r2, r2; \n\
3201 mov r0, r2; \n\
3202 }; \n\
3204 technique technique_water_no_diffuse_1_4 \n\
3205 { \n\
3206 pass p0 \n\
3207 { \n\
3208 Texture[0] = <texture0>; \n\
3209 Texture[1] = <texture1>; \n\
3210 Texture[2] = <texture2>; \n\
3211 PixelShaderConstant[0] = <factor0>; \n\
3212 PixelShaderConstant[1] = <factor1>; \n\
3213 PixelShader = (water_no_diffuse_1_4); \n\
3214 } \n\
3215 }; \n\
3217 pixelshader water_no_diffuse_1_1 = asm \n\
3218 { \n\
3219 // note in OpenGL on nVidia cards, it is permitted to chain 2 texbem so the effect is less nice there (no bumpmap animation)\n\
3220 ps_1_1; \n\
3221 tex t1; \n\
3222 texbem t2, t1; \n\
3223 mov r0, t2; \n\
3224 }; \n\
3226 technique technique_water_no_diffuse_1_1 \n\
3227 { \n\
3228 pass p0 \n\
3229 { \n\
3230 Texture[1] = <texture1>; \n\
3231 Texture[2] = <texture2>; \n\
3232 PixelShaderConstant[0] = <factor0>; \n\
3233 PixelShaderConstant[1] = <factor1>; \n\
3234 PixelShader = (water_no_diffuse_1_1); \n\
3235 BumpEnvMat00[2] = <scalarFloat0>; \n\
3236 BumpEnvMat01[0] = 0; \n\
3237 BumpEnvMat10[0] = 0; \n\
3238 BumpEnvMat11[2] = <scalarFloat0>; \n\
3239 } \n\
3240 }; \n\
3246 void CDriverD3D::initInternalShaders()
3248 H_AUTO_D3D(CDriverD3D_initInternalShaders)
3249 setFx(_ShaderLightmap0,"lightmap0Fx", Lightmap0Fx);
3250 setFx(_ShaderLightmap1,"lightmap1Fx", Lightmap1Fx);
3251 setFx(_ShaderLightmap2,"lightmap2Fx", Lightmap2Fx);
3252 setFx(_ShaderLightmap3,"lightmap3Fx", Lightmap3Fx);
3253 setFx(_ShaderLightmap4,"lightmap4Fx", Lightmap4Fx);
3254 setFx(_ShaderLightmap0Blend,"lightmap0blendFx", Lightmap0blendFx);
3255 setFx(_ShaderLightmap1Blend,"lightmap1blendFx", Lightmap1blendFx);
3256 setFx(_ShaderLightmap2Blend,"lightmap2blendFx", Lightmap2blendFx);
3257 setFx(_ShaderLightmap3Blend,"lightmap3blendFx", Lightmap3blendFx);
3258 setFx(_ShaderLightmap4Blend,"lightmap4blendFx", Lightmap4blendFx);
3259 setFx(_ShaderLightmap0X2,"lightmap0_x2Fx", Lightmap0_x2Fx);
3260 setFx(_ShaderLightmap1X2,"lightmap1_x2Fx", Lightmap1_x2Fx);
3261 setFx(_ShaderLightmap2X2,"lightmap2_x2Fx", Lightmap2_x2Fx);
3262 setFx(_ShaderLightmap3X2,"lightmap3_x2Fx", Lightmap3_x2Fx);
3263 setFx(_ShaderLightmap4X2,"lightmap4_x2Fx", Lightmap4_x2Fx);
3264 setFx(_ShaderLightmap0BlendX2,"lightmap0blend_x2Fx", Lightmap0blend_x2Fx);
3265 setFx(_ShaderLightmap1BlendX2,"lightmap1blend_x2Fx", Lightmap1blend_x2Fx);
3266 setFx(_ShaderLightmap2BlendX2,"lightmap2blend_x2Fx", Lightmap2blend_x2Fx);
3267 setFx(_ShaderLightmap3BlendX2,"lightmap3blend_x2Fx", Lightmap3blend_x2Fx);
3268 setFx(_ShaderLightmap4BlendX2,"lightmap4blend_x2Fx", Lightmap4blend_x2Fx);
3269 setFx(_ShaderCloud, "cloudFx", CloudFx);
3270 setFx(_ShaderWaterNoDiffuse,"water_no_diffuseFx", Water_no_diffuseFx);
3271 setFx(_ShaderWaterDiffuse, "water_diffuseFx", Water_diffuseFx);
3275 // ***************************************************************************
3277 void CDriverD3D::releaseInternalShaders()
3279 H_AUTO_D3D(CDriverD3D_releaseInternalShaders)
3280 _ShaderLightmap0._DrvInfo.kill();
3281 _ShaderLightmap1._DrvInfo.kill();
3282 _ShaderLightmap2._DrvInfo.kill();
3283 _ShaderLightmap3._DrvInfo.kill();
3284 _ShaderLightmap4._DrvInfo.kill();
3285 _ShaderLightmap0Blend._DrvInfo.kill();
3286 _ShaderLightmap1Blend._DrvInfo.kill();
3287 _ShaderLightmap2Blend._DrvInfo.kill();
3288 _ShaderLightmap3Blend._DrvInfo.kill();
3289 _ShaderLightmap4Blend._DrvInfo.kill();
3290 _ShaderLightmap0X2._DrvInfo.kill();
3291 _ShaderLightmap1X2._DrvInfo.kill();
3292 _ShaderLightmap2X2._DrvInfo.kill();
3293 _ShaderLightmap3X2._DrvInfo.kill();
3294 _ShaderLightmap4X2._DrvInfo.kill();
3295 _ShaderLightmap0BlendX2._DrvInfo.kill();
3296 _ShaderLightmap1BlendX2._DrvInfo.kill();
3297 _ShaderLightmap2BlendX2._DrvInfo.kill();
3298 _ShaderLightmap3BlendX2._DrvInfo.kill();
3299 _ShaderLightmap4BlendX2._DrvInfo.kill();
3300 _ShaderCloud._DrvInfo.kill();
3301 _ShaderWaterNoDiffuse._DrvInfo.kill();
3302 _ShaderWaterDiffuse._DrvInfo.kill();
3305 // ***************************************************************************
3306 bool CDriverD3D::setShaderTexture (uint textureHandle, ITexture *texture, CFXCache *cache)
3308 H_AUTO_D3D(CDriverD3D_setShaderTexture )
3309 // Setup the texture
3310 if (!setupTexture(*texture))
3311 return false;
3313 // Set the main texture
3314 nlassert (_CurrentShader);
3315 CShaderDrvInfosD3D *shaderInfo = static_cast<CShaderDrvInfosD3D*>((IShaderDrvInfos*)_CurrentShader->_DrvInfo);
3316 nlassert (shaderInfo);
3317 ID3DXEffect *effect = shaderInfo->Effect;
3318 CTextureDrvInfosD3D *d3dtext = getTextureD3D (*texture);
3319 if (texture)
3321 if (cache)
3323 cache->Params.setTexture(textureHandle, d3dtext->Texture);
3325 else
3327 effect->SetTexture (shaderInfo->TextureHandle[textureHandle], d3dtext->Texture);
3332 // Add a ref on this texture
3333 _CurrentShaderTextures.push_back (CTextureRef());
3334 CTextureRef &ref = _CurrentShaderTextures.back();
3335 ref.NeLTexture = texture;
3336 ref.D3DTexture = d3dtext->Texture;
3337 return true;
3340 // ***************************************************************************
3342 void CDriverD3D::disableHardwareTextureShader()
3344 // cannot disable pixel shader under DX, because it crashes with lightmap
3345 // => no-op
3347 _DisableHardwarePixelShader = true;
3348 _PixelShader = false;
3354 // ***************************************************************************
3355 void CDriverD3D::notifyAllShaderDrvOfLostDevice()
3357 for(TShaderDrvInfoPtrList::iterator it = _ShaderDrvInfos.begin(); it != _ShaderDrvInfos.end(); ++it)
3359 nlassert(*it);
3360 CShaderDrvInfosD3D *drvInfo = NLMISC::safe_cast<CShaderDrvInfosD3D *>(*it);
3361 if (drvInfo->Effect)
3363 nlverify(drvInfo->Effect->OnLostDevice() == D3D_OK);
3368 // ***************************************************************************
3369 void CDriverD3D::notifyAllShaderDrvOfResetDevice()
3371 for(TShaderDrvInfoPtrList::iterator it = _ShaderDrvInfos.begin(); it != _ShaderDrvInfos.end(); ++it)
3373 nlassert(*it);
3374 CShaderDrvInfosD3D *drvInfo = NLMISC::safe_cast<CShaderDrvInfosD3D *>(*it);
3375 if (drvInfo->Effect)
3377 //nlverify(
3378 drvInfo->Effect->OnResetDevice();
3379 //== D3D_OK);
3385 // ***************************************************************************
3386 // state records (for .fx caching)
3387 // ***************************************************************************
3389 class CStateRecordLightEnable : public CStateRecord
3391 public:
3392 DWORD Index;
3393 BOOL Enable;
3394 public:
3395 CStateRecordLightEnable(DWORD index, BOOL enable) : Index(index), Enable(enable) {}
3396 virtual void apply(class CDriverD3D &drv)
3398 drv.enableLight ((uint8)Index, Enable!=FALSE);
3402 class CStateRecordLight : public CStateRecord
3404 public:
3405 DWORD Index;
3406 D3DLIGHT9 Light;
3407 public:
3408 CStateRecordLight(DWORD index, const D3DLIGHT9 *pLight) : Index(index), Light(*pLight) {}
3409 virtual void apply(class CDriverD3D &drv)
3411 drv._LightCache[Index].Light = Light;
3412 drv.touchRenderVariable (&drv._LightCache[Index]);
3416 class CStateRecordMaterial : public CStateRecord
3418 public:
3419 D3DMATERIAL9 Material;
3420 public:
3421 CStateRecordMaterial(const D3DMATERIAL9 *pMaterial) : Material(*pMaterial) {}
3422 virtual void apply(class CDriverD3D &drv)
3424 drv.setMaterialState(Material);
3428 class CStateRecordPixelShader : public CStateRecord
3430 public:
3431 LPDIRECT3DPIXELSHADER9 PixelShader;
3432 public:
3433 CStateRecordPixelShader(LPDIRECT3DPIXELSHADER9 pixelShader) : PixelShader(pixelShader) {}
3434 virtual void apply(class CDriverD3D &drv)
3436 drv.setPixelShader(PixelShader);
3440 class CStateRecordPixelShaderConstantB : public CStateRecord
3442 public:
3443 std::vector<BOOL> Values;
3444 uint StartRegister;
3445 public:
3446 CStateRecordPixelShaderConstantB(DWORD startRegister, const BOOL *values, DWORD countVec4) : StartRegister(startRegister)
3448 Values.resize(countVec4 * 4);
3449 std::copy(values, values + countVec4 * 4, Values.begin());
3451 virtual void apply(class CDriverD3D &drv)
3453 const BOOL *curr = &Values[0];
3454 const BOOL *last = &Values[0] + Values.size();
3455 uint i = StartRegister;
3456 while (curr != last)
3458 drv.setPixelShaderConstant (i, curr);
3459 curr += 4;
3460 ++ i;
3465 class CStateRecordPixelShaderConstantF : public CStateRecord
3467 public:
3468 std::vector<FLOAT> Values;
3469 uint StartRegister;
3470 public:
3471 CStateRecordPixelShaderConstantF(DWORD startRegister, const FLOAT *values, DWORD countVec4) : StartRegister(startRegister)
3473 Values.resize(countVec4 * 4);
3474 std::copy(values, values + countVec4 * 4, Values.begin());
3476 virtual void apply(class CDriverD3D &drv)
3478 const FLOAT *curr = &Values[0];
3479 const FLOAT *last = &Values[0] + Values.size();
3480 uint i = StartRegister;
3481 while (curr != last)
3483 drv.setPixelShaderConstant (i, curr);
3484 curr += 4;
3485 ++ i;
3490 class CStateRecordPixelShaderConstantI : public CStateRecord
3492 public:
3493 std::vector<INT> Values;
3494 uint StartRegister;
3495 public:
3496 CStateRecordPixelShaderConstantI(DWORD startRegister, const INT *values, DWORD countVec4) : StartRegister(startRegister)
3498 Values.resize(countVec4 * 4);
3499 std::copy(values, values + countVec4 * 4, Values.begin());
3501 virtual void apply(class CDriverD3D &drv)
3503 const INT *curr = &Values[0];
3504 const INT *last = &Values[0] + Values.size();
3505 uint i = StartRegister;
3506 while (curr != last)
3508 drv.setPixelShaderConstant (i, curr);
3509 curr += 4;
3510 ++ i;
3515 class CStateRecordRenderState : public CStateRecord
3517 public:
3518 D3DRENDERSTATETYPE State;
3519 DWORD Value;
3520 public:
3521 CStateRecordRenderState(D3DRENDERSTATETYPE state, DWORD value) : State(state), Value(value) {}
3522 virtual void apply(class CDriverD3D &drv)
3524 drv.setRenderState(State, Value);
3528 class CStateRecordSamplerState : public CStateRecord
3530 public:
3531 DWORD Sampler;
3532 D3DSAMPLERSTATETYPE Type;
3533 DWORD Value;
3534 public:
3535 CStateRecordSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value) : Sampler(sampler), Type(type), Value(value) {}
3536 virtual void apply(class CDriverD3D &drv)
3538 drv.setSamplerState(Sampler, Type, Value);
3542 class CStateRecordTexture : public CStateRecord
3544 public:
3545 DWORD Stage;
3546 CRefPtr<ITexture> TexRef;
3547 LPDIRECT3DBASETEXTURE9 Texture;
3548 BOOL IsNelTexture;
3549 public:
3550 CStateRecordTexture(DWORD stage, LPDIRECT3DBASETEXTURE9 texture, ITexture *nelTexture) : Stage(stage), Texture(texture)
3552 nlassert(Texture);
3553 H_AUTO_D3D(CDriverD3D_SetTexture )
3554 // if not a NeL texture, should add a reference on texture, else use refptr instead
3555 IsNelTexture = nelTexture != NULL;
3556 TexRef = nelTexture;
3557 if (!IsNelTexture)
3559 HRESULT r = Texture->AddRef();
3560 nlassert(r == D3D_OK);
3563 ~CStateRecordTexture()
3565 nlassert(Texture); // no default ctor, so texture should have been set
3566 if (!IsNelTexture)
3568 nlassert(TexRef == NULL);
3569 HRESULT r = Texture->Release();
3570 nlassert(r == D3D_OK);
3573 virtual void apply(class CDriverD3D &drv)
3575 nlassert(Texture);
3576 if (TexRef)
3578 drv.setTexture(Stage, TexRef);
3580 else
3582 drv.setTexture(Stage, Texture);
3587 class CStateRecordTextureStageState : public CStateRecord
3589 public:
3590 DWORD Stage;
3591 D3DTEXTURESTAGESTATETYPE Type;
3592 DWORD Value;
3593 public:
3594 CStateRecordTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value) : Stage(stage), Type(type), Value(value) {}
3595 virtual void apply(class CDriverD3D &drv)
3597 if (Type == D3DTSS_TEXCOORDINDEX)
3598 drv.setTextureIndexUV (Stage, Value);
3599 else
3600 drv.setTextureState (Stage, Type, Value);
3604 class CStateRecordTransform : public CStateRecord
3606 public:
3607 D3DTRANSFORMSTATETYPE State;
3608 D3DMATRIX Matrix;
3609 public:
3610 CStateRecordTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *pMatrix) : State(state), Matrix(*pMatrix) {}
3611 virtual void apply(class CDriverD3D &drv)
3613 drv.setMatrix(State, Matrix);
3617 class CStateRecordVertexShader : public CStateRecord
3619 public:
3620 LPDIRECT3DVERTEXSHADER9 Shader;
3621 public:
3622 CStateRecordVertexShader(LPDIRECT3DVERTEXSHADER9 shader) : Shader(shader) {}
3623 virtual void apply(class CDriverD3D &/* drv */)
3625 nlassert(0); // not supported
3626 //drv.setVertexProgram(Shader);
3630 class CStateRecordVertexShaderConstantB : public CStateRecord
3632 public:
3633 std::vector<BOOL> Values;
3634 uint StartRegister;
3635 public:
3636 CStateRecordVertexShaderConstantB(DWORD startRegister, const BOOL *values, DWORD countVec4) : StartRegister(startRegister)
3638 Values.resize(countVec4 * 4);
3639 std::copy(values, values + countVec4 * 4, Values.begin());
3641 virtual void apply(class CDriverD3D &drv)
3643 const BOOL *curr = &Values[0];
3644 const BOOL *last = &Values[0] + Values.size();
3645 uint i = StartRegister;
3646 while (curr != last)
3648 drv.setVertexProgramConstant(i, curr);
3649 curr += 4;
3650 ++ i;
3654 class CStateRecordVertexShaderConstantF : public CStateRecord
3656 public:
3657 std::vector<FLOAT> Values;
3658 uint StartRegister;
3659 public:
3660 CStateRecordVertexShaderConstantF(DWORD startRegister, const FLOAT *values, DWORD countVec4) : StartRegister(startRegister)
3662 Values.resize(countVec4 * 4);
3663 std::copy(values, values + countVec4 * 4, Values.begin());
3665 virtual void apply(class CDriverD3D &drv)
3667 const FLOAT *curr = &Values[0];
3668 const FLOAT *last = &Values[0] + Values.size();
3669 uint i = StartRegister;
3670 while (curr != last)
3672 drv.setVertexProgramConstant(i, curr);
3673 curr += 4;
3674 ++ i;
3678 class CStateRecordVertexShaderConstantI : public CStateRecord
3680 public:
3681 std::vector<INT> Values;
3682 uint StartRegister;
3683 public:
3684 CStateRecordVertexShaderConstantI(DWORD startRegister, const INT *values, DWORD countVec4) : StartRegister(startRegister)
3686 Values.resize(countVec4 * 4);
3687 std::copy(values, values + countVec4 * 4, Values.begin());
3689 virtual void apply(class CDriverD3D &drv)
3691 const INT *curr = &Values[0];
3692 const INT *last = &Values[0] + Values.size();
3693 uint i = StartRegister;
3694 while (curr != last)
3696 drv.setVertexProgramConstant(i, curr);
3697 curr += 4;
3698 ++ i;
3703 // state recorder
3704 HRESULT STDMETHODCALLTYPE CFXPassRecorder::QueryInterface(REFIID riid, LPVOID *ppvObj)
3706 nlassert(Driver);
3707 return Driver->QueryInterface(riid, ppvObj);
3710 ULONG STDMETHODCALLTYPE CFXPassRecorder::AddRef(VOID)
3712 nlassert(Driver);
3713 return Driver->AddRef();
3716 ULONG STDMETHODCALLTYPE CFXPassRecorder::Release(VOID)
3718 nlassert(Driver);
3719 return Driver->Release();
3722 HRESULT STDMETHODCALLTYPE CFXPassRecorder::LightEnable(DWORD Index, BOOL Enable)
3724 nlassert(Driver);
3725 nlassert(Target);
3726 Target->States.push_back(new CStateRecordLightEnable(Index, Enable));
3727 return D3D_OK;
3730 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetFVF(DWORD /* FVF */)
3732 nlassert(0); // not managed
3733 return D3D_OK;
3736 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetLight(DWORD Index, CONST D3DLIGHT9* pLight)
3738 nlassert(Driver);
3739 nlassert(Target);
3740 Target->States.push_back(new CStateRecordLight(Index, pLight));
3741 return D3D_OK;
3744 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetMaterial(CONST D3DMATERIAL9* pMaterial)
3746 nlassert(Driver);
3747 nlassert(Target);
3748 Target->States.push_back(new CStateRecordMaterial(pMaterial));
3749 return D3D_OK;
3752 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetNPatchMode(FLOAT /* nSegments */)
3754 nlassert(0); // not managed
3755 return D3D_OK;
3758 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader)
3760 nlassert(Driver);
3761 nlassert(Target);
3762 Target->States.push_back(new CStateRecordPixelShader(pShader));
3763 return D3D_OK;
3766 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetPixelShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount)
3768 nlassert(Driver);
3769 nlassert(Target);
3770 Target->States.push_back(new CStateRecordPixelShaderConstantB(StartRegister, pConstantData, RegisterCount));
3771 return D3D_OK;
3774 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetPixelShaderConstantF(UINT StartRegister, CONST FLOAT* pConstantData, UINT RegisterCount)
3776 nlassert(Driver);
3777 nlassert(Target);
3778 Target->States.push_back(new CStateRecordPixelShaderConstantF(StartRegister, pConstantData, RegisterCount));
3779 return D3D_OK;
3782 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetPixelShaderConstantI(UINT StartRegister, CONST INT* pConstantData, UINT RegisterCount)
3784 nlassert(Driver);
3785 nlassert(Target);
3786 Target->States.push_back(new CStateRecordPixelShaderConstantI(StartRegister, pConstantData, RegisterCount));
3787 return D3D_OK;
3790 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetRenderState(D3DRENDERSTATETYPE State, DWORD Value)
3792 nlassert(Driver);
3793 nlassert(Target);
3794 Target->States.push_back(new CStateRecordRenderState(State, Value));
3795 return D3D_OK;
3798 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
3800 nlassert(Driver);
3801 nlassert(Target);
3802 Target->States.push_back(new CStateRecordSamplerState(Sampler, Type, Value));
3803 return D3D_OK;
3806 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetTexture(DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture)
3808 nlassert(Driver);
3809 nlassert(Target);
3810 // Look for the current texture
3811 uint i;
3812 const uint count = (uint)Driver->getCurrentShaderTextures().size();
3813 for (i=0; i<count; i++)
3815 const CDriverD3D::CTextureRef &ref = Driver->getCurrentShaderTextures()[i];
3816 if (ref.D3DTexture == pTexture)
3818 // Set the additionnal stage set by NeL texture (D3DSAMP_ADDRESSU, D3DSAMP_ADDRESSV, D3DSAMP_MAGFILTER, D3DSAMP_MINFILTER and D3DSAMP_MIPFILTER)
3819 Target->States.push_back(new CStateRecordTexture(Stage, pTexture, ref.NeLTexture));
3820 break;
3823 if (i == count)
3825 // The texture isn't a NeL texture (was created inside driver)
3826 Target->States.push_back(new CStateRecordTexture(Stage, pTexture, NULL));
3828 return D3D_OK;
3832 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
3834 nlassert(Driver);
3835 nlassert(Target);
3836 Target->States.push_back(new CStateRecordTextureStageState(Stage, Type, Value));
3837 return D3D_OK;
3840 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix)
3842 nlassert(Driver);
3843 nlassert(Target);
3844 Target->States.push_back(new CStateRecordTransform(State, pMatrix));
3845 return D3D_OK;
3848 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetVertexShader(LPDIRECT3DVERTEXSHADER9 pShader)
3850 nlassert(Driver);
3851 nlassert(Target);
3852 Target->States.push_back(new CStateRecordVertexShader(pShader));
3853 return D3D_OK;
3856 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetVertexShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount)
3858 nlassert(Driver);
3859 nlassert(Target);
3860 Target->States.push_back(new CStateRecordVertexShaderConstantB(StartRegister, pConstantData, RegisterCount));
3861 return D3D_OK;
3864 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetVertexShaderConstantF(UINT StartRegister, CONST FLOAT* pConstantData, UINT RegisterCount)
3866 nlassert(Driver);
3867 nlassert(Target);
3868 Target->States.push_back(new CStateRecordVertexShaderConstantF(StartRegister, pConstantData, RegisterCount));
3869 return D3D_OK;
3872 HRESULT STDMETHODCALLTYPE CFXPassRecorder::SetVertexShaderConstantI(UINT StartRegister, CONST INT* pConstantData, UINT RegisterCount)
3874 nlassert(Driver);
3875 nlassert(Target);
3876 Target->States.push_back(new CStateRecordVertexShaderConstantI(StartRegister, pConstantData, RegisterCount));
3877 return D3D_OK;
3880 //===================================================================================
3881 CFXPassRecord::~CFXPassRecord()
3883 for(std::vector<CStateRecord *>::iterator it = States.begin(); it != States.end(); ++it)
3885 delete *it;
3889 void CFXPassRecord::apply(CDriverD3D &drv)
3891 for(std::vector<CStateRecord *>::iterator it = States.begin(); it != States.end(); ++it)
3893 (*it)->apply(drv);
3897 const uint NL_D3D_NUM_RENDER_FOR_FX_CACHING = 4;
3899 //===================================================================================
3900 void CFXCache::setConstants(CShaderDrvInfosD3D *si)
3902 nlassert(si);
3903 nlassert(si->Effect);
3904 for(uint k = 0; k < CFXInputParams::MaxNumParams; ++k)
3906 if (Params.Textures[k].Set) si->Effect->SetTexture(si->TextureHandle[k], Params.Textures[k].Value);
3907 if (Params.Vectors[k].Set) si->Effect->SetFloatArray(si->FactorHandle[k], (CONST FLOAT *) &(Params.Vectors[k].Value), 4);
3908 if (Params.Colors[k].Set) si->Effect->SetInt(si->ColorHandle[k], Params.Colors[k].Value);
3909 if (Params.Floats[k].Set) si->Effect->SetFloat(si->ScalarFloatHandle[k], Params.Floats[k].Value);
3913 void CFXCache::begin(CShaderDrvInfosD3D *si, CDriverD3D *driver)
3915 nlassert(driver);
3916 // amortize cost of caching for animated material -> ensure that the parameters don't change for
3917 // a few number of display before doing caching
3918 if (Params.Touched)
3920 Steadyness = 0;
3921 Passes.clear();
3922 NumPasses = 0;
3923 Params.Touched = false;
3924 return;
3926 if (!Params.Touched)
3928 ++ Steadyness;
3930 if (Steadyness < NL_D3D_NUM_RENDER_FOR_FX_CACHING)
3932 NumPasses = 0;
3933 Passes.clear();
3934 return;
3936 if (Passes.empty()) // must record shader ?
3938 Passes.clear();
3939 UINT numPasses;
3940 CFXPassRecorder pr;
3941 pr.Driver = driver;
3942 si->Effect->SetStateManager(&pr);
3943 // Set constants
3944 setConstants(si);
3946 HRESULT r = si->Effect->Begin(&numPasses, D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESHADERSTATE);
3947 nlassert(r == D3D_OK);
3948 Passes.resize(numPasses);
3949 for(uint k = 0; k < numPasses; ++k)
3951 pr.Target = &Passes[k];
3952 #if (DIRECT3D_VERSION >= 0x0900) && (D3D_SDK_VERSION >= 32)
3953 si->Effect->BeginPass(k);
3954 si->Effect->EndPass();
3955 #else
3956 si->Effect->Pass(k);
3957 #endif
3959 r = si->Effect->End();
3960 nlassert(r == D3D_OK);
3961 NumPasses = numPasses;
3962 si->Effect->SetStateManager(driver);
3966 void CFXCache::applyPass(class CDriverD3D &drv, CShaderDrvInfosD3D *si, uint passIndex)
3968 if (Passes.empty() && NumPasses == 0)
3970 // the shader has not been cached yet (maybe animated)
3971 // so uses the standard path
3972 UINT numPasses;
3973 setConstants(si);
3974 HRESULT r = si->Effect->Begin(&numPasses, D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESHADERSTATE);
3975 nlassert(r == D3D_OK);
3976 NumPasses = numPasses;
3978 nlassert(passIndex < NumPasses);
3979 if (Passes.empty())
3981 #if (DIRECT3D_VERSION >= 0x0900) && (D3D_SDK_VERSION >= 32)
3982 HRESULT r = si->Effect->BeginPass(passIndex);
3983 si->Effect->EndPass ();
3984 #else
3985 HRESULT r = si->Effect->Pass(passIndex);
3986 #endif
3987 nlassert(r == D3D_OK);
3989 else
3991 Passes[passIndex].apply(drv);
3995 void CFXCache::end(CShaderDrvInfosD3D *si)
3997 if (Passes.empty())
3999 HRESULT r = si->Effect->End();
4000 nlassert(r == D3D_OK);
4005 void CFXCache::reset()
4007 Params.reset();
4008 Passes.clear();
4009 Steadyness = 0;
4014 } // NL3D