Counter Strike : Global Offensive Source Code
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.

636 lines
23 KiB

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