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
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //============================================================================//
  6. #include "BaseVSShader.h"
  7. #include "common_hlsl_cpp_consts.h"
  8. #include "convar.h"
  9. #include "Downsample_nohdr_ps20.inc"
  10. #include "Downsample_nohdr_ps20b.inc"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. static ConVar r_bloomtintr( "r_bloomtintr", "0.3" );
  14. static ConVar r_bloomtintg( "r_bloomtintg", "0.59" );
  15. static ConVar r_bloomtintb( "r_bloomtintb", "0.11" );
  16. static ConVar r_bloomtintexponent( "r_bloomtintexponent", "2.2" );
  17. BEGIN_VS_SHADER_FLAGS( Downsample_nohdr, "Help for Downsample_nohdr", SHADER_NOT_EDITABLE )
  18. BEGIN_SHADER_PARAMS
  19. SHADER_PARAM( BLOOMTINTENABLE, SHADER_PARAM_TYPE_INTEGER, "1", "" )
  20. SHADER_PARAM( CSTRIKE, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  21. END_SHADER_PARAMS
  22. SHADER_INIT_PARAMS()
  23. {
  24. if ( !params[ BLOOMTINTENABLE ]->IsDefined() )
  25. {
  26. params[ BLOOMTINTENABLE ]->SetIntValue( 1 );
  27. }
  28. }
  29. SHADER_INIT
  30. {
  31. LoadTexture( BASETEXTURE );
  32. }
  33. SHADER_FALLBACK
  34. {
  35. if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  36. {
  37. return "Downsample_nohdr_DX80";
  38. }
  39. return 0;
  40. }
  41. SHADER_DRAW
  42. {
  43. SHADOW_STATE
  44. {
  45. pShaderShadow->EnableDepthWrites( false );
  46. pShaderShadow->EnableAlphaWrites( true );
  47. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  48. // Render targets are pegged as sRGB on OSX, so just force these reads and writes
  49. bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
  50. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
  51. pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
  52. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
  53. pShaderShadow->SetVertexShader( "Downsample_vs20", 0 );
  54. if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
  55. {
  56. DECLARE_STATIC_PIXEL_SHADER( downsample_nohdr_ps20b );
  57. SET_STATIC_PIXEL_SHADER_COMBO( CSTRIKE, params[CSTRIKE]->GetIntValue() ? 1 : 0 );
  58. #ifndef _X360
  59. SET_STATIC_PIXEL_SHADER_COMBO( SRGB_ADAPTER, bForceSRGBReadAndWrite );
  60. #endif
  61. SET_STATIC_PIXEL_SHADER( downsample_nohdr_ps20b );
  62. }
  63. else
  64. {
  65. DECLARE_STATIC_PIXEL_SHADER( downsample_nohdr_ps20 );
  66. SET_STATIC_PIXEL_SHADER_COMBO( CSTRIKE, params[CSTRIKE]->GetIntValue() ? 1 : 0 );
  67. SET_STATIC_PIXEL_SHADER( downsample_nohdr_ps20 );
  68. }
  69. }
  70. DYNAMIC_STATE
  71. {
  72. BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
  73. int width, height;
  74. pShaderAPI->GetBackBufferDimensions( width, height );
  75. float v[4][4];
  76. float dX = 1.0f/width;
  77. float dY = 1.0f/height;
  78. v[0][0] = .5*dX;
  79. v[0][1] = .5*dY;
  80. v[1][0] = 2.5*dX;
  81. v[1][1] = .5*dY;
  82. v[2][0] = .5*dX;
  83. v[2][1] = 2.5*dY;
  84. v[3][0] = 2.5*dX;
  85. v[3][1] = 2.5*dY;
  86. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 );
  87. pShaderAPI->SetVertexShaderIndex( 0 );
  88. float flPixelShaderParams[4] = { r_bloomtintr.GetFloat(),
  89. r_bloomtintg.GetFloat(),
  90. r_bloomtintb.GetFloat(),
  91. r_bloomtintexponent.GetFloat() };
  92. if ( params[ BLOOMTINTENABLE ]->GetIntValue() == 0 )
  93. {
  94. flPixelShaderParams[0] = 0.333f;
  95. flPixelShaderParams[1] = 0.333f;
  96. flPixelShaderParams[2] = 0.333f;
  97. flPixelShaderParams[3] = 1.0f;
  98. }
  99. pShaderAPI->SetPixelShaderConstant( 0, flPixelShaderParams, 1 );
  100. if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
  101. {
  102. DECLARE_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20b );
  103. SET_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20b );
  104. }
  105. else
  106. {
  107. DECLARE_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20 );
  108. SET_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20 );
  109. }
  110. }
  111. Draw();
  112. }
  113. END_SHADER