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.

141 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "c_sun.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. static void RecvProxy_HDRColorScale( const CRecvProxyData *pData, void *pStruct, void *pOut )
  12. {
  13. C_Sun *pSun = ( C_Sun * )pStruct;
  14. pSun->m_Overlay.m_flHDRColorScale = pData->m_Value.m_Float;
  15. pSun->m_GlowOverlay.m_flHDRColorScale = pData->m_Value.m_Float;
  16. }
  17. IMPLEMENT_CLIENTCLASS_DT_NOBASE( C_Sun, DT_Sun, CSun )
  18. RecvPropInt( RECVINFO(m_clrRender), 0, RecvProxy_IntToColor32 ),
  19. RecvPropInt( RECVINFO(m_clrOverlay), 0, RecvProxy_IntToColor32 ),
  20. RecvPropVector( RECVINFO( m_vDirection ) ),
  21. RecvPropInt( RECVINFO( m_bOn ) ),
  22. RecvPropInt( RECVINFO( m_nSize ) ),
  23. RecvPropInt( RECVINFO( m_nOverlaySize ) ),
  24. RecvPropInt( RECVINFO( m_nMaterial ) ),
  25. RecvPropInt( RECVINFO( m_nOverlayMaterial ) ),
  26. RecvPropFloat("HDRColorScale", 0, SIZEOF_IGNORE, 0, RecvProxy_HDRColorScale),
  27. END_RECV_TABLE()
  28. C_Sun::C_Sun()
  29. {
  30. m_Overlay.m_bDirectional = true;
  31. m_Overlay.m_bInSky = true;
  32. m_GlowOverlay.m_bDirectional = true;
  33. m_GlowOverlay.m_bInSky = true;
  34. }
  35. C_Sun::~C_Sun()
  36. {
  37. }
  38. void C_Sun::OnDataChanged( DataUpdateType_t updateType )
  39. {
  40. BaseClass::OnDataChanged( updateType );
  41. // We have to do special setup on our colors because we're tinting an additive material.
  42. // If we don't have at least one component at full strength, the luminosity of the material
  43. // will change and that will cause the material to become more translucent This would be incorrect
  44. // for the sun, which should always be completely opaque at its core. Here, we renormalize the
  45. // components to make sure only hue is altered.
  46. float maxComponent = MAX ( m_clrRender->r, MAX ( m_clrRender->g, m_clrRender->b ) );
  47. Vector vOverlayColor;
  48. Vector vMainColor;
  49. // Re-normalize the color ranges
  50. if ( maxComponent <= 0.0f )
  51. {
  52. // This is an error, set to pure white
  53. vMainColor.Init( 1.0f, 1.0f, 1.0f );
  54. }
  55. else
  56. {
  57. vMainColor.x = m_clrRender->r / maxComponent;
  58. vMainColor.y = m_clrRender->g / maxComponent;
  59. vMainColor.z = m_clrRender->b / maxComponent;
  60. }
  61. // If we're non-zero, use the value (otherwise use the value we calculated above)
  62. if ( m_clrOverlay.r != 0 || m_clrOverlay.g != 0 || m_clrOverlay.b != 0 )
  63. {
  64. // Get our overlay color
  65. vOverlayColor.x = m_clrOverlay.r / 255.0f;
  66. vOverlayColor.y = m_clrOverlay.g / 255.0f;
  67. vOverlayColor.z = m_clrOverlay.b / 255.0f;
  68. }
  69. else
  70. {
  71. vOverlayColor = vMainColor;
  72. }
  73. //
  74. // Setup the core overlay
  75. //
  76. m_Overlay.m_vDirection = m_vDirection;
  77. m_Overlay.m_nSprites = 1;
  78. m_Overlay.m_Sprites[0].m_vColor = vMainColor;
  79. m_Overlay.m_Sprites[0].m_flHorzSize = m_nSize;
  80. m_Overlay.m_Sprites[0].m_flVertSize = m_nSize;
  81. const model_t* pModel = (m_nMaterial != 0) ? modelinfo->GetModel( m_nMaterial ) : NULL;
  82. const char *pModelName = pModel ? modelinfo->GetModelName( pModel ) : "";
  83. m_Overlay.m_Sprites[0].m_pMaterial = materials->FindMaterial( pModelName, TEXTURE_GROUP_OTHER );
  84. m_Overlay.m_flProxyRadius = 0.05f; // about 1/20th of the screen
  85. //
  86. // Setup the external glow overlay
  87. //
  88. m_GlowOverlay.m_vDirection = m_vDirection;
  89. m_GlowOverlay.m_nSprites = 1;
  90. m_GlowOverlay.m_Sprites[0].m_vColor = vOverlayColor;
  91. m_GlowOverlay.m_Sprites[0].m_flHorzSize = m_nOverlaySize;
  92. m_GlowOverlay.m_Sprites[0].m_flVertSize = m_nOverlaySize;
  93. pModel = (m_nOverlayMaterial != 0) ? modelinfo->GetModel( m_nOverlayMaterial ) : NULL;
  94. pModelName = pModel ? modelinfo->GetModelName( pModel ) : "";
  95. m_GlowOverlay.m_Sprites[0].m_pMaterial = materials->FindMaterial( pModelName, TEXTURE_GROUP_OTHER );
  96. // This texture will fade away as the dot between camera and sun changes
  97. m_GlowOverlay.SetModulateByDot();
  98. m_GlowOverlay.m_flProxyRadius = 0.05f; // about 1/20th of the screen
  99. // Either activate or deactivate.
  100. if ( m_bOn )
  101. {
  102. m_Overlay.Activate();
  103. m_GlowOverlay.Activate();
  104. }
  105. else
  106. {
  107. m_Overlay.Deactivate();
  108. m_GlowOverlay.Deactivate();
  109. }
  110. }