1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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"
31 using namespace NLMISC
;
37 // ***************************************************************************
39 CD3DShaderFX::~CD3DShaderFX()
41 // Must kill the drv mirror of this shader.
45 // ***************************************************************************
47 CD3DShaderFX::CD3DShaderFX()
49 _ShaderChanged
= true;
52 // ***************************************************************************
54 void CD3DShaderFX::setText (const char *text
)
57 _ShaderChanged
= true;
60 // ***************************************************************************
62 void CD3DShaderFX::setName (const char *name
)
65 _ShaderChanged
= true;
68 // ***************************************************************************
70 bool CD3DShaderFX::loadShaderFile (const char *filename
)
74 string _filename
= NLMISC::CPath::lookup(filename
, false, true, true);
75 if (!_filename
.empty())
78 uint size
= NLMISC::CFile::getFileSize (_filename
);
79 _Text
.reserve (size
+1);
84 if (file
.open (_filename
))
90 file
.getline (line
, 512);
94 // Set the shader name
95 _Name
= NLMISC::CFile::getFilename (filename
);
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());
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
)
137 // ***************************************************************************
139 ULONG
CDriverD3D::AddRef(VOID
)
141 H_AUTO_D3D(CDriverD3D_AddRef
)
145 // ***************************************************************************
147 ULONG
CDriverD3D::Release(VOID
)
149 H_AUTO_D3D(CDriverD3D_Release
)
153 // ***************************************************************************
155 HRESULT
CDriverD3D::LightEnable(DWORD Index
, BOOL Enable
)
157 H_AUTO_D3D(CDriverD3D_LightEnable
)
158 enableLight ((uint8
)Index
, Enable
!=FALSE
);
162 // ***************************************************************************
164 HRESULT
CDriverD3D::SetFVF(DWORD
/* FVF */)
166 H_AUTO_D3D(CDriverD3D_SetFVF
)
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
]);
181 // ***************************************************************************
183 HRESULT
CDriverD3D::SetMaterial(CONST D3DMATERIAL9
* pMaterial
)
185 H_AUTO_D3D(CDriverD3D_SetMaterial
)
186 setMaterialState( *pMaterial
);
190 // ***************************************************************************
192 HRESULT
CDriverD3D::SetNPatchMode(FLOAT
/* nSegments */)
194 H_AUTO_D3D(CDriverD3D_SetNPatchMode
)
199 // ***************************************************************************
201 HRESULT
CDriverD3D::SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader
)
203 H_AUTO_D3D(CDriverD3D_SetPixelShader
)
204 setPixelShader (pShader
);
208 // ***************************************************************************
210 HRESULT
CDriverD3D::SetPixelShaderConstantB(UINT StartRegister
, CONST BOOL
* pConstantData
, UINT RegisterCount
)
212 H_AUTO_D3D(CDriverD3D_SetPixelShaderConstantB
)
214 for (i
=0; i
<RegisterCount
; i
++)
215 setPixelShaderConstant (i
+StartRegister
, (int*)(pConstantData
+i
*4));
219 // ***************************************************************************
221 HRESULT
CDriverD3D::SetPixelShaderConstantF(UINT StartRegister
, CONST FLOAT
* pConstantData
, UINT RegisterCount
)
223 H_AUTO_D3D(CDriverD3D_SetPixelShaderConstantF
)
225 for (i
=0; i
<RegisterCount
; i
++)
226 setPixelShaderConstant (i
+StartRegister
, pConstantData
+i
*4);
230 // ***************************************************************************
232 HRESULT
CDriverD3D::SetPixelShaderConstantI(UINT StartRegister
, CONST INT
* pConstantData
, UINT RegisterCount
)
234 H_AUTO_D3D(CDriverD3D_SetPixelShaderConstantI
)
236 for (i
=0; i
<RegisterCount
; i
++)
237 setPixelShaderConstant (i
+StartRegister
, pConstantData
+i
*4);
241 // ***************************************************************************
243 HRESULT
CDriverD3D::SetRenderState(D3DRENDERSTATETYPE State
, DWORD Value
)
245 H_AUTO_D3D(CDriverD3D_SetRenderState
)
246 setRenderState (State
, Value
);
250 // ***************************************************************************
252 HRESULT
CDriverD3D::SetSamplerState(DWORD Sampler
, D3DSAMPLERSTATETYPE Type
, DWORD Value
)
254 H_AUTO_D3D(CDriverD3D_SetSamplerState
)
255 setSamplerState (Sampler
, Type
, Value
);
259 // ***************************************************************************
261 HRESULT
CDriverD3D::SetTexture (DWORD Stage
, LPDIRECT3DBASETEXTURE9 pTexture
)
263 H_AUTO_D3D(CDriverD3D_SetTexture
)
264 // Look for the current texture
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
);
278 setTexture (Stage
, pTexture
);
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
);
291 setTextureState (Stage
, Type
, Value
);
295 // ***************************************************************************
297 HRESULT
CDriverD3D::SetTransform(D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* pMatrix
)
299 H_AUTO_D3D(CDriverD3D_SetTransform
)
300 setMatrix (State
, *pMatrix
);
304 // ***************************************************************************
306 HRESULT
CDriverD3D::SetVertexShader(LPDIRECT3DVERTEXSHADER9 pShader
)
308 H_AUTO_D3D(CDriverD3D_SetVertexShader
)
309 setVertexProgram (pShader
, NULL
);
313 // ***************************************************************************
315 HRESULT
CDriverD3D::SetVertexShaderConstantB(UINT StartRegister
, CONST BOOL
* pConstantData
, UINT RegisterCount
)
317 H_AUTO_D3D(CDriverD3D_SetVertexShaderConstantB
)
319 for (i
=0; i
<RegisterCount
; i
++)
320 setVertexProgramConstant (i
+StartRegister
, (int*)(pConstantData
+i
*4));
324 // ***************************************************************************
326 HRESULT
CDriverD3D::SetVertexShaderConstantF(UINT StartRegister
, CONST FLOAT
* pConstantData
, UINT RegisterCount
)
328 H_AUTO_D3D(CDriverD3D_SetVertexShaderConstantF
)
330 for (i
=0; i
<RegisterCount
; i
++)
331 setVertexProgramConstant (i
+StartRegister
, pConstantData
+i
*4);
335 // ***************************************************************************
337 HRESULT
CDriverD3D::SetVertexShaderConstantI(UINT StartRegister
, CONST INT
* pConstantData
, UINT RegisterCount
)
339 H_AUTO_D3D(CDriverD3D_SetVertexShaderConstantI
)
341 for (i
=0; i
<RegisterCount
; i
++)
342 setVertexProgramConstant (i
+StartRegister
, pConstantData
+i
*4);
346 // ***************************************************************************
348 CShaderDrvInfosD3D::CShaderDrvInfosD3D(CDriverD3D
*drv
, ItShaderDrvInfoPtrList it
) : IShaderDrvInfos(drv
, it
)
350 H_AUTO_D3D(CShaderDrvInfosD3D_CShaderDrvInfosD3D
)
354 // ***************************************************************************
356 CShaderDrvInfosD3D::~CShaderDrvInfosD3D()
358 H_AUTO_D3D(CShaderDrvInfosD3D_CShaderDrvInfosD3DDtor
)
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
)
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
);
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
405 D3DXTECHNIQUE_DESC desc
;
406 nlverify (shaderInfo
->Effect
->GetTechniqueDesc(hCurrentTechnique
, &desc
) == D3D_OK
);
408 nlinfo ("Shader \"%s\" : use technique \"%s\" with %d passes.", shader
->getName(), desc
.Name
, desc
.Passes
);
410 #endif // NL_DEBUG_D3D
414 shaderInfo
->Effect
->SetTechnique(hTechnique
);
416 // Set the state manager
417 shaderInfo
->Effect
->SetStateManager (this);
419 shaderInfo
->Validated
= true;
424 // ***************************************************************************
426 bool CDriverD3D::activeShader(CD3DShaderFX
*shd
)
428 H_AUTO_D3D(CDriverD3D_activeShader
)
429 if (_DisableHardwarePixelShader
)
432 // Clear current textures
433 _CurrentShaderTextures
.clear();
435 // Shader has been changed ?
436 if (shd
&& shd
->_ShaderChanged
)
439 shd
->_DrvInfo
.kill();
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
);
457 // Get the texture handle
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());
473 nlwarning ("Can't create shader '%s' (0x%x):", shd
->getName(), hr
);
475 nlwarning ((const char*)pErrorMsgs
->GetBufferPointer());
476 shd
->_ShaderChanged
= false;
477 _CurrentShader
= NULL
;
482 shd
->_ShaderChanged
= false;
486 _CurrentShader
= shd
;
492 static void setFX(CD3DShaderFX
&s
, const char *name
, const char *prog
, CDriverD3D
*drv
)
498 nlverify (drv
->activeShader (&s
));
501 #define setFx(a,b,c) { setFX(a, b, c, this); }
503 static const char *CloudFx
=
505 texture texture0; \n\
506 texture texture1; \n\
509 pixelshader two_stages_ps = asm \n\
514 lrp r0.w, v0, t0, t1; \n\
516 +mul r0.w, c0, r0; \n\
519 technique two_stages_2 \n\
523 Texture[0] = <texture0>; \n\
524 Texture[1] = <texture1>; \n\
525 PixelShaderConstant[0] = <factor0>; \n\
526 PixelShader = (two_stages_ps); \n\
532 static const char *Lightmap0Fx
=
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\
543 // do a standard lighting with the first light \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\
562 static const char *Lightmap0blendFx
=
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\
573 // do a standard lighting with the first light \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\
594 static const char *Lightmap0blend_x2Fx
=
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\
605 // do a standard lighting with the first light \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\
626 static const char *Lightmap0_x2Fx
=
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\
637 // do a standard lighting with the first light \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\
656 static const char *Lightmap1Fx
=
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\
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\
674 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\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\
704 static const char *Lightmap1blendFx
=
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\
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\
722 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\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\
755 static const char *Lightmap1blend_x2Fx
=
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\
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\
774 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\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\
807 static const char *Lightmap1_x2Fx
=
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\
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\
826 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\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\
856 static const char *Lightmap2Fx
=
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\
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\
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\
888 technique three_stages_3 \n\
892 TexCoordIndex[2] = 1; \n\
894 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\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\
911 // **** 2 stages, no pixel shader technique \n\
912 technique two_stages_2 \n\
916 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\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\
945 FogColor = 0x00000000; // don't accumulate fog several times\n\
946 Lighting = false; \n\
947 AlphaBlendEnable = true; \n\
950 Texture[0] = <texture2>; \n\
951 TextureFactor = <color2>; \n\
952 ColorOp[0] = MODULATE; \n\
958 static const char *Lightmap2blendFx
=
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\
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\
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\
990 technique three_stages_3 \n\
994 TexCoordIndex[2] = 1; \n\
996 // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\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\
1015 // **** 2 stages, no pixel shader technique \n\
1016 technique two_stages_2 \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\
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\
1063 static const char *Lightmap2blend_x2Fx
=
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\
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\
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\
1096 technique three_stages_3 \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\
1121 // **** 2 stages, no pixel shader technique \n\
1122 technique two_stages_2 \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\
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\
1169 static const char *Lightmap2_x2Fx
=
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\
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\
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\
1202 technique three_stages_3 \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\
1225 // **** 2 stages, no pixel shader technique \n\
1226 technique two_stages_2 \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\
1259 FogColor = 0x00000000; // don't accumulate fog several times\n\
1260 Lighting = false; \n\
1261 AlphaBlendEnable = true; \n\
1263 DestBlend = one; \n\
1264 Texture[0] = <texture2>; \n\
1265 TextureFactor = <color2>; \n\
1266 ColorOp[0] = MODULATE; \n\
1272 static const char *Lightmap3Fx
=
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\
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\
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\
1309 technique four_stages_4 \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\
1335 // **** 3 stages technique \n\
1336 pixelshader three_stages_0_ps = asm \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\
1349 technique three_stages_3 \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\
1372 FogColor = 0x00000000; // don't accumulate fog several times\n\
1373 AlphaBlendEnable = true; \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\
1401 // **** 2 stages, no pixel shader technique \n\
1402 technique two_stages_2 \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\
1435 FogColor = 0x00000000; // don't accumulate fog several times\n\
1436 Lighting = false; \n\
1437 AlphaBlendEnable = true; \n\
1439 DestBlend = one; \n\
1440 Texture[0] = <texture2>; \n\
1441 TextureFactor = <color2>; \n\
1442 ColorOp[0] = MODULATE; \n\
1446 Texture[0] = <texture3>; \n\
1447 TextureFactor = <color3>; \n\
1455 static const char *Lightmap3blendFx
=
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\
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\
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\
1492 technique four_stages_4 \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\
1520 // **** 3 stages technique \n\
1521 pixelshader three_stages_0_ps = asm \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\
1534 technique three_stages_3 \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\
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\
1586 // **** 2 stages, no pixel shader technique \n\
1587 technique two_stages_2 \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\
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\
1631 Texture[0] = <texture3>; \n\
1632 TextureFactor = <color3>; \n\
1638 static const char *Lightmap3blend_x2Fx
=
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\
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\
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\
1676 technique four_stages_4 \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\
1704 // **** 3 stages technique \n\
1705 pixelshader three_stages_0_ps = asm \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\
1718 technique three_stages_3 \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\
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\
1770 // **** 2 stages, no pixel shader technique \n\
1771 technique two_stages_2 \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\
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\
1815 Texture[0] = <texture3>; \n\
1816 TextureFactor = <color3>; \n\
1822 static const char *Lightmap3_x2Fx
=
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\
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\
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\
1860 technique four_stages_4 \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\
1886 // **** 3 stages technique \n\
1887 pixelshader three_stages_0_ps = asm \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\
1900 technique three_stages_3 \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\
1923 FogColor = 0x00000000; // don't accumulate fog several times\n\
1924 AlphaBlendEnable = true; \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\
1952 // **** 2 stages, no pixel shader technique \n\
1953 technique two_stages_2 \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\
1986 FogColor = 0x00000000; // don't accumulate fog several times\n\
1987 Lighting = false; \n\
1988 AlphaBlendEnable = true; \n\
1990 DestBlend = one; \n\
1991 Texture[0] = <texture2>; \n\
1992 TextureFactor = <color2>; \n\
1993 ColorOp[0] = MODULATE; \n\
1997 Texture[0] = <texture3>; \n\
1998 TextureFactor = <color3>; \n\
2006 static const char *Lightmap4Fx
=
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\
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\
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\
2047 technique five_stages_5 \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\
2076 // **** 4 stages technique \n\
2077 pixelshader four_stages_ps = asm \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\
2092 technique four_stages_4 \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\
2118 FogColor = 0x00000000; // don't accumulate fog several times\n\
2119 Lighting = false; \n\
2120 AlphaBlendEnable = true; \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\
2149 // **** 3 stages technique \n\
2150 pixelshader three_stages_0_ps = asm \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\
2163 technique three_stages_3 \n\
2165 // 2 pass with the same pixel shader \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\
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\
2194 DestBlend = one; \n\
2195 Texture[1] = <texture3>; \n\
2196 Texture[2] = <texture4>; \n\
2197 PixelShaderConstant[1] = <factor3>; \n\
2198 PixelShaderConstant[2] = <factor4>; \n\
2202 // **** 2 stages, no pixel shader technique \n\
2203 technique two_stages_2 \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\
2236 FogColor = 0x00000000; // don't accumulate fog several times\n\
2237 Lighting = false; \n\
2238 AlphaBlendEnable = true; \n\
2240 DestBlend = one; \n\
2241 Texture[0] = <texture2>; \n\
2242 TextureFactor = <color2>; \n\
2243 ColorOp[0] = MODULATE; \n\
2247 Texture[0] = <texture3>; \n\
2248 TextureFactor = <color3>; \n\
2252 Texture[0] = <texture4>; \n\
2253 TextureFactor = <color4>; \n\
2260 static const char *Lightmap4blendFx
=
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\
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\
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\
2302 technique five_stages_5 \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\
2333 // **** 4 stages technique \n\
2334 pixelshader four_stages_ps = asm \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\
2349 technique four_stages_4 \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\
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\
2406 // **** 3 stages technique \n\
2407 pixelshader three_stages_0_ps = asm \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\
2420 technique three_stages_3 \n\
2422 // 2 pass with the same pixel shader \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\
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\
2459 // **** 2 stages, no pixel shader technique \n\
2460 technique two_stages_2 \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\
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\
2504 Texture[0] = <texture3>; \n\
2505 TextureFactor = <color3>; \n\
2509 Texture[0] = <texture4>; \n\
2510 TextureFactor = <color4>; \n\
2518 static const char *Lightmap4blend_x2Fx
=
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\
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\
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\
2560 technique five_stages_5 \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\
2591 // **** 4 stages technique \n\
2592 pixelshader four_stages_ps = asm \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\
2607 technique four_stages_4 \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\
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\
2664 // **** 3 stages technique \n\
2665 pixelshader three_stages_0_ps = asm \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\
2678 technique three_stages_3 \n\
2680 // 2 pass with the same pixel shader \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\
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\
2717 // **** 2 stages, no pixel shader technique \n\
2718 technique two_stages_2 \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\
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\
2762 Texture[0] = <texture3>; \n\
2763 TextureFactor = <color3>; \n\
2767 Texture[0] = <texture4>; \n\
2768 TextureFactor = <color4>; \n\
2776 static const char *Lightmap4_x2Fx
=
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\
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\
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\
2818 technique five_stages_5 \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\
2847 // **** 4 stages technique \n\
2848 pixelshader four_stages_ps = asm \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\
2863 technique four_stages_4 \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\
2889 FogColor = 0x00000000; // don't accumulate fog several times\n\
2890 Lighting = false; \n\
2891 AlphaBlendEnable = true; \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\
2920 // **** 3 stages technique \n\
2921 pixelshader three_stages_0_ps = asm \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\
2934 technique three_stages_3 \n\
2936 // 2 pass with the same pixel shader \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\
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\
2965 DestBlend = one; \n\
2966 Texture[1] = <texture3>; \n\
2967 Texture[2] = <texture4>; \n\
2968 PixelShaderConstant[1] = <factor3>; \n\
2969 PixelShaderConstant[2] = <factor4>; \n\
2973 // **** 2 stages, no pixel shader technique \n\
2974 technique two_stages_2 \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\
3007 FogColor = 0x00000000; // don't accumulate fog several times\n\
3008 Lighting = false; \n\
3009 AlphaBlendEnable = true; \n\
3011 DestBlend = one; \n\
3012 Texture[0] = <texture2>; \n\
3013 TextureFactor = <color2>; \n\
3014 ColorOp[0] = MODULATE; \n\
3018 Texture[0] = <texture3>; \n\
3019 TextureFactor = <color3>; \n\
3023 Texture[0] = <texture4>; \n\
3024 TextureFactor = <color4>; \n\
3031 static const char *Water_diffuseFx
=
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\
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\
3065 texld r0, r0, s2; \n\
3067 texld r1, t3, s3; \n\
3072 technique technique_water_diffuse_2_0 \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\
3086 pixelshader water_diffuse_1_4 = asm \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\
3100 technique technique_water_diffuse_1_4 \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\
3114 pixelshader water_diffuse_1_1 = asm \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\
3124 technique technique_water_diffuse_1_1 \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\
3143 static const char *Water_no_diffuseFx
=
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\
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\
3174 texld r0, r0, s2; \n\
3178 technique technique_water_no_diffuse_2_0 \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\
3191 pixelshader water_no_diffuse_1_4 = asm \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\
3204 technique technique_water_no_diffuse_1_4 \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\
3217 pixelshader water_no_diffuse_1_1 = asm \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\
3226 technique technique_water_no_diffuse_1_1 \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\
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
))
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
);
3323 cache
->Params
.setTexture(textureHandle
, d3dtext
->Texture
);
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
;
3340 // ***************************************************************************
3342 void CDriverD3D::disableHardwareTextureShader()
3344 // cannot disable pixel shader under DX, because it crashes with lightmap
3347 _DisableHardwarePixelShader = true;
3348 _PixelShader = false;
3354 // ***************************************************************************
3355 void CDriverD3D::notifyAllShaderDrvOfLostDevice()
3357 for(TShaderDrvInfoPtrList::iterator it
= _ShaderDrvInfos
.begin(); it
!= _ShaderDrvInfos
.end(); ++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
)
3374 CShaderDrvInfosD3D
*drvInfo
= NLMISC::safe_cast
<CShaderDrvInfosD3D
*>(*it
);
3375 if (drvInfo
->Effect
)
3378 drvInfo
->Effect
->OnResetDevice();
3385 // ***************************************************************************
3386 // state records (for .fx caching)
3387 // ***************************************************************************
3389 class CStateRecordLightEnable
: public CStateRecord
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
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
3419 D3DMATERIAL9 Material
;
3421 CStateRecordMaterial(const D3DMATERIAL9
*pMaterial
) : Material(*pMaterial
) {}
3422 virtual void apply(class CDriverD3D
&drv
)
3424 drv
.setMaterialState(Material
);
3428 class CStateRecordPixelShader
: public CStateRecord
3431 LPDIRECT3DPIXELSHADER9 PixelShader
;
3433 CStateRecordPixelShader(LPDIRECT3DPIXELSHADER9 pixelShader
) : PixelShader(pixelShader
) {}
3434 virtual void apply(class CDriverD3D
&drv
)
3436 drv
.setPixelShader(PixelShader
);
3440 class CStateRecordPixelShaderConstantB
: public CStateRecord
3443 std::vector
<BOOL
> Values
;
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
);
3465 class CStateRecordPixelShaderConstantF
: public CStateRecord
3468 std::vector
<FLOAT
> Values
;
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
);
3490 class CStateRecordPixelShaderConstantI
: public CStateRecord
3493 std::vector
<INT
> Values
;
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
);
3515 class CStateRecordRenderState
: public CStateRecord
3518 D3DRENDERSTATETYPE State
;
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
3532 D3DSAMPLERSTATETYPE Type
;
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
3546 CRefPtr
<ITexture
> TexRef
;
3547 LPDIRECT3DBASETEXTURE9 Texture
;
3550 CStateRecordTexture(DWORD stage
, LPDIRECT3DBASETEXTURE9 texture
, ITexture
*nelTexture
) : Stage(stage
), Texture(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
;
3559 HRESULT r
= Texture
->AddRef();
3560 nlassert(r
== D3D_OK
);
3563 ~CStateRecordTexture()
3565 nlassert(Texture
); // no default ctor, so texture should have been set
3568 nlassert(TexRef
== NULL
);
3569 HRESULT r
= Texture
->Release();
3570 nlassert(r
== D3D_OK
);
3573 virtual void apply(class CDriverD3D
&drv
)
3578 drv
.setTexture(Stage
, TexRef
);
3582 drv
.setTexture(Stage
, Texture
);
3587 class CStateRecordTextureStageState
: public CStateRecord
3591 D3DTEXTURESTAGESTATETYPE Type
;
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
);
3600 drv
.setTextureState (Stage
, Type
, Value
);
3604 class CStateRecordTransform
: public CStateRecord
3607 D3DTRANSFORMSTATETYPE State
;
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
3620 LPDIRECT3DVERTEXSHADER9 Shader
;
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
3633 std::vector
<BOOL
> Values
;
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
);
3654 class CStateRecordVertexShaderConstantF
: public CStateRecord
3657 std::vector
<FLOAT
> Values
;
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
);
3678 class CStateRecordVertexShaderConstantI
: public CStateRecord
3681 std::vector
<INT
> Values
;
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
);
3704 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::QueryInterface(REFIID riid
, LPVOID
*ppvObj
)
3707 return Driver
->QueryInterface(riid
, ppvObj
);
3710 ULONG STDMETHODCALLTYPE
CFXPassRecorder::AddRef(VOID
)
3713 return Driver
->AddRef();
3716 ULONG STDMETHODCALLTYPE
CFXPassRecorder::Release(VOID
)
3719 return Driver
->Release();
3722 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::LightEnable(DWORD Index
, BOOL Enable
)
3726 Target
->States
.push_back(new CStateRecordLightEnable(Index
, Enable
));
3730 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetFVF(DWORD
/* FVF */)
3732 nlassert(0); // not managed
3736 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetLight(DWORD Index
, CONST D3DLIGHT9
* pLight
)
3740 Target
->States
.push_back(new CStateRecordLight(Index
, pLight
));
3744 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetMaterial(CONST D3DMATERIAL9
* pMaterial
)
3748 Target
->States
.push_back(new CStateRecordMaterial(pMaterial
));
3752 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetNPatchMode(FLOAT
/* nSegments */)
3754 nlassert(0); // not managed
3758 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader
)
3762 Target
->States
.push_back(new CStateRecordPixelShader(pShader
));
3766 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetPixelShaderConstantB(UINT StartRegister
, CONST BOOL
* pConstantData
, UINT RegisterCount
)
3770 Target
->States
.push_back(new CStateRecordPixelShaderConstantB(StartRegister
, pConstantData
, RegisterCount
));
3774 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetPixelShaderConstantF(UINT StartRegister
, CONST FLOAT
* pConstantData
, UINT RegisterCount
)
3778 Target
->States
.push_back(new CStateRecordPixelShaderConstantF(StartRegister
, pConstantData
, RegisterCount
));
3782 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetPixelShaderConstantI(UINT StartRegister
, CONST INT
* pConstantData
, UINT RegisterCount
)
3786 Target
->States
.push_back(new CStateRecordPixelShaderConstantI(StartRegister
, pConstantData
, RegisterCount
));
3790 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetRenderState(D3DRENDERSTATETYPE State
, DWORD Value
)
3794 Target
->States
.push_back(new CStateRecordRenderState(State
, Value
));
3798 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetSamplerState(DWORD Sampler
, D3DSAMPLERSTATETYPE Type
, DWORD Value
)
3802 Target
->States
.push_back(new CStateRecordSamplerState(Sampler
, Type
, Value
));
3806 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetTexture(DWORD Stage
, LPDIRECT3DBASETEXTURE9 pTexture
)
3810 // Look for the current texture
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
));
3825 // The texture isn't a NeL texture (was created inside driver)
3826 Target
->States
.push_back(new CStateRecordTexture(Stage
, pTexture
, NULL
));
3832 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetTextureStageState(DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
)
3836 Target
->States
.push_back(new CStateRecordTextureStageState(Stage
, Type
, Value
));
3840 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetTransform(D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* pMatrix
)
3844 Target
->States
.push_back(new CStateRecordTransform(State
, pMatrix
));
3848 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetVertexShader(LPDIRECT3DVERTEXSHADER9 pShader
)
3852 Target
->States
.push_back(new CStateRecordVertexShader(pShader
));
3856 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetVertexShaderConstantB(UINT StartRegister
, CONST BOOL
* pConstantData
, UINT RegisterCount
)
3860 Target
->States
.push_back(new CStateRecordVertexShaderConstantB(StartRegister
, pConstantData
, RegisterCount
));
3864 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetVertexShaderConstantF(UINT StartRegister
, CONST FLOAT
* pConstantData
, UINT RegisterCount
)
3868 Target
->States
.push_back(new CStateRecordVertexShaderConstantF(StartRegister
, pConstantData
, RegisterCount
));
3872 HRESULT STDMETHODCALLTYPE
CFXPassRecorder::SetVertexShaderConstantI(UINT StartRegister
, CONST INT
* pConstantData
, UINT RegisterCount
)
3876 Target
->States
.push_back(new CStateRecordVertexShaderConstantI(StartRegister
, pConstantData
, RegisterCount
));
3880 //===================================================================================
3881 CFXPassRecord::~CFXPassRecord()
3883 for(std::vector
<CStateRecord
*>::iterator it
= States
.begin(); it
!= States
.end(); ++it
)
3889 void CFXPassRecord::apply(CDriverD3D
&drv
)
3891 for(std::vector
<CStateRecord
*>::iterator it
= States
.begin(); it
!= States
.end(); ++it
)
3897 const uint NL_D3D_NUM_RENDER_FOR_FX_CACHING
= 4;
3899 //===================================================================================
3900 void CFXCache::setConstants(CShaderDrvInfosD3D
*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
)
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
3923 Params
.Touched
= false;
3926 if (!Params
.Touched
)
3930 if (Steadyness
< NL_D3D_NUM_RENDER_FOR_FX_CACHING
)
3936 if (Passes
.empty()) // must record shader ?
3942 si
->Effect
->SetStateManager(&pr
);
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();
3956 si
->Effect
->Pass(k
);
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
3974 HRESULT r
= si
->Effect
->Begin(&numPasses
, D3DXFX_DONOTSAVESTATE
|D3DXFX_DONOTSAVESHADERSTATE
);
3975 nlassert(r
== D3D_OK
);
3976 NumPasses
= numPasses
;
3978 nlassert(passIndex
< NumPasses
);
3981 #if (DIRECT3D_VERSION >= 0x0900) && (D3D_SDK_VERSION >= 32)
3982 HRESULT r
= si
->Effect
->BeginPass(passIndex
);
3983 si
->Effect
->EndPass ();
3985 HRESULT r
= si
->Effect
->Pass(passIndex
);
3987 nlassert(r
== D3D_OK
);
3991 Passes
[passIndex
].apply(drv
);
3995 void CFXCache::end(CShaderDrvInfosD3D
*si
)
3999 HRESULT r
= si
->Effect
->End();
4000 nlassert(r
== D3D_OK
);
4005 void CFXCache::reset()