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.

640 lines
23 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "vertexlitgeneric_dx9_helper.h"
  10. #include "vortwarp_vs20.inc"
  11. #include "vortwarp_ps20.inc"
  12. #include "vortwarp_ps20b.inc"
  13. #include "convar.h"
  14. #ifndef _X360
  15. #include "vortwarp_vs30.inc"
  16. #include "vortwarp_ps30.inc"
  17. #endif
  18. DEFINE_FALLBACK_SHADER( VortWarp, VortWarp_dx9 )
  19. extern ConVar r_flashlight_version2;
  20. struct VortWarp_DX9_Vars_t : public VertexLitGeneric_DX9_Vars_t
  21. {
  22. VortWarp_DX9_Vars_t() { memset( this, 0xFF, sizeof(*this) ); }
  23. int m_nEntityOrigin;
  24. int m_nWarpParam;
  25. int m_nFlowMap;
  26. int m_nSelfIllumMap;
  27. int m_nUnlit;
  28. };
  29. //-----------------------------------------------------------------------------
  30. // Draws the shader
  31. //-----------------------------------------------------------------------------
  32. void DrawVortWarp_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  33. IShaderShadow* pShaderShadow, bool bVertexLitGeneric, bool hasFlashlight, VortWarp_DX9_Vars_t &info, VertexCompressionType_t vertexCompression )
  34. {
  35. bool hasBaseTexture = params[info.m_nBaseTexture]->IsTexture();
  36. bool hasBump = (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsTexture();
  37. bool hasDetailTexture = !hasBump && params[info.m_nDetail]->IsTexture();
  38. bool hasNormalMapAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK );
  39. bool hasVertexColor = bVertexLitGeneric ? false : IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR );
  40. bool hasVertexAlpha = bVertexLitGeneric ? false : IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA );
  41. bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0;
  42. bool hasSelfIllumInEnvMapMask =
  43. ( info.m_nSelfIllumEnvMapMask_Alpha != -1 ) &&
  44. ( params[info.m_nSelfIllumEnvMapMask_Alpha]->GetFloatValue() != 0.0 ) ;
  45. bool bHasFlowMap = ( info.m_nFlowMap != -1 ) && params[info.m_nFlowMap]->IsTexture();
  46. bool bHasSelfIllumMap = ( info.m_nSelfIllumMap != -1 ) && params[info.m_nSelfIllumMap]->IsTexture();
  47. BlendType_t blendType;
  48. if ( params[info.m_nBaseTexture]->IsTexture() )
  49. {
  50. blendType = pShader->EvaluateBlendRequirements( info.m_nBaseTexture, true );
  51. }
  52. else
  53. {
  54. blendType = pShader->EvaluateBlendRequirements( info.m_nEnvmapMask, false );
  55. }
  56. if( pShader->IsSnapshotting() )
  57. {
  58. // look at color and alphamod stuff.
  59. // Unlit generic never uses the flashlight
  60. bool hasEnvmap = !hasFlashlight && params[info.m_nEnvmap]->IsTexture();
  61. bool hasEnvmapMask = (hasSelfIllumInEnvMapMask || !hasFlashlight) &&
  62. params[info.m_nEnvmapMask]->IsTexture();
  63. bool bHasNormal = bVertexLitGeneric || hasEnvmap;
  64. if( hasFlashlight )
  65. {
  66. hasEnvmapMask = false;
  67. }
  68. bool bHalfLambert = IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT );
  69. // Alpha test: FIXME: shouldn't this be handled in CBaseVSShader::SetInitialShadowState
  70. pShaderShadow->EnableAlphaTest( bIsAlphaTested );
  71. if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f )
  72. {
  73. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() );
  74. }
  75. if( hasFlashlight )
  76. {
  77. if (params[info.m_nBaseTexture]->IsTexture())
  78. {
  79. pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true );
  80. }
  81. else
  82. {
  83. pShader->SetAdditiveBlendingShadowState( info.m_nEnvmapMask, false );
  84. }
  85. if( bIsAlphaTested )
  86. {
  87. // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to
  88. // be the same on both the regular pass and the flashlight pass.
  89. pShaderShadow->EnableAlphaTest( false );
  90. pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL );
  91. }
  92. pShaderShadow->EnableBlending( true );
  93. pShaderShadow->EnableDepthWrites( false );
  94. }
  95. else
  96. {
  97. if (params[info.m_nBaseTexture]->IsTexture())
  98. {
  99. pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true );
  100. }
  101. else
  102. {
  103. pShader->SetDefaultBlendingShadowState( info.m_nEnvmapMask, false );
  104. }
  105. }
  106. unsigned int flags = VERTEX_POSITION;
  107. int nTexCoordCount = 1; // texcoord0 : base texcoord
  108. int userDataSize = 0;
  109. if( bHasNormal )
  110. {
  111. flags |= VERTEX_NORMAL;
  112. }
  113. if( hasBaseTexture )
  114. {
  115. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  116. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  117. }
  118. if( hasEnvmap )
  119. {
  120. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  121. if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE )
  122. {
  123. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  124. }
  125. }
  126. if( hasFlashlight )
  127. {
  128. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true );
  129. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  130. userDataSize = 4; // tangent S
  131. }
  132. if( hasDetailTexture )
  133. {
  134. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  135. }
  136. if( hasBump )
  137. {
  138. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  139. userDataSize = 4; // tangent S
  140. // Normalizing cube map
  141. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true );
  142. }
  143. if( hasEnvmapMask )
  144. {
  145. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  146. }
  147. if( hasVertexColor || hasVertexAlpha )
  148. {
  149. flags |= VERTEX_COLOR;
  150. }
  151. pShaderShadow->EnableSRGBWrite( true );
  152. if( bHasSelfIllumMap )
  153. {
  154. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true );
  155. }
  156. if( bHasFlowMap )
  157. {
  158. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  159. }
  160. // This shader supports compressed vertices, so OR in that flag:
  161. flags |= VERTEX_FORMAT_COMPRESSED;
  162. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  163. Assert( hasBump );
  164. #ifndef _X360
  165. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  166. #endif
  167. {
  168. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  169. DECLARE_STATIC_VERTEX_SHADER( vortwarp_vs20 );
  170. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  171. SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow );
  172. SET_STATIC_VERTEX_SHADER( vortwarp_vs20 );
  173. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  174. {
  175. DECLARE_STATIC_PIXEL_SHADER( vortwarp_ps20b );
  176. SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, hasBaseTexture );
  177. SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap );
  178. SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, !params[info.m_nUnlit]->GetIntValue() );
  179. SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask );
  180. SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  181. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight );
  182. SET_STATIC_PIXEL_SHADER_COMBO( TRANSLUCENT, blendType == BT_BLEND );
  183. SET_STATIC_PIXEL_SHADER( vortwarp_ps20b );
  184. }
  185. else
  186. {
  187. DECLARE_STATIC_PIXEL_SHADER( vortwarp_ps20 );
  188. SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, hasBaseTexture );
  189. SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap );
  190. SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, !params[info.m_nUnlit]->GetIntValue() );
  191. SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask );
  192. SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  193. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight );
  194. SET_STATIC_PIXEL_SHADER_COMBO( TRANSLUCENT, blendType == BT_BLEND );
  195. SET_STATIC_PIXEL_SHADER( vortwarp_ps20 );
  196. }
  197. }
  198. #ifndef _X360
  199. else
  200. {
  201. // The vertex shader uses the vertex id stream
  202. SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
  203. DECLARE_STATIC_VERTEX_SHADER( vortwarp_vs30 );
  204. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  205. SET_STATIC_VERTEX_SHADER( vortwarp_vs30 );
  206. DECLARE_STATIC_PIXEL_SHADER( vortwarp_ps30 );
  207. SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, hasBaseTexture );
  208. SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap );
  209. SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, !params[info.m_nUnlit]->GetIntValue() );
  210. SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask );
  211. SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  212. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight );
  213. SET_STATIC_PIXEL_SHADER_COMBO( TRANSLUCENT, blendType == BT_BLEND );
  214. SET_STATIC_PIXEL_SHADER( vortwarp_ps30 );
  215. }
  216. #endif
  217. if( hasFlashlight )
  218. {
  219. pShader->FogToBlack();
  220. }
  221. else
  222. {
  223. pShader->DefaultFog();
  224. }
  225. if( blendType == BT_BLEND )
  226. {
  227. pShaderShadow->EnableBlending( true );
  228. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  229. pShaderShadow->EnableAlphaWrites( false );
  230. }
  231. else
  232. {
  233. pShaderShadow->EnableAlphaWrites( true );
  234. }
  235. }
  236. else
  237. {
  238. bool hasEnvmap = !hasFlashlight && params[info.m_nEnvmap]->IsTexture();
  239. bool hasEnvmapMask = !hasFlashlight && params[info.m_nEnvmapMask]->IsTexture();
  240. if( hasBaseTexture )
  241. {
  242. pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame );
  243. }
  244. if( hasEnvmap )
  245. {
  246. pShader->BindTexture( SHADER_SAMPLER1, info.m_nEnvmap, info.m_nEnvmapFrame );
  247. }
  248. if( hasDetailTexture )
  249. {
  250. pShader->BindTexture( SHADER_SAMPLER2, info.m_nDetail, info.m_nDetailFrame );
  251. }
  252. if( !g_pConfig->m_bFastNoBump )
  253. {
  254. if( hasBump )
  255. {
  256. pShader->BindTexture( SHADER_SAMPLER3, info.m_nBumpmap, info.m_nBumpFrame );
  257. }
  258. }
  259. else
  260. {
  261. if( hasBump )
  262. {
  263. pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALMAP_FLAT );
  264. }
  265. }
  266. if( hasEnvmapMask )
  267. {
  268. pShader->BindTexture( SHADER_SAMPLER4, info.m_nEnvmapMask, info.m_nEnvmapMaskFrame );
  269. }
  270. if( hasFlashlight )
  271. {
  272. Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 );
  273. pShader->BindTexture( SHADER_SAMPLER7, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame );
  274. VMatrix worldToTexture;
  275. ITexture *pFlashlightDepthTexture;
  276. FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture );
  277. SetFlashLightColorFromState( state, pShaderAPI );
  278. }
  279. // Set up light combo state
  280. LightState_t lightState = {0, false, false};
  281. if ( bVertexLitGeneric && !hasFlashlight )
  282. {
  283. pShaderAPI->GetDX9LightState( &lightState );
  284. }
  285. MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode();
  286. int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0;
  287. int numBones = pShaderAPI->GetCurrentNumBones();
  288. Assert( hasBump );
  289. #ifndef _X360
  290. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  291. #endif
  292. {
  293. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  294. DECLARE_DYNAMIC_VERTEX_SHADER( vortwarp_vs20 );
  295. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex );
  296. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
  297. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  298. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights );
  299. SET_DYNAMIC_VERTEX_SHADER( vortwarp_vs20 );
  300. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  301. {
  302. DECLARE_DYNAMIC_PIXEL_SHADER( vortwarp_ps20b );
  303. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  304. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  305. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z &&
  306. blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested );
  307. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  308. float warpParam = params[info.m_nWarpParam]->GetFloatValue();
  309. // float selfIllumTint = params[info.m_nSelfIllumTint]->GetFloatValue();
  310. // DevMsg( 1, "warpParam: %f %f\n", warpParam, selfIllumTint );
  311. SET_DYNAMIC_PIXEL_SHADER_COMBO( WARPINGIN, warpParam > 0.0f && warpParam < 1.0f );
  312. SET_DYNAMIC_PIXEL_SHADER( vortwarp_ps20b );
  313. }
  314. else
  315. {
  316. DECLARE_DYNAMIC_PIXEL_SHADER( vortwarp_ps20 );
  317. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  318. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  319. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z &&
  320. blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested );
  321. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  322. float warpParam = params[info.m_nWarpParam]->GetFloatValue();
  323. // float selfIllumTint = params[info.m_nSelfIllumTint]->GetFloatValue();
  324. // DevMsg( 1, "warpParam: %f %f\n", warpParam, selfIllumTint );
  325. SET_DYNAMIC_PIXEL_SHADER_COMBO( WARPINGIN, warpParam > 0.0f && warpParam < 1.0f );
  326. SET_DYNAMIC_PIXEL_SHADER( vortwarp_ps20 );
  327. }
  328. }
  329. #ifndef _X360
  330. else
  331. {
  332. pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 );
  333. DECLARE_DYNAMIC_VERTEX_SHADER( vortwarp_vs30 );
  334. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex );
  335. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
  336. SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() );
  337. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  338. SET_DYNAMIC_VERTEX_SHADER( vortwarp_vs30 );
  339. DECLARE_DYNAMIC_PIXEL_SHADER( vortwarp_ps30 );
  340. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  341. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  342. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z &&
  343. blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested );
  344. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  345. float warpParam = params[info.m_nWarpParam]->GetFloatValue();
  346. // float selfIllumTint = params[info.m_nSelfIllumTint]->GetFloatValue();
  347. // DevMsg( 1, "warpParam: %f %f\n", warpParam, selfIllumTint );
  348. SET_DYNAMIC_PIXEL_SHADER_COMBO( WARPINGIN, warpParam > 0.0f && warpParam < 1.0f );
  349. SET_DYNAMIC_PIXEL_SHADER( vortwarp_ps30 );
  350. }
  351. #endif
  352. pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform );
  353. if( hasDetailTexture )
  354. {
  355. pShader->SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBaseTextureTransform, info.m_nDetailScale );
  356. Assert( !hasBump );
  357. }
  358. if( hasBump )
  359. {
  360. pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBumpTransform );
  361. Assert( !hasDetailTexture );
  362. }
  363. if( hasEnvmapMask )
  364. {
  365. pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nEnvmapMaskTransform );
  366. }
  367. if( hasEnvmap )
  368. {
  369. pShader->SetEnvMapTintPixelShaderDynamicState( 0, info.m_nEnvmapTint, -1, true );
  370. }
  371. if( ( info.m_nHDRColorScale != -1 ) && pShader->IsHDREnabled() )
  372. {
  373. pShader->SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( 1, params[info.m_nHDRColorScale]->GetFloatValue() );
  374. }
  375. else
  376. {
  377. pShader->SetModulationPixelShaderDynamicState_LinearColorSpace( 1 );
  378. }
  379. pShader->SetPixelShaderConstant( 2, info.m_nEnvmapContrast );
  380. pShader->SetPixelShaderConstant( 3, info.m_nEnvmapSaturation );
  381. pShader->SetPixelShaderConstant( 4, info.m_nSelfIllumTint );
  382. pShader->SetAmbientCubeDynamicStateVertexShader();
  383. if( hasBump )
  384. {
  385. pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
  386. pShaderAPI->SetPixelShaderStateAmbientLightCube( 5 );
  387. pShaderAPI->CommitPixelShaderLighting( 13 );
  388. }
  389. if( bHasSelfIllumMap )
  390. {
  391. pShader->BindTexture( SHADER_SAMPLER6, info.m_nSelfIllumMap, -1 );
  392. }
  393. if( bHasFlowMap )
  394. {
  395. pShader->BindTexture( SHADER_SAMPLER2, info.m_nFlowMap, -1 );
  396. }
  397. float eyePos[4];
  398. pShaderAPI->GetWorldSpaceCameraPosition( eyePos );
  399. pShaderAPI->SetPixelShaderConstant( 20, eyePos, 1 );
  400. pShaderAPI->SetPixelShaderFogParams( 21 );
  401. // dynamic drawing code that extends vertexlitgeneric
  402. float curTime = params[info.m_nWarpParam]->GetFloatValue();
  403. float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime };
  404. Assert( params[info.m_nEntityOrigin]->IsDefined() );
  405. params[info.m_nEntityOrigin]->GetVecValue( timeVec, 3 );
  406. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, timeVec, 1 );
  407. curTime = pShaderAPI->CurrentTime();
  408. timeVec[0] = curTime;
  409. timeVec[1] = curTime;
  410. timeVec[2] = curTime;
  411. timeVec[3] = curTime;
  412. pShaderAPI->SetPixelShaderConstant( 22, timeVec, 1 );
  413. // flashlightfixme: put this in common code.
  414. if( hasFlashlight )
  415. {
  416. VMatrix worldToTexture;
  417. const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture );
  418. // Set the flashlight attenuation factors
  419. float atten[4];
  420. atten[0] = flashlightState.m_fConstantAtten;
  421. atten[1] = flashlightState.m_fLinearAtten;
  422. atten[2] = flashlightState.m_fQuadraticAtten;
  423. atten[3] = flashlightState.m_FarZ;
  424. pShaderAPI->SetPixelShaderConstant( 22, atten, 1 );
  425. // Set the flashlight origin
  426. float pos[4];
  427. pos[0] = flashlightState.m_vecLightOrigin[0];
  428. pos[1] = flashlightState.m_vecLightOrigin[1];
  429. pos[2] = flashlightState.m_vecLightOrigin[2];
  430. pos[3] = 1.0f;
  431. pShaderAPI->SetPixelShaderConstant( 23, pos, 1 );
  432. pShaderAPI->SetPixelShaderConstant( 24, worldToTexture.Base(), 4 );
  433. }
  434. }
  435. pShader->Draw();
  436. }
  437. BEGIN_VS_SHADER( VortWarp_DX9,
  438. "Help for VortWarp_DX9" )
  439. BEGIN_SHADER_PARAMS
  440. SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" )
  441. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  442. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  443. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  444. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
  445. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  446. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" )
  447. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  448. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  449. SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" )
  450. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  451. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" )
  452. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  453. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  454. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  455. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  456. SHADER_PARAM( SELFILLUM_ENVMAPMASK_ALPHA, SHADER_PARAM_TYPE_FLOAT,"0.0","defines that self illum value comes from env map mask alpha" )
  457. // Debugging term for visualizing ambient data on its own
  458. SHADER_PARAM( AMBIENTONLY, SHADER_PARAM_TYPE_INTEGER, "0", "Control drawing of non-ambient light ()" )
  459. // hack hack hack
  460. SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" )
  461. SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" )
  462. SHADER_PARAM( FLOWMAP, SHADER_PARAM_TYPE_TEXTURE, "", "flow map" )
  463. SHADER_PARAM( SELFILLUMMAP, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" )
  464. SHADER_PARAM( UNLIT, SHADER_PARAM_TYPE_BOOL, "", "" )
  465. SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" )
  466. SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" )
  467. SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" )
  468. SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" )
  469. SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "warp specular term" )
  470. SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" )
  471. SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" )
  472. SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" )
  473. SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" )
  474. END_SHADER_PARAMS
  475. void SetupVars( VortWarp_DX9_Vars_t& info )
  476. {
  477. info.m_nBaseTexture = BASETEXTURE;
  478. info.m_nBaseTextureFrame = FRAME;
  479. info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
  480. info.m_nAlbedo = ALBEDO;
  481. info.m_nSelfIllumTint = SELFILLUMTINT;
  482. info.m_nDetail = DETAIL;
  483. info.m_nDetailFrame = DETAILFRAME;
  484. info.m_nDetailScale = DETAILSCALE;
  485. info.m_nEnvmap = ENVMAP;
  486. info.m_nEnvmapFrame = ENVMAPFRAME;
  487. info.m_nEnvmapMask = ENVMAPMASK;
  488. info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
  489. info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
  490. info.m_nEnvmapTint = ENVMAPTINT;
  491. info.m_nBumpmap = BUMPMAP;
  492. info.m_nBumpFrame = BUMPFRAME;
  493. info.m_nBumpTransform = BUMPTRANSFORM;
  494. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  495. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  496. info.m_nAlphaTestReference = -1;
  497. info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
  498. info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
  499. info.m_nSelfIllumEnvMapMask_Alpha = SELFILLUM_ENVMAPMASK_ALPHA;
  500. info.m_nAmbientOnly = AMBIENTONLY;
  501. info.m_nEntityOrigin = ENTITYORIGIN;
  502. info.m_nWarpParam = WARPPARAM;
  503. info.m_nFlowMap = FLOWMAP;
  504. info.m_nSelfIllumMap = SELFILLUMMAP;
  505. info.m_nUnlit = UNLIT;
  506. info.m_nPhongExponent = PHONGEXPONENT;
  507. info.m_nPhongExponentTexture = PHONGEXPONENTTEXTURE;
  508. info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE;
  509. info.m_nPhongWarpTexture = PHONGWARPTEXTURE;
  510. info.m_nPhongBoost = PHONGBOOST;
  511. info.m_nPhongFresnelRanges = PHONGFRESNELRANGES;
  512. info.m_nPhong = PHONG;
  513. }
  514. SHADER_INIT_PARAMS()
  515. {
  516. VortWarp_DX9_Vars_t vars;
  517. if( !params[BUMPMAP]->IsDefined() )
  518. {
  519. params[BUMPMAP]->SetStringValue( "dev/flat_normal" );
  520. }
  521. SetupVars( vars );
  522. if( !params[UNLIT]->IsDefined() )
  523. {
  524. params[UNLIT]->SetIntValue( 0 );
  525. }
  526. if( !params[SELFILLUMTINT]->IsDefined() )
  527. {
  528. params[SELFILLUMTINT]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  529. }
  530. InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, true, vars );
  531. }
  532. SHADER_FALLBACK
  533. {
  534. if (g_pHardwareConfig->GetDXSupportLevel() < 90)
  535. return "vortwarp_DX8";
  536. return 0;
  537. }
  538. SHADER_INIT
  539. {
  540. VortWarp_DX9_Vars_t vars;
  541. SetupVars( vars );
  542. InitVertexLitGeneric_DX9( this, params, true, vars );
  543. if( params[FLOWMAP]->IsDefined() )
  544. {
  545. LoadTexture( FLOWMAP );
  546. }
  547. if( params[SELFILLUMMAP]->IsDefined() )
  548. {
  549. LoadTexture( SELFILLUMMAP );
  550. }
  551. }
  552. SHADER_DRAW
  553. {
  554. VortWarp_DX9_Vars_t vars;
  555. SetupVars( vars );
  556. // UGH!!! FIXME!!!!! Should fix VertexlitGeneric_dx9_helper so that you
  557. // can override the vertex shader/pixel shader used (along with the combo vars).
  558. bool bHasFlashlight = UsingFlashlight( params );
  559. if ( bHasFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) )
  560. {
  561. DrawVortWarp_DX9( this, params, pShaderAPI, pShaderShadow, true, false, vars, vertexCompression );
  562. SHADOW_STATE
  563. {
  564. SetInitialShadowState();
  565. }
  566. }
  567. DrawVortWarp_DX9( this, params, pShaderAPI, pShaderShadow, true, bHasFlashlight, vars, vertexCompression );
  568. }
  569. END_SHADER