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.

95 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Screen warp overlay
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "view.h"
  9. #include "c_sun.h"
  10. #include "particles_simple.h"
  11. #include "clienteffectprecachesystem.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffectWarp )
  15. CLIENTEFFECT_MATERIAL( "sun/overlay" )
  16. CLIENTEFFECT_REGISTER_END()
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Special draw for the warped overlay
  19. //-----------------------------------------------------------------------------
  20. void CWarpOverlay::Draw( bool bCacheFullSceneState )
  21. {
  22. // Get the vector to the sun.
  23. Vector vToGlow;
  24. if( m_bDirectional )
  25. vToGlow = m_vDirection;
  26. else
  27. vToGlow = m_vPos - CurrentViewOrigin();
  28. VectorNormalize( vToGlow );
  29. float flDot = vToGlow.Dot( CurrentViewForward() );
  30. if( flDot <= g_flOverlayRange )
  31. return;
  32. UpdateGlowObstruction( vToGlow, bCacheFullSceneState );
  33. if( m_flGlowObstructionScale == 0 )
  34. return;
  35. CMatRenderContextPtr pRenderContext( materials );
  36. //FIXME: Allow multiple?
  37. for( int iSprite=0; iSprite < m_nSprites; iSprite++ )
  38. {
  39. CGlowSprite *pSprite = &m_Sprites[iSprite];
  40. // Figure out the color and size to draw it.
  41. float flHorzSize, flVertSize;
  42. Vector vColor;
  43. CalcSpriteColorAndSize( flDot, pSprite, &flHorzSize, &flVertSize, &vColor );
  44. // Setup the basis to draw the sprite.
  45. Vector vBasePt, vUp, vRight;
  46. CalcBasis( vToGlow, flHorzSize, flVertSize, vBasePt, vUp, vRight );
  47. // Draw the sprite.
  48. IMaterial *pMaterial = materials->FindMaterial( "sun/overlay", TEXTURE_GROUP_CLIENT_EFFECTS );
  49. IMesh *pMesh = pRenderContext->GetDynamicMesh( false, 0, 0, pMaterial );
  50. CMeshBuilder builder;
  51. builder.Begin( pMesh, MATERIAL_QUADS, 1 );
  52. Vector vPt;
  53. vPt = vBasePt - vRight + vUp;
  54. builder.Position3fv( vPt.Base() );
  55. builder.Color4f( VectorExpand(vColor), 1 );
  56. builder.TexCoord2f( 0, 0, 1 );
  57. builder.AdvanceVertex();
  58. vPt = vBasePt + vRight + vUp;
  59. builder.Position3fv( vPt.Base() );
  60. builder.Color4f( VectorExpand(vColor), 1 );
  61. builder.TexCoord2f( 0, 1, 1 );
  62. builder.AdvanceVertex();
  63. vPt = vBasePt + vRight - vUp;
  64. builder.Position3fv( vPt.Base() );
  65. builder.Color4f( VectorExpand(vColor), 1 );
  66. builder.TexCoord2f( 0, 1, 0 );
  67. builder.AdvanceVertex();
  68. vPt = vBasePt - vRight - vUp;
  69. builder.Position3fv( vPt.Base() );
  70. builder.Color4f( VectorExpand(vColor), 1 );
  71. builder.TexCoord2f( 0, 0, 0 );
  72. builder.AdvanceVertex();
  73. builder.End( false, true );
  74. }
  75. }