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.

105 lines
2.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "proxyentity.h"
  9. #include "materialsystem/imaterialvar.h"
  10. #include "materialsystem/imaterial.h"
  11. #include "view.h"
  12. #include "imaterialproxydict.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Used for halos on lamps, this material fades the sprite IN
  17. // as the viewer nears.
  18. //-----------------------------------------------------------------------------
  19. class CLampHaloProxy : public CEntityMaterialProxy
  20. {
  21. public:
  22. CLampHaloProxy( void );
  23. virtual ~CLampHaloProxy( void );
  24. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  25. virtual void OnBind( C_BaseEntity *pC_BaseEntity );
  26. virtual IMaterial * GetMaterial();
  27. private:
  28. IMaterialVar *m_pFadeValue;
  29. };
  30. //-----------------------------------------------------------------------------
  31. // Purpose:
  32. //-----------------------------------------------------------------------------
  33. CLampHaloProxy::CLampHaloProxy( void )
  34. {
  35. m_pFadeValue = NULL;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. //-----------------------------------------------------------------------------
  40. CLampHaloProxy::~CLampHaloProxy( void )
  41. {
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Get pointer to the color value
  45. // Input : *pMaterial -
  46. //-----------------------------------------------------------------------------
  47. bool CLampHaloProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  48. {
  49. assert( pMaterial );
  50. // Get pointers to material vars.
  51. // Need to get the color variable.
  52. bool found;
  53. m_pFadeValue = pMaterial->FindVar( "$alpha", &found );
  54. pMaterial->SetMaterialVarFlag( MATERIAL_VAR_ALPHA_MODIFIED_BY_PROXY, true );
  55. return found;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. // Input : *pC_BaseEntity -
  60. //-----------------------------------------------------------------------------
  61. #define FADE_DIST 150
  62. void CLampHaloProxy::OnBind( C_BaseEntity *pEnt )
  63. {
  64. if ( !m_pFadeValue )
  65. return;
  66. Vector vecLocal = pEnt->GetAbsOrigin() - CurrentViewOrigin();
  67. VectorNormalize( vecLocal );
  68. float fade = fabs( vecLocal.z );
  69. // I hate these magic numbers here, will have to revise
  70. // (sjb)
  71. if( fade < 0.25 )
  72. {
  73. fade = 0.0;
  74. }
  75. else
  76. {
  77. fade = MIN( (fade - 0.25) * 1.35, 1.0f );
  78. }
  79. m_pFadeValue->SetFloatValue( fade );
  80. }
  81. IMaterial *CLampHaloProxy::GetMaterial()
  82. {
  83. if ( !m_pFadeValue )
  84. return NULL;
  85. return m_pFadeValue->GetOwningMaterial();
  86. }
  87. EXPOSE_MATERIAL_PROXY( CLampHaloProxy, lamphalo );