Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

537 lines
18 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "convar.h"
  10. #include "worldvertextransition.inc"
  11. #include "worldvertextransition_vs14.inc"
  12. #include "worldvertextransition_seamless.inc"
  13. #include "lightmappedgeneric_vs11.inc"
  14. #include "writevertexalphatodestalpha_vs11.inc"
  15. #include "worldvertextransition_dx8_helper.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. DEFINE_FALLBACK_SHADER( WorldVertexTransition, WorldVertexTransition_DX8 )
  19. ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT );
  20. BEGIN_VS_SHADER( WorldVertexTransition_DX8,
  21. "Help for WorldVertexTransition_DX8" )
  22. BEGIN_SHADER_PARAMS
  23. SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture2", "base texture2 help" )
  24. SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $baseTexture" )
  25. SHADER_PARAM( BASETEXTURETRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$baseTexture texcoord transform" )
  26. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  27. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  28. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  29. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
  30. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  31. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
  32. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  33. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
  34. SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" )
  35. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  36. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map for BASETEXTURE" )
  37. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  38. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  39. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  40. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  41. SHADER_PARAM( BUMPBASETEXTURE2WITHBUMPMAP, SHADER_PARAM_TYPE_BOOL, "0", "" )
  42. SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "0.0", "1.0 == mirror, 0.0 == water" )
  43. SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" )
  44. SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" )
  45. SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" )
  46. SHADER_PARAM( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" )
  47. END_SHADER_PARAMS
  48. SHADER_FALLBACK
  49. {
  50. if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 )
  51. return "WorldVertexTransition_DX6";
  52. return 0;
  53. }
  54. void SetupVars( WorldVertexTransitionEditor_DX8_Vars_t& info )
  55. {
  56. info.m_nBaseTextureVar = BASETEXTURE;
  57. info.m_nBaseTextureFrameVar = FRAME;
  58. info.m_nBaseTextureTransformVar = BASETEXTURETRANSFORM;
  59. info.m_nBaseTexture2Var = BASETEXTURE2;
  60. info.m_nBaseTexture2FrameVar = FRAME2;
  61. info.m_nBaseTexture2TransformVar = BASETEXTURETRANSFORM2;
  62. }
  63. SHADER_INIT_PARAMS()
  64. {
  65. // Initializes FLASHLIGHTTEXTURE + MATERIAL_VAR2_LIGHTING_LIGHTMAP
  66. WorldVertexTransitionEditor_DX8_Vars_t info;
  67. SetupVars( info );
  68. InitParamsWorldVertexTransitionEditor_DX8( params, info );
  69. // FLASHLIGHTFIXME
  70. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
  71. if( IsUsingGraphics() && params[ENVMAP]->IsDefined() && !CanUseEditorMaterials() )
  72. {
  73. if( stricmp( params[ENVMAP]->GetStringValue(), "env_cubemap" ) == 0 )
  74. {
  75. Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName );
  76. params[ENVMAP]->SetUndefined();
  77. }
  78. }
  79. if( !params[ENVMAPMASKSCALE]->IsDefined() )
  80. {
  81. params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f );
  82. }
  83. if( !params[ENVMAPTINT]->IsDefined() )
  84. {
  85. params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  86. }
  87. if( !params[SELFILLUMTINT]->IsDefined() )
  88. {
  89. params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  90. }
  91. if( !params[DETAILSCALE]->IsDefined() )
  92. {
  93. params[DETAILSCALE]->SetFloatValue( 4.0f );
  94. }
  95. if( !params[FRESNELREFLECTION]->IsDefined() )
  96. {
  97. params[FRESNELREFLECTION]->SetFloatValue( 1.0f );
  98. }
  99. if( !params[ENVMAPMASKFRAME]->IsDefined() )
  100. {
  101. params[ENVMAPMASKFRAME]->SetIntValue( 0 );
  102. }
  103. if( !params[ENVMAPFRAME]->IsDefined() )
  104. {
  105. params[ENVMAPFRAME]->SetIntValue( 0 );
  106. }
  107. if( !params[BUMPFRAME]->IsDefined() )
  108. {
  109. params[BUMPFRAME]->SetIntValue( 0 );
  110. }
  111. if( !params[ENVMAPCONTRAST]->IsDefined() )
  112. {
  113. params[ENVMAPCONTRAST]->SetFloatValue( 0.0f );
  114. }
  115. if( !params[ENVMAPSATURATION]->IsDefined() )
  116. {
  117. params[ENVMAPSATURATION]->SetFloatValue( 1.0f );
  118. }
  119. // No texture means no self-illum or env mask in base alpha
  120. if ( !params[BASETEXTURE]->IsDefined() )
  121. {
  122. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  123. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  124. }
  125. // If in decal mode, no debug override...
  126. if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
  127. {
  128. SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  129. }
  130. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  131. if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() )
  132. {
  133. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP );
  134. }
  135. if( !params[BUMPBASETEXTURE2WITHBUMPMAP]->IsDefined() )
  136. {
  137. params[BUMPBASETEXTURE2WITHBUMPMAP]->SetIntValue( 0 );
  138. }
  139. if( !params[DETAILSCALE]->IsDefined() )
  140. {
  141. params[DETAILSCALE]->SetFloatValue( 4.0f );
  142. }
  143. if( !params[DETAILFRAME]->IsDefined() )
  144. {
  145. params[DETAILFRAME]->SetIntValue( 0 );
  146. }
  147. if( params[SEAMLESS_SCALE]->IsDefined() && params[SEAMLESS_SCALE]->GetFloatValue() != 0.0f )
  148. {
  149. // seamless scale is going to be used, so kill some other features. . might implement with these features later.
  150. params[DETAIL]->SetUndefined();
  151. params[BUMPMAP]->SetUndefined();
  152. params[ENVMAP]->SetUndefined();
  153. }
  154. if ( !params[SEAMLESS_SCALE]->IsDefined() )
  155. {
  156. // zero means don't do seamless mapping.
  157. params[SEAMLESS_SCALE]->SetFloatValue( 0.0f );
  158. }
  159. if( params[SSBUMP]->IsDefined() && params[SSBUMP]->GetIntValue() != 0 )
  160. {
  161. // turn of normal mapping since we have ssbump defined, which
  162. // means that we didn't make a dx8 fallback for this material.
  163. params[BUMPMAP]->SetUndefined();
  164. }
  165. }
  166. SHADER_INIT
  167. {
  168. // Loads BASETEXTURE, BASETEXTURE2
  169. WorldVertexTransitionEditor_DX8_Vars_t info;
  170. SetupVars( info );
  171. InitWorldVertexTransitionEditor_DX8( this, params, info );
  172. // FLASHLIGHTFIXME
  173. if ( params[FLASHLIGHTTEXTURE]->IsDefined() )
  174. {
  175. LoadTexture( FLASHLIGHTTEXTURE );
  176. }
  177. if (params[DETAIL]->IsDefined())
  178. {
  179. LoadTexture( DETAIL );
  180. }
  181. if ( g_pHardwareConfig->SupportsPixelShaders_1_4() && params[BLENDMODULATETEXTURE]->IsDefined() )
  182. {
  183. LoadTexture( BLENDMODULATETEXTURE );
  184. }
  185. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  186. if( params[ENVMAP]->IsDefined() && !params[BUMPMAP]->IsDefined() )
  187. {
  188. Warning( "must have $bumpmap if you have $envmap for worldvertextransition\n" );
  189. params[ENVMAP]->SetUndefined();
  190. params[BUMPMAP]->SetUndefined();
  191. }
  192. if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() )
  193. {
  194. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
  195. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP );
  196. LoadBumpMap( BUMPMAP );
  197. }
  198. if( params[ENVMAP]->IsDefined() )
  199. {
  200. if( !IS_FLAG_SET( MATERIAL_VAR_ENVMAPSPHERE ) )
  201. {
  202. LoadCubeMap( ENVMAP );
  203. }
  204. else
  205. {
  206. Warning( "$envmapsphere not supported by worldvertextransition\n" );
  207. params[ENVMAP]->SetUndefined();
  208. }
  209. }
  210. }
  211. void WriteVertexAlphaToDestAlpha( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow )
  212. {
  213. if( pShaderShadow )
  214. {
  215. pShaderShadow->EnableDepthWrites( false );
  216. pShaderShadow->EnableAlphaWrites( true );
  217. pShaderShadow->EnableColorWrites( false );
  218. writevertexalphatodestalpha_vs11_Static_Index vshIndex;
  219. pShaderShadow->SetVertexShader( "writevertexalphatodestalpha_vs11", vshIndex.GetIndex() );
  220. pShaderShadow->SetPixelShader( "writevertexalphatodestalpha_ps11" );
  221. pShaderShadow->VertexShaderVertexFormat(
  222. VERTEX_POSITION | VERTEX_COLOR, 2, 0, 0 );
  223. }
  224. else
  225. {
  226. writevertexalphatodestalpha_vs11_Dynamic_Index vshIndex;
  227. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  228. }
  229. Draw();
  230. }
  231. void DrawFlashlightPass( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, int passID )
  232. {
  233. bool bBump = ( passID == 0 ) && ShouldUseBumpmapping( params ) && params[BUMPMAP]->IsTexture();
  234. DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, bBump, BUMPMAP, BUMPFRAME, BUMPTRANSFORM,
  235. FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, true, passID, BASETEXTURE2, FRAME2 );
  236. }
  237. bool ShouldUseBumpmapping( IMaterialVar **params )
  238. {
  239. return g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined();
  240. }
  241. void DrawFlashlight( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow )
  242. {
  243. WriteVertexAlphaToDestAlpha( params, pShaderAPI, pShaderShadow );
  244. DrawFlashlightPass( params, pShaderAPI, pShaderShadow, 0 );
  245. DrawFlashlightPass( params, pShaderAPI, pShaderShadow, 1 );
  246. }
  247. SHADER_DRAW
  248. {
  249. bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  250. bool bSupports14 = g_pHardwareConfig->SupportsPixelShaders_1_4();
  251. // FLASHLIGHTFIXME: need to make these the same.
  252. bool hasFlashlight = UsingFlashlight( params );
  253. if( hasFlashlight )
  254. {
  255. DrawFlashlight( params, pShaderAPI, pShaderShadow );
  256. }
  257. else if ( params[SEAMLESS_SCALE]->GetFloatValue() != 0.0f )
  258. {
  259. // This is the seamless_scale version, which doesn't use $detail or $bumpmap
  260. SHADOW_STATE
  261. {
  262. // three copies of the base texture for seamless blending
  263. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  264. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  265. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  266. // lightmap
  267. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  268. int fmt = VERTEX_POSITION;
  269. pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 );
  270. worldvertextransition_seamless_Static_Index vshIndex;
  271. pShaderShadow->SetVertexShader( "WorldVertexTransition_Seamless", vshIndex.GetIndex() );
  272. int pshIndex = 0;
  273. pShaderShadow->SetPixelShader( "WorldVertexTransition_Seamless", pshIndex );
  274. FogToFogColor();
  275. }
  276. DYNAMIC_STATE
  277. {
  278. // Texture 0..2
  279. if( bLightingOnly )
  280. {
  281. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY );
  282. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY );
  283. pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_GREY );
  284. }
  285. else
  286. {
  287. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  288. BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME );
  289. BindTexture( SHADER_SAMPLER2, BASETEXTURE, FRAME );
  290. }
  291. // Texture 3 = lightmap
  292. pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_LIGHTMAP );
  293. EnablePixelShaderOverbright( 0, true, true );
  294. float fSeamlessScale = params[SEAMLESS_SCALE]->GetFloatValue();
  295. float map_scale[4]= { fSeamlessScale, fSeamlessScale, fSeamlessScale, fSeamlessScale };
  296. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, map_scale );
  297. worldvertextransition_seamless_Dynamic_Index vshIndex;
  298. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  299. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  300. }
  301. Draw();
  302. SHADOW_STATE
  303. {
  304. // inherit state from previous pass
  305. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  306. }
  307. DYNAMIC_STATE
  308. {
  309. if( !bLightingOnly )
  310. {
  311. BindTexture( SHADER_SAMPLER0, BASETEXTURE2, FRAME2 );
  312. BindTexture( SHADER_SAMPLER1, BASETEXTURE2, FRAME2 );
  313. BindTexture( SHADER_SAMPLER2, BASETEXTURE2, FRAME2 );
  314. }
  315. }
  316. Draw();
  317. }
  318. else if( !params[BUMPMAP]->IsTexture() || !g_pConfig->UseBumpmapping() )
  319. {
  320. bool bDetail = params[DETAIL]->IsTexture();
  321. bool bBlendModulate = params[BLENDMODULATETEXTURE]->IsTexture();
  322. SHADOW_STATE
  323. {
  324. // This is the dx8, non-worldcraft version, non-bumped version
  325. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  326. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  327. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  328. if( bDetail )
  329. {
  330. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  331. }
  332. if ( bSupports14 && bBlendModulate )
  333. {
  334. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  335. }
  336. int fmt = VERTEX_POSITION | VERTEX_COLOR;
  337. pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 );
  338. if ( !bSupports14 )
  339. {
  340. worldvertextransition_Static_Index vshIndex;
  341. pShaderShadow->SetVertexShader( "WorldVertexTransition", vshIndex.GetIndex() );
  342. int pshIndex = bDetail ? 1 : 0;
  343. pShaderShadow->SetPixelShader( "WorldVertexTransition", pshIndex );
  344. }
  345. else
  346. {
  347. worldvertextransition_vs14_Static_Index vshIndex;
  348. pShaderShadow->SetVertexShader( "WorldVertexTransition_vs14", vshIndex.GetIndex() );
  349. int pshIndex = bDetail ? 1 : 0;
  350. pshIndex += bBlendModulate ? 2 : 0;
  351. pShaderShadow->SetPixelShader( "WorldVertexTransition_ps14", pshIndex );
  352. }
  353. FogToFogColor();
  354. }
  355. DYNAMIC_STATE
  356. {
  357. // Texture 1
  358. if( bLightingOnly )
  359. {
  360. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY );
  361. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY );
  362. }
  363. else
  364. {
  365. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  366. BindTexture( SHADER_SAMPLER1, BASETEXTURE2, FRAME2 );
  367. }
  368. if( bDetail )
  369. {
  370. BindTexture( SHADER_SAMPLER3, DETAIL, DETAILFRAME );
  371. }
  372. if ( bSupports14 && bBlendModulate )
  373. {
  374. BindTexture( SHADER_SAMPLER4, BLENDMODULATETEXTURE );
  375. }
  376. // always set the transform for detail textures since I'm assuming that you'll
  377. // always have a detailscale.
  378. // go ahead and set this even if we don't have a detail texture so the vertex shader doesn't
  379. // barf chunks with unitialized data.
  380. SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURETRANSFORM, DETAILSCALE );
  381. if ( bSupports14 )
  382. {
  383. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, BLENDMASKTRANSFORM );
  384. }
  385. // Texture 3 = lightmap
  386. pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_LIGHTMAP );
  387. EnablePixelShaderOverbright( 0, true, true );
  388. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  389. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BASETEXTURETRANSFORM2 );
  390. if ( !bSupports14 )
  391. {
  392. worldvertextransition_Dynamic_Index vshIndex;
  393. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  394. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  395. }
  396. else
  397. {
  398. worldvertextransition_vs14_Dynamic_Index vshIndex;
  399. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  400. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  401. }
  402. }
  403. Draw();
  404. }
  405. else
  406. {
  407. if( params[BUMPBASETEXTURE2WITHBUMPMAP]->GetIntValue() )
  408. {
  409. DrawWorldBumpedUsingVertexShader( BASETEXTURE, BASETEXTURETRANSFORM,
  410. BUMPMAP, BUMPFRAME, BUMPTRANSFORM, ENVMAPMASK, ENVMAPMASKFRAME, ENVMAP,
  411. ENVMAPFRAME, ENVMAPTINT, COLOR, ALPHA, ENVMAPCONTRAST, ENVMAPSATURATION, FRAME,
  412. FRESNELREFLECTION, true, BASETEXTURE2, BASETEXTURETRANSFORM2, FRAME2, false );
  413. }
  414. else
  415. {
  416. // draw the base texture with everything else you normally would for
  417. // bumped world materials
  418. DrawWorldBumpedUsingVertexShader(
  419. BASETEXTURE, BASETEXTURETRANSFORM,
  420. BUMPMAP, BUMPFRAME, BUMPTRANSFORM,
  421. ENVMAPMASK, ENVMAPMASKFRAME, ENVMAP, ENVMAPFRAME, ENVMAPTINT,
  422. COLOR, ALPHA, ENVMAPCONTRAST, ENVMAPSATURATION, FRAME,
  423. FRESNELREFLECTION,
  424. false, -1, -1, -1, false );
  425. // blend basetexture 2 on top of everything using lightmap alpha.
  426. SHADOW_STATE
  427. {
  428. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  429. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  430. pShaderShadow->VertexShaderVertexFormat(
  431. VERTEX_POSITION | VERTEX_COLOR, 2, 0, 0 );
  432. pShaderShadow->EnableBlending( true );
  433. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  434. lightmappedgeneric_vs11_Static_Index vshIndex;
  435. vshIndex.SetDETAIL( false );
  436. vshIndex.SetENVMAP( false );
  437. vshIndex.SetENVMAPCAMERASPACE( false );
  438. vshIndex.SetENVMAPSPHERE( false );
  439. vshIndex.SetVERTEXCOLOR( true );
  440. pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() );
  441. pShaderShadow->SetPixelShader( "WorldVertexTransition_BlendBase2" );
  442. FogToFogColor();
  443. }
  444. DYNAMIC_STATE
  445. {
  446. if( bLightingOnly )
  447. {
  448. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY );
  449. }
  450. else
  451. {
  452. BindTexture( SHADER_SAMPLER0, BASETEXTURE2, FRAME2 );
  453. }
  454. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
  455. float half[4] = { 0.5f, 0.5f, 0.5f, 0.5f };
  456. pShaderAPI->SetPixelShaderConstant( 4, half );
  457. EnablePixelShaderOverbright( 0, true, true );
  458. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM2 );
  459. lightmappedgeneric_vs11_Dynamic_Index vshIndex;
  460. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  461. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  462. }
  463. Draw();
  464. }
  465. }
  466. }
  467. END_SHADER