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.

78 lines
2.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: This module implements all the proxies used by the particle systems.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "particlemgr.h"
  9. #include "materialsystem/imaterialproxy.h"
  10. #include "materialsystem/imaterialvar.h"
  11. #include "imaterialproxydict.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. // ------------------------------------------------------------------------ //
  15. // ParticleSphereProxy
  16. // ------------------------------------------------------------------------ //
  17. class ParticleSphereProxy : public IMaterialProxy
  18. {
  19. // IMaterialProxy overrides.
  20. public:
  21. ParticleSphereProxy()
  22. {
  23. }
  24. virtual ~ParticleSphereProxy()
  25. {
  26. }
  27. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  28. {
  29. m_pLightPosition = pMaterial->FindVar( "$light_position", NULL, false );
  30. m_pLightColor = pMaterial->FindVar( "$light_color", NULL, false );
  31. return true;
  32. }
  33. virtual void OnBind( void *pvParticleMgr )
  34. {
  35. if( !pvParticleMgr )
  36. return;
  37. CParticleMgr *pMgr = (CParticleMgr*)pvParticleMgr;
  38. CParticleLightInfo info;
  39. pMgr->GetDirectionalLightInfo( info );
  40. // Transform the light into camera space.
  41. Vector vTransformedPos = pMgr->GetModelView() * info.m_vPos;
  42. if ( m_pLightPosition )
  43. m_pLightPosition->SetVecValue( vTransformedPos.Base(), 3 );
  44. if ( m_pLightColor )
  45. {
  46. Vector vTotalColor = info.m_vColor * info.m_flIntensity;
  47. m_pLightColor->SetVecValue( vTotalColor.Base(), 3 );
  48. }
  49. }
  50. virtual void Release( void ) { delete this; }
  51. virtual IMaterial *GetMaterial()
  52. {
  53. IMaterialVar *pVar = m_pLightPosition ? m_pLightPosition : m_pLightColor;
  54. if ( !pVar )
  55. return NULL;
  56. return pVar->GetOwningMaterial();
  57. }
  58. private:
  59. IMaterialVar *m_pLightPosition;
  60. IMaterialVar *m_pLightColor;
  61. };
  62. EXPOSE_MATERIAL_PROXY( ParticleSphereProxy, ParticleSphereProxy );