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.

77 lines
2.0 KiB

  1. //========= Copyright 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. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. // ------------------------------------------------------------------------ //
  14. // ParticleSphereProxy
  15. // ------------------------------------------------------------------------ //
  16. class ParticleSphereProxy : public IMaterialProxy
  17. {
  18. // IMaterialProxy overrides.
  19. public:
  20. ParticleSphereProxy()
  21. {
  22. }
  23. virtual ~ParticleSphereProxy()
  24. {
  25. }
  26. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  27. {
  28. m_pLightPosition = pMaterial->FindVar( "$light_position", NULL, false );
  29. m_pLightColor = pMaterial->FindVar( "$light_color", NULL, false );
  30. return true;
  31. }
  32. virtual void OnBind( void *pvParticleMgr )
  33. {
  34. if( !pvParticleMgr )
  35. return;
  36. CParticleMgr *pMgr = (CParticleMgr*)pvParticleMgr;
  37. CParticleLightInfo info;
  38. pMgr->GetDirectionalLightInfo( info );
  39. // Transform the light into camera space.
  40. Vector vTransformedPos = pMgr->GetModelView() * info.m_vPos;
  41. if ( m_pLightPosition )
  42. m_pLightPosition->SetVecValue( vTransformedPos.Base(), 3 );
  43. if ( m_pLightColor )
  44. {
  45. Vector vTotalColor = info.m_vColor * info.m_flIntensity;
  46. m_pLightColor->SetVecValue( vTotalColor.Base(), 3 );
  47. }
  48. }
  49. virtual void Release( void ) { delete this; }
  50. virtual IMaterial *GetMaterial()
  51. {
  52. IMaterialVar *pVar = m_pLightPosition ? m_pLightPosition : m_pLightColor;
  53. if ( !pVar )
  54. return NULL;
  55. return pVar->GetOwningMaterial();
  56. }
  57. private:
  58. IMaterialVar *m_pLightPosition;
  59. IMaterialVar *m_pLightColor;
  60. };
  61. EXPOSE_INTERFACE( ParticleSphereProxy, IMaterialProxy, "ParticleSphereProxy" IMATERIAL_PROXY_INTERFACE_VERSION );