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.

500 lines
17 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 "lightmappedgeneric_vs20.inc"
  11. #include "WorldTwoTextureBlend_ps20.inc"
  12. #include "WorldTwoTextureBlend_ps20b.inc"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. extern ConVar r_flashlight_version2;
  16. // FIXME: Need to make a dx9 version so that "CENTROID" works.
  17. BEGIN_VS_SHADER( WorldTwoTextureBlend,
  18. "Help for WorldTwoTextureBlend" )
  19. BEGIN_SHADER_PARAMS
  20. SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend", "iris texture", 0 )
  21. SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend", "albedo (Base texture with no baked lighting)" )
  22. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  23. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend_detail", "detail texture" )
  24. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  25. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "scale of the detail texture" )
  26. SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0",
  27. "If this is 1, then when detail alpha=0, no base texture is blended and when "
  28. "detail alpha=1, you get detail*base*lightmap" )
  29. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" )
  30. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  31. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  32. SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_INTEGER, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" )
  33. SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" )
  34. END_SHADER_PARAMS
  35. SHADER_FALLBACK
  36. {
  37. if( g_pHardwareConfig->GetDXSupportLevel() < 80 )
  38. return "WorldTwoTextureBlend_DX6";
  39. if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  40. return "WorldTwoTextureBlend_DX8";
  41. return 0;
  42. }
  43. SHADER_INIT_PARAMS()
  44. {
  45. if( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->IsDefined() )
  46. {
  47. params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->SetIntValue( 0 );
  48. }
  49. if ( g_pHardwareConfig->SupportsBorderColor() )
  50. {
  51. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
  52. }
  53. else
  54. {
  55. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
  56. }
  57. // Write over $basetexture with $albedo if we are going to be using diffuse normal mapping.
  58. if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() && params[ALBEDO]->IsDefined() &&
  59. params[BASETEXTURE]->IsDefined() &&
  60. !( params[NODIFFUSEBUMPLIGHTING]->IsDefined() && params[NODIFFUSEBUMPLIGHTING]->GetIntValue() ) )
  61. {
  62. params[BASETEXTURE]->SetStringValue( params[ALBEDO]->GetStringValue() );
  63. }
  64. if( !params[NODIFFUSEBUMPLIGHTING]->IsDefined() )
  65. {
  66. params[NODIFFUSEBUMPLIGHTING]->SetIntValue( 0 );
  67. }
  68. if( !params[SELFILLUMTINT]->IsDefined() )
  69. {
  70. params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  71. }
  72. if( !params[DETAILSCALE]->IsDefined() )
  73. {
  74. params[DETAILSCALE]->SetFloatValue( 4.0f );
  75. }
  76. if( !params[BUMPFRAME]->IsDefined() )
  77. {
  78. params[BUMPFRAME]->SetIntValue( 0 );
  79. }
  80. if( !params[DETAILFRAME]->IsDefined() )
  81. {
  82. params[DETAILFRAME]->SetIntValue( 0 );
  83. }
  84. // No texture means no self-illum or env mask in base alpha
  85. if ( !params[BASETEXTURE]->IsDefined() )
  86. {
  87. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  88. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  89. }
  90. // If in decal mode, no debug override...
  91. if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
  92. {
  93. SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  94. }
  95. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  96. if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0) )
  97. {
  98. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP );
  99. }
  100. }
  101. SHADER_INIT
  102. {
  103. if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() )
  104. {
  105. LoadBumpMap( BUMPMAP );
  106. }
  107. if (params[BASETEXTURE]->IsDefined())
  108. {
  109. LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
  110. if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent())
  111. {
  112. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  113. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  114. }
  115. }
  116. if (params[DETAIL]->IsDefined())
  117. {
  118. LoadTexture( DETAIL );
  119. }
  120. LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB );
  121. // Don't alpha test if the alpha channel is used for other purposes
  122. if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
  123. {
  124. CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
  125. }
  126. // We always need this because of the flashlight.
  127. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
  128. }
  129. void DrawPass( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  130. IShaderShadow* pShaderShadow, bool hasFlashlight, VertexCompressionType_t vertexCompression )
  131. {
  132. bool hasBump = params[BUMPMAP]->IsTexture();
  133. bool hasDiffuseBumpmap = hasBump && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0);
  134. bool hasBaseTexture = params[BASETEXTURE]->IsTexture();
  135. bool hasDetailTexture = /*!hasBump && */params[DETAIL]->IsTexture();
  136. bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) != 0;
  137. bool bHasDetailAlpha = params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->GetIntValue() != 0;
  138. bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0;
  139. BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true );
  140. bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use
  141. bool bSeamlessMapping = params[SEAMLESS_SCALE]->GetFloatValue() != 0.0;
  142. SHADOW_STATE
  143. {
  144. int nShadowFilterMode = 0;
  145. // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState
  146. pShaderShadow->EnableAlphaTest( bIsAlphaTested );
  147. if( hasFlashlight )
  148. {
  149. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  150. {
  151. nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats
  152. }
  153. SetAdditiveBlendingShadowState( BASETEXTURE, true );
  154. pShaderShadow->EnableDepthWrites( false );
  155. // Be sure not to write to dest alpha
  156. pShaderShadow->EnableAlphaWrites( false );
  157. }
  158. else
  159. {
  160. SetDefaultBlendingShadowState( BASETEXTURE, true );
  161. }
  162. unsigned int flags = VERTEX_POSITION;
  163. if( hasBaseTexture )
  164. {
  165. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  166. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  167. }
  168. // if( hasLightmap )
  169. {
  170. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  171. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE );
  172. }
  173. if( hasFlashlight )
  174. {
  175. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  176. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true );
  177. pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER7 );
  178. flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T | VERTEX_NORMAL;
  179. }
  180. if( hasDetailTexture )
  181. {
  182. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  183. }
  184. if( hasBump )
  185. {
  186. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  187. }
  188. if( hasVertexColor )
  189. {
  190. flags |= VERTEX_COLOR;
  191. }
  192. // Normalizing cube map
  193. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true );
  194. // texcoord0 : base texcoord
  195. // texcoord1 : lightmap texcoord
  196. // texcoord2 : lightmap texcoord offset
  197. int numTexCoords = 2;
  198. if( hasBump )
  199. {
  200. numTexCoords = 3;
  201. }
  202. pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 );
  203. // Pre-cache pixel shaders
  204. bool hasSelfIllum = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM );
  205. pShaderShadow->EnableSRGBWrite( true );
  206. DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 );
  207. SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, false );
  208. SET_STATIC_VERTEX_SHADER_COMBO( BUMPMASK, false );
  209. SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, hasFlashlight );
  210. SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, hasBump );
  211. SET_STATIC_VERTEX_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap );
  212. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, hasVertexColor );
  213. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXALPHATEXBLENDFACTOR, false );
  214. SET_STATIC_VERTEX_SHADER_COMBO( RELIEF_MAPPING, 0 ); //( bumpmap_variant == 2 )?1:0);
  215. SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); //( bumpmap_variant == 2 )?1:0);
  216. #ifdef _X360
  217. SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, hasFlashlight );
  218. #endif
  219. SET_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 );
  220. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  221. {
  222. DECLARE_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20b );
  223. SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture );
  224. SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, hasBump );
  225. SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap );
  226. SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, hasVertexColor );
  227. SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum );
  228. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_ALPHA_MASK_BASE_TEXTURE, bHasDetailAlpha );
  229. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight );
  230. SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping );
  231. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  232. SET_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20b );
  233. }
  234. else
  235. {
  236. DECLARE_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20 );
  237. SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture );
  238. SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, hasBump );
  239. SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap );
  240. SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, hasVertexColor );
  241. SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum );
  242. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_ALPHA_MASK_BASE_TEXTURE, bHasDetailAlpha );
  243. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight );
  244. SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping );
  245. SET_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20 );
  246. }
  247. // HACK HACK HACK - enable alpha writes all the time so that we have them for
  248. // underwater stuff.
  249. // But only do it if we're not using the alpha already for translucency
  250. pShaderShadow->EnableAlphaWrites( bFullyOpaque );
  251. if( hasFlashlight )
  252. {
  253. FogToBlack();
  254. }
  255. else
  256. {
  257. DefaultFog();
  258. }
  259. }
  260. DYNAMIC_STATE
  261. {
  262. if( hasBaseTexture )
  263. {
  264. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  265. }
  266. else
  267. {
  268. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE );
  269. }
  270. // if( hasLightmap )
  271. {
  272. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
  273. }
  274. bool bFlashlightShadows = false;
  275. if( hasFlashlight )
  276. {
  277. VMatrix worldToTexture;
  278. ITexture *pFlashlightDepthTexture;
  279. FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture );
  280. bFlashlightShadows = state.m_bEnableShadows && ( pFlashlightDepthTexture != NULL );
  281. SetFlashLightColorFromState( state, pShaderAPI );
  282. BindTexture( SHADER_SAMPLER2, state.m_pSpotlightTexture, state.m_nSpotlightTextureFrame );
  283. if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() )
  284. {
  285. BindTexture( SHADER_SAMPLER7, pFlashlightDepthTexture );
  286. }
  287. }
  288. if( hasDetailTexture )
  289. {
  290. BindTexture( SHADER_SAMPLER3, DETAIL, DETAILFRAME );
  291. }
  292. if( hasBump )
  293. {
  294. if( !g_pConfig->m_bFastNoBump )
  295. {
  296. BindTexture( SHADER_SAMPLER4, BUMPMAP, BUMPFRAME );
  297. }
  298. else
  299. {
  300. pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_NORMALMAP_FLAT );
  301. }
  302. }
  303. pShaderAPI->BindStandardTexture( SHADER_SAMPLER6, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
  304. // If we don't have a texture transform, we don't have
  305. // to set vertex shader constants or run vertex shader instructions
  306. // for the texture transform.
  307. bool bHasTextureTransform =
  308. !( params[BASETEXTURETRANSFORM]->MatrixIsIdentity() &&
  309. params[BUMPTRANSFORM]->MatrixIsIdentity() );
  310. bool bVertexShaderFastPath = !bHasTextureTransform;
  311. if( params[DETAIL]->IsTexture() )
  312. {
  313. bVertexShaderFastPath = false;
  314. }
  315. if( pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0 )
  316. {
  317. bVertexShaderFastPath = false;
  318. }
  319. float color[4] = { 1.0, 1.0, 1.0, 1.0 };
  320. ComputeModulationColor( color );
  321. if( !( bVertexShaderFastPath && color[0] == 1.0f && color[1] == 1.0f && color[2] == 1.0f && color[3] == 1.0f ) )
  322. {
  323. bVertexShaderFastPath = false;
  324. s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color );
  325. if (! bSeamlessMapping)
  326. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  327. if( hasBump && !bHasDetailAlpha )
  328. {
  329. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BUMPTRANSFORM );
  330. Assert( !hasDetailTexture );
  331. }
  332. }
  333. MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode();
  334. DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 );
  335. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  336. SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, bVertexShaderFastPath );
  337. SET_DYNAMIC_VERTEX_SHADER_COMBO(
  338. LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0);
  339. SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 );
  340. bool bWriteDepthToAlpha;
  341. bool bWriteWaterFogToAlpha;
  342. if( bFullyOpaque )
  343. {
  344. bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha();
  345. bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z);
  346. AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." );
  347. }
  348. else
  349. {
  350. //can't write a special value to dest alpha if we're actually using as-intended alpha
  351. bWriteDepthToAlpha = false;
  352. bWriteWaterFogToAlpha = false;
  353. }
  354. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  355. {
  356. DECLARE_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20b );
  357. // Don't write fog to alpha if we're using translucency
  358. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha );
  359. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha );
  360. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  361. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows );
  362. SET_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20b );
  363. }
  364. else
  365. {
  366. DECLARE_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20 );
  367. // Don't write fog to alpha if we're using translucency
  368. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z) &&
  369. (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !bIsAlphaTested );
  370. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  371. SET_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20 );
  372. }
  373. // always set the transform for detail textures since I'm assuming that you'll
  374. // always have a detailscale.
  375. if( hasDetailTexture )
  376. {
  377. SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BASETEXTURETRANSFORM, DETAILSCALE );
  378. Assert( !( hasBump && !bHasDetailAlpha ) );
  379. }
  380. SetPixelShaderConstantGammaToLinear( 7, SELFILLUMTINT );
  381. float eyePos[4];
  382. pShaderAPI->GetWorldSpaceCameraPosition( eyePos );
  383. pShaderAPI->SetPixelShaderConstant( 10, eyePos, 1 );
  384. pShaderAPI->SetPixelShaderFogParams( 11 );
  385. if ( bSeamlessMapping )
  386. {
  387. float map_scale[4]={ params[SEAMLESS_SCALE]->GetFloatValue(),0,0,0};
  388. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, map_scale );
  389. }
  390. if( hasFlashlight )
  391. {
  392. VMatrix worldToTexture;
  393. const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture );
  394. // Set the flashlight attenuation factors
  395. float atten[4];
  396. atten[0] = flashlightState.m_fConstantAtten;
  397. atten[1] = flashlightState.m_fLinearAtten;
  398. atten[2] = flashlightState.m_fQuadraticAtten;
  399. atten[3] = flashlightState.m_FarZ;
  400. pShaderAPI->SetPixelShaderConstant( 20, atten, 1 );
  401. // Set the flashlight origin
  402. float pos[4];
  403. pos[0] = flashlightState.m_vecLightOrigin[0];
  404. pos[1] = flashlightState.m_vecLightOrigin[1];
  405. pos[2] = flashlightState.m_vecLightOrigin[2];
  406. pos[3] = 1.0f;
  407. pShaderAPI->SetPixelShaderConstant( 15, pos, 1 );
  408. pShaderAPI->SetPixelShaderConstant( 16, worldToTexture.Base(), 4 );
  409. }
  410. }
  411. Draw();
  412. }
  413. SHADER_DRAW
  414. {
  415. bool bHasFlashlight = UsingFlashlight( params );
  416. if ( bHasFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) )
  417. {
  418. DrawPass( params, pShaderAPI, pShaderShadow, false, vertexCompression );
  419. SHADOW_STATE
  420. {
  421. SetInitialShadowState( );
  422. }
  423. }
  424. DrawPass( params, pShaderAPI, pShaderShadow, bHasFlashlight, vertexCompression );
  425. }
  426. END_SHADER