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.

83 lines
2.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "materialsystem/imaterialproxy.h"
  9. #include "materialsystem/imaterial.h"
  10. #include "materialsystem/imaterialvar.h"
  11. #include "iviewrender.h"
  12. #include "toolframework_client.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. // forward declarations
  16. void ToolFramework_RecordMaterialParams( IMaterial *pMaterial );
  17. // no inputs, assumes that the results go into $CHEAPWATERSTARTDISTANCE and $CHEAPWATERENDDISTANCE
  18. class CWaterLODMaterialProxy : public IMaterialProxy
  19. {
  20. public:
  21. CWaterLODMaterialProxy();
  22. virtual ~CWaterLODMaterialProxy();
  23. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  24. virtual void OnBind( void *pC_BaseEntity );
  25. virtual void Release( void ) { delete this; }
  26. virtual IMaterial *GetMaterial();
  27. private:
  28. IMaterialVar *m_pCheapWaterStartDistanceVar;
  29. IMaterialVar *m_pCheapWaterEndDistanceVar;
  30. };
  31. CWaterLODMaterialProxy::CWaterLODMaterialProxy()
  32. {
  33. m_pCheapWaterStartDistanceVar = NULL;
  34. m_pCheapWaterEndDistanceVar = NULL;
  35. }
  36. CWaterLODMaterialProxy::~CWaterLODMaterialProxy()
  37. {
  38. }
  39. bool CWaterLODMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  40. {
  41. bool foundVar;
  42. m_pCheapWaterStartDistanceVar = pMaterial->FindVar( "$CHEAPWATERSTARTDISTANCE", &foundVar, false );
  43. if( !foundVar )
  44. return false;
  45. m_pCheapWaterEndDistanceVar = pMaterial->FindVar( "$CHEAPWATERENDDISTANCE", &foundVar, false );
  46. if( !foundVar )
  47. return false;
  48. return true;
  49. }
  50. void CWaterLODMaterialProxy::OnBind( void *pC_BaseEntity )
  51. {
  52. if( !m_pCheapWaterStartDistanceVar || !m_pCheapWaterEndDistanceVar )
  53. {
  54. return;
  55. }
  56. float start, end;
  57. view->GetWaterLODParams( start, end );
  58. m_pCheapWaterStartDistanceVar->SetFloatValue( start );
  59. m_pCheapWaterEndDistanceVar->SetFloatValue( end );
  60. if ( ToolsEnabled() )
  61. {
  62. ToolFramework_RecordMaterialParams( GetMaterial() );
  63. }
  64. }
  65. IMaterial *CWaterLODMaterialProxy::GetMaterial()
  66. {
  67. return m_pCheapWaterStartDistanceVar->GetOwningMaterial();
  68. }
  69. EXPOSE_INTERFACE( CWaterLODMaterialProxy, IMaterialProxy, "WaterLOD" IMATERIAL_PROXY_INTERFACE_VERSION );