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.

135 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // A class representing a light
  4. //
  5. //=============================================================================
  6. #ifndef DMELIGHT_H
  7. #define DMELIGHT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "movieobjects/dmedag.h"
  12. //-----------------------------------------------------------------------------
  13. // Forward declaration
  14. //-----------------------------------------------------------------------------
  15. struct LightDesc_t;
  16. //-----------------------------------------------------------------------------
  17. // A base class for lights
  18. //-----------------------------------------------------------------------------
  19. class CDmeLight : public CDmeDag
  20. {
  21. DEFINE_ELEMENT( CDmeLight, CDmeDag );
  22. public:
  23. // Sets the color and intensity
  24. // NOTE: Color is specified 0-255 floating point.
  25. void SetColor( const Color &color );
  26. void SetIntensity( float flIntensity );
  27. // Sets up render state in the material system for rendering
  28. virtual void SetupRenderState( int nLightIndex );
  29. virtual bool GetLightDesc( LightDesc_t *pDesc ) { return false; }
  30. protected:
  31. // Sets up render state in the material system for rendering
  32. void SetupRenderStateInternal( LightDesc_t &desc, float flAtten0, float flAtten1, float flAtten2 );
  33. CDmaVar< Color > m_Color;
  34. CDmaVar< float > m_flIntensity;
  35. };
  36. //-----------------------------------------------------------------------------
  37. // A directional light
  38. //-----------------------------------------------------------------------------
  39. class CDmeDirectionalLight : public CDmeLight
  40. {
  41. DEFINE_ELEMENT( CDmeDirectionalLight, CDmeLight );
  42. public:
  43. void SetDirection( const Vector &direction );
  44. const Vector &GetDirection() const { return m_Direction; }
  45. // Sets up render state in the material system for rendering
  46. virtual bool GetLightDesc( LightDesc_t *pDesc );
  47. private:
  48. CDmaVar<Vector> m_Direction;
  49. };
  50. //-----------------------------------------------------------------------------
  51. // A point light
  52. //-----------------------------------------------------------------------------
  53. class CDmePointLight : public CDmeLight
  54. {
  55. DEFINE_ELEMENT( CDmePointLight, CDmeLight );
  56. public:
  57. void SetPosition( const Vector &pos ) { m_Position = pos; }
  58. const Vector &GetPosition() const { return m_Position; }
  59. // Sets the attenuation factors
  60. void SetAttenuation( float flConstant, float flLinear, float flQuadratic );
  61. // Sets the maximum range
  62. void SetMaxDistance( float flMaxDistance );
  63. // Sets up render state in the material system for rendering
  64. virtual bool GetLightDesc( LightDesc_t *pDesc );
  65. protected:
  66. CDmaVar< Vector > m_Position;
  67. CDmaVar< float > m_flAttenuation0;
  68. CDmaVar< float > m_flAttenuation1;
  69. CDmaVar< float > m_flAttenuation2;
  70. CDmaVar< float > m_flMaxDistance;
  71. };
  72. //-----------------------------------------------------------------------------
  73. // A spot light
  74. //-----------------------------------------------------------------------------
  75. class CDmeSpotLight : public CDmePointLight
  76. {
  77. DEFINE_ELEMENT( CDmeSpotLight, CDmePointLight );
  78. public:
  79. // Sets the spotlight direction
  80. void SetDirection( const Vector &direction );
  81. // Sets the spotlight angle factors
  82. // Angles are specified in degrees, as full angles (as opposed to half-angles)
  83. void SetAngles( float flInnerAngle, float flOuterAngle, float flAngularFalloff );
  84. // Sets up render state in the material system for rendering
  85. virtual bool GetLightDesc( LightDesc_t *pDesc );
  86. private:
  87. CDmaVar<Vector> m_Direction;
  88. CDmaVar<float> m_flSpotInnerAngle;
  89. CDmaVar<float> m_flSpotOuterAngle;
  90. CDmaVar<float> m_flSpotAngularFalloff;
  91. };
  92. //-----------------------------------------------------------------------------
  93. // An ambient light
  94. //-----------------------------------------------------------------------------
  95. class CDmeAmbientLight : public CDmeLight
  96. {
  97. DEFINE_ELEMENT( CDmeAmbientLight, CDmeLight );
  98. public:
  99. // Sets up render state in the material system for rendering
  100. virtual void SetupRenderState( int nLightIndex );
  101. };
  102. #endif // DMELIGHT_H