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.

303 lines
9.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #if 0
  9. #include "particlelitgeneric_dx9_helper.h"
  10. #include "BaseVSShader.h"
  11. #include "particlelit_generic_vs30.inc"
  12. #include "particlelit_generic_ps30.inc"
  13. #include "convar.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. //-----------------------------------------------------------------------------
  17. // Initialize shader parameters
  18. //-----------------------------------------------------------------------------
  19. void InitParamsParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, ParticleLitGeneric_DX9_Vars_t &info )
  20. {
  21. // FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture
  22. Assert( info.m_nFlashlightTexture >= 0 );
  23. if ( g_pHardwareConfig->SupportsBorderColor() )
  24. {
  25. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
  26. }
  27. else
  28. {
  29. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
  30. }
  31. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  32. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  33. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  34. if( (info.m_nBumpFrame != -1) && !params[info.m_nBumpFrame]->IsDefined() )
  35. {
  36. params[info.m_nBumpFrame]->SetIntValue( 0 );
  37. }
  38. if( (info.m_nBumpmap != -1) && g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() )
  39. {
  40. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
  41. }
  42. else
  43. {
  44. CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK );
  45. }
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Initialize shader
  49. //-----------------------------------------------------------------------------
  50. void InitParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, ParticleLitGeneric_DX9_Vars_t &info )
  51. {
  52. Assert( info.m_nFlashlightTexture >= 0 );
  53. pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB );
  54. bool bIsBaseTextureTranslucent = false;
  55. if ( params[info.m_nBaseTexture]->IsDefined() )
  56. {
  57. pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );
  58. if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() )
  59. {
  60. bIsBaseTextureTranslucent = true;
  61. }
  62. }
  63. // No alpha channel in any of the textures? No self illum or envmapmask
  64. if ( !bIsBaseTextureTranslucent )
  65. {
  66. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  67. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  68. }
  69. if ( g_pConfig->UseBumpmapping() )
  70. {
  71. if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() )
  72. {
  73. pShader->LoadBumpMap( info.m_nBumpmap );
  74. SET_FLAGS2( MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL );
  75. }
  76. }
  77. // Don't alpha test if the alpha channel is used for other purposes
  78. if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
  79. {
  80. CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
  81. }
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Draws the shader
  85. //-----------------------------------------------------------------------------
  86. void DrawParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params,
  87. IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, ParticleLitGeneric_DX9_Vars_t &info )
  88. {
  89. bool hasBaseTexture = params[info.m_nBaseTexture]->IsTexture();
  90. bool hasBump = (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsTexture();
  91. bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR );
  92. bool hasVertexAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA );
  93. bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0;
  94. bool bNoFog = IS_FLAG_SET( MATERIAL_VAR_NOFOG );
  95. HDRType_t hdrType = g_pHardwareConfig->GetHDRType();
  96. BlendType_t blendType = pShader->EvaluateBlendRequirements( info.m_nBaseTexture, true );
  97. if( pShader->IsSnapshotting() )
  98. {
  99. // look at color and alphamod stuff.
  100. // Unlit generic never uses the flashlight
  101. bool hasFlashlight = CShader_IsFlag2Set( params, MATERIAL_VAR2_USE_FLASHLIGHT );
  102. bool bHalfLambert = IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT );
  103. // Alpha test: FIXME: shouldn't this be handled in CBaseVSShader::SetInitialShadowState
  104. pShaderShadow->EnableAlphaTest( bIsAlphaTested );
  105. if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f )
  106. {
  107. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() );
  108. }
  109. if( hasFlashlight )
  110. {
  111. pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true );
  112. if( bIsAlphaTested )
  113. {
  114. // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to
  115. // be the same on both the regular pass and the flashlight pass.
  116. pShaderShadow->EnableAlphaTest( false );
  117. pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL );
  118. }
  119. pShaderShadow->EnableBlending( true );
  120. pShaderShadow->EnableDepthWrites( false );
  121. }
  122. else
  123. {
  124. pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true );
  125. }
  126. unsigned int flags = VERTEX_POSITION;
  127. int userDataSize = 0;
  128. if( hasBaseTexture )
  129. {
  130. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  131. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  132. }
  133. if( hasFlashlight )
  134. {
  135. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true );
  136. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, true );
  137. userDataSize = 4; // tangent S
  138. }
  139. if( hasBump )
  140. {
  141. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  142. userDataSize = 4; // tangent S
  143. // Normalizing cube map
  144. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true );
  145. }
  146. if( hasVertexColor || hasVertexAlpha )
  147. {
  148. flags |= VERTEX_COLOR;
  149. }
  150. pShaderShadow->EnableSRGBWrite( true );
  151. // texcoord0 : base texcoord
  152. int pTexCoordCount[2] = { 2, 3 };
  153. pShaderShadow->VertexShaderVertexFormat(
  154. flags, 2, pTexCoordCount, 0, userDataSize );
  155. DECLARE_STATIC_VERTEX_SHADER( particlelit_generic_vs30 );
  156. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  157. SET_STATIC_VERTEX_SHADER( particlelit_generic_vs30 );
  158. DECLARE_STATIC_PIXEL_SHADER( particlelit_generic_ps30 );
  159. SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  160. // SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight );
  161. SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, hdrType );
  162. SET_STATIC_PIXEL_SHADER( particlelit_generic_ps30 );
  163. if( hasFlashlight )
  164. {
  165. pShader->FogToBlack();
  166. }
  167. else
  168. {
  169. pShader->DefaultFog();
  170. }
  171. // HACK HACK HACK - enable alpha writes all the time so that we have them for
  172. // underwater stuff
  173. if( blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested )
  174. {
  175. pShaderShadow->EnableAlphaWrites( true );
  176. }
  177. }
  178. else
  179. {
  180. bool hasFlashlight = pShaderAPI->InFlashlightMode();
  181. if( hasBaseTexture )
  182. {
  183. pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame );
  184. }
  185. if( !g_pConfig->m_bFastNoBump )
  186. {
  187. if( hasBump )
  188. {
  189. pShader->BindTexture( SHADER_SAMPLER3, info.m_nBumpmap, info.m_nBumpFrame );
  190. }
  191. }
  192. else
  193. {
  194. if( hasBump )
  195. {
  196. pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALMAP_FLAT );
  197. }
  198. }
  199. if( hasFlashlight )
  200. {
  201. Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 );
  202. pShader->BindTexture( SHADER_SAMPLER7, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame );
  203. }
  204. LightState_t lightState = { 0, false, false };
  205. if( !hasFlashlight )
  206. pShaderAPI->GetDX9LightState( &lightState );
  207. MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode();
  208. // int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0;
  209. DECLARE_DYNAMIC_VERTEX_SHADER( particlelit_generic_vs30 );
  210. SET_DYNAMIC_VERTEX_SHADER( particlelit_generic_vs30 );
  211. DECLARE_DYNAMIC_PIXEL_SHADER( particlelit_generic_ps30 );
  212. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  213. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  214. SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  215. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z &&
  216. blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested );
  217. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  218. SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, pShader->IsHDREnabled() );
  219. SET_DYNAMIC_PIXEL_SHADER( particlelit_generic_ps30 );
  220. pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform );
  221. if( hasBump )
  222. {
  223. pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBumpTransform );
  224. }
  225. if( hasBump )
  226. {
  227. pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
  228. pShaderAPI->SetPixelShaderStateAmbientLightCube( 5 );
  229. pShaderAPI->CommitPixelShaderLighting( 13 );
  230. }
  231. float eyePos[4];
  232. pShaderAPI->GetWorldSpaceCameraPosition( eyePos );
  233. pShaderAPI->SetPixelShaderConstant( 20, eyePos, 1 );
  234. pShaderAPI->SetPixelShaderFogParams( 21 );
  235. // flashlightfixme: put this in common code.
  236. if( hasFlashlight )
  237. {
  238. VMatrix worldToTexture;
  239. const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture );
  240. // Set the flashlight attenuation factors
  241. float atten[4];
  242. atten[0] = flashlightState.m_fConstantAtten;
  243. atten[1] = flashlightState.m_fLinearAtten;
  244. atten[2] = flashlightState.m_fQuadraticAtten;
  245. atten[3] = flashlightState.m_FarZ;
  246. pShaderAPI->SetPixelShaderConstant( 22, atten, 1 );
  247. // Set the flashlight origin
  248. float pos[4];
  249. pos[0] = flashlightState.m_vecLightOrigin[0];
  250. pos[1] = flashlightState.m_vecLightOrigin[1];
  251. pos[2] = flashlightState.m_vecLightOrigin[2];
  252. pos[3] = 1.0f;
  253. pShaderAPI->SetPixelShaderConstant( 23, pos, 1 );
  254. pShaderAPI->SetPixelShaderConstant( 24, worldToTexture.Base(), 4 );
  255. }
  256. }
  257. pShader->Draw();
  258. }
  259. // Commenting out this entire file
  260. #endif