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.

111 lines
3.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "smoke_fog_overlay.h"
  10. #include "materialsystem/imaterial.h"
  11. #include "materialsystem/imesh.h"
  12. #include "view.h"
  13. #include "precache_register.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. static IMaterial *g_pSmokeFogMaterial = NULL;
  17. float g_SmokeFogOverlayAlpha;
  18. Vector g_SmokeFogOverlayColor;
  19. PRECACHE_REGISTER_BEGIN( GLOBAL, PrecacheSmokeFogOverlay )
  20. PRECACHE( MATERIAL, "particle/screenspace_fog" )
  21. PRECACHE_REGISTER_END()
  22. void InitSmokeFogOverlay()
  23. {
  24. TermSmokeFogOverlay();
  25. g_SmokeFogOverlayAlpha = 0;
  26. g_SmokeFogOverlayColor.Init( 0.0f, 0.0f, 0.0f );
  27. if(materials)
  28. {
  29. g_pSmokeFogMaterial = materials->FindMaterial( "particle/screenspace_fog", TEXTURE_GROUP_CLIENT_EFFECTS );
  30. if(g_pSmokeFogMaterial)
  31. g_pSmokeFogMaterial->IncrementReferenceCount();
  32. }
  33. }
  34. void TermSmokeFogOverlay()
  35. {
  36. if(g_pSmokeFogMaterial)
  37. {
  38. g_pSmokeFogMaterial->DecrementReferenceCount();
  39. g_pSmokeFogMaterial = NULL;
  40. }
  41. }
  42. void DrawSmokeFogOverlay()
  43. {
  44. if(g_SmokeFogOverlayAlpha == 0 || !g_pSmokeFogMaterial || !materials)
  45. return;
  46. CMatRenderContextPtr pRenderContext( materials );
  47. PIXEVENT( pRenderContext, "DrawSmokeFogOverlay()" );
  48. pRenderContext->MatrixMode( MATERIAL_PROJECTION );
  49. pRenderContext->LoadIdentity();
  50. pRenderContext->Ortho( 0, 0, 1, 1, -99999, 99999 );
  51. pRenderContext->MatrixMode( MATERIAL_VIEW );
  52. pRenderContext->LoadIdentity();
  53. pRenderContext->MatrixMode( MATERIAL_MODEL );
  54. pRenderContext->LoadIdentity();
  55. IMesh* pMesh = pRenderContext->GetDynamicMesh( false, NULL, NULL, g_pSmokeFogMaterial );
  56. CMeshBuilder meshBuilder;
  57. static float dist = 10;
  58. // g_SmokeFogOverlayColor is the sum total of all the smoke colors weighted by their alpha contribution and added.
  59. // Dividing by the g_SmokeFogOverlayAlpha gives us the weighted average color of all the smoke plumes that are influencing
  60. // the fog overlay.
  61. Vector vColor = g_SmokeFogOverlayColor/* / g_SmokeFogOverlayAlpha*/;
  62. vColor.x = MIN(MAX(vColor.x, 0), 1);
  63. vColor.y = MIN(MAX(vColor.y, 0), 1);
  64. vColor.z = MIN(MAX(vColor.z, 0), 1);
  65. float alpha = MIN(MAX(g_SmokeFogOverlayAlpha, 0), 1);
  66. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  67. meshBuilder.Position3f( 0, 0, dist );
  68. meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha );
  69. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  70. meshBuilder.AdvanceVertex();
  71. meshBuilder.Position3f( 0, 1, dist );
  72. meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha );
  73. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  74. meshBuilder.AdvanceVertex();
  75. meshBuilder.Position3f( 1, 1, dist );
  76. meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha );
  77. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  78. meshBuilder.AdvanceVertex();
  79. meshBuilder.Position3f( 1, 0, dist );
  80. meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha );
  81. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  82. meshBuilder.AdvanceVertex();
  83. meshBuilder.End();
  84. pMesh->Draw();
  85. }