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.

93 lines
2.7 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 'card' beams on lamps, this material fades the sprite out
  17. // as the viewer nears, so that the viewer can't see that the effect is really
  18. // a card.
  19. //-----------------------------------------------------------------------------
  20. class CLampBeamProxy : public CEntityMaterialProxy
  21. {
  22. public:
  23. CLampBeamProxy( void );
  24. virtual ~CLampBeamProxy( void );
  25. virtual bool Init( IMaterial *pMaterial, KeyValues* pKeyValues );
  26. virtual void OnBind( C_BaseEntity *pC_BaseEntity );
  27. virtual IMaterial * GetMaterial();
  28. private:
  29. IMaterialVar *m_pFadeValue;
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. CLampBeamProxy::CLampBeamProxy( void )
  35. {
  36. m_pFadeValue = NULL;
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose:
  40. //-----------------------------------------------------------------------------
  41. CLampBeamProxy::~CLampBeamProxy( void )
  42. {
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose: Get pointer to the color value
  46. // Input : *pMaterial -
  47. //-----------------------------------------------------------------------------
  48. bool CLampBeamProxy::Init( IMaterial *pMaterial, KeyValues* pKeyValues )
  49. {
  50. assert( pMaterial );
  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 CLampBeamProxy::OnBind( C_BaseEntity *pEnt )
  63. {
  64. if ( !m_pFadeValue )
  65. return;
  66. Vector vecLocal = pEnt->GetAbsOrigin() - CurrentViewOrigin();
  67. VectorNormalize( vecLocal );
  68. float fade = 1.0 - fabs( vecLocal.z );
  69. m_pFadeValue->SetFloatValue( fade );
  70. }
  71. IMaterial *CLampBeamProxy::GetMaterial()
  72. {
  73. if ( !m_pFadeValue )
  74. return NULL;
  75. return m_pFadeValue->GetOwningMaterial();
  76. }
  77. EXPOSE_MATERIAL_PROXY( CLampBeamProxy, lampbeam );