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.

141 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, 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_Int32ToColor32 ),
  19. RecvPropInt( RECVINFO(m_clrOverlay), 0, RecvProxy_Int32ToColor32 ),
  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. color24 c = GetRenderColor();
  47. float maxComponent = MAX( c.r, MAX( c.g, c.b ) );
  48. Vector vOverlayColor;
  49. Vector vMainColor;
  50. // Re-normalize the color ranges
  51. if ( maxComponent <= 0.0f )
  52. {
  53. // This is an error, set to pure white
  54. vMainColor.Init( 1.0f, 1.0f, 1.0f );
  55. }
  56. else
  57. {
  58. vMainColor.x = c.r / maxComponent;
  59. vMainColor.y = c.g / maxComponent;
  60. vMainColor.z = c.b / maxComponent;
  61. }
  62. // If we're non-zero, use the value (otherwise use the value we calculated above)
  63. if ( m_clrOverlay.r != 0 || m_clrOverlay.g != 0 || m_clrOverlay.b != 0 )
  64. {
  65. // Get our overlay color
  66. vOverlayColor.x = m_clrOverlay.r / 255.0f;
  67. vOverlayColor.y = m_clrOverlay.g / 255.0f;
  68. vOverlayColor.z = m_clrOverlay.b / 255.0f;
  69. }
  70. else
  71. {
  72. vOverlayColor = vMainColor;
  73. }
  74. //
  75. // Setup the core overlay
  76. //
  77. m_Overlay.m_vDirection = m_vDirection;
  78. m_Overlay.m_nSprites = 1;
  79. m_Overlay.m_Sprites[0].m_vColor = vMainColor;
  80. m_Overlay.m_Sprites[0].m_flHorzSize = m_nSize;
  81. m_Overlay.m_Sprites[0].m_flVertSize = m_nSize;
  82. const model_t* pModel = (m_nMaterial != 0) ? modelinfo->GetModel( m_nMaterial ) : NULL;
  83. const char *pModelName = pModel ? modelinfo->GetModelName( pModel ) : "";
  84. m_Overlay.m_Sprites[0].m_pMaterial = materials->FindMaterial( pModelName, TEXTURE_GROUP_OTHER );
  85. m_Overlay.m_flProxyRadius = 0.05f; // about 1/20th of the screen
  86. //
  87. // Setup the external glow overlay
  88. //
  89. m_GlowOverlay.m_vDirection = m_vDirection;
  90. m_GlowOverlay.m_nSprites = 1;
  91. m_GlowOverlay.m_Sprites[0].m_vColor = vOverlayColor;
  92. m_GlowOverlay.m_Sprites[0].m_flHorzSize = m_nOverlaySize;
  93. m_GlowOverlay.m_Sprites[0].m_flVertSize = m_nOverlaySize;
  94. pModel = (m_nOverlayMaterial != 0) ? modelinfo->GetModel( m_nOverlayMaterial ) : NULL;
  95. pModelName = pModel ? modelinfo->GetModelName( pModel ) : "";
  96. m_GlowOverlay.m_Sprites[0].m_pMaterial = materials->FindMaterial( pModelName, TEXTURE_GROUP_OTHER );
  97. // This texture will fade away as the dot between camera and sun changes
  98. m_GlowOverlay.SetModulateByDot();
  99. m_GlowOverlay.m_flProxyRadius = 0.05f; // about 1/20th of the screen
  100. // Either activate or deactivate.
  101. if ( m_bOn )
  102. {
  103. m_Overlay.Activate();
  104. m_GlowOverlay.Activate();
  105. }
  106. else
  107. {
  108. m_Overlay.Deactivate();
  109. m_GlowOverlay.Deactivate();
  110. }
  111. }