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.

149 lines
4.7 KiB

  1. //========= Copyright � 1996-2005, 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( BLOOMTYPE, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  20. SHADER_PARAM( BLOOMEXP, SHADER_PARAM_TYPE_FLOAT, "2.5", "" )
  21. SHADER_PARAM( BLOOMSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
  22. SHADER_PARAM( BLOOMTINTENABLE, SHADER_PARAM_TYPE_INTEGER, "1", "" )
  23. END_SHADER_PARAMS
  24. SHADER_INIT_PARAMS()
  25. {
  26. SET_PARAM_FLOAT_IF_NOT_DEFINED( BLOOMEXP, 2.5f );
  27. SET_PARAM_FLOAT_IF_NOT_DEFINED( BLOOMSATURATION, 1.0f );
  28. SET_PARAM_INT_IF_NOT_DEFINED( BLOOMTINTENABLE, 1 );
  29. if ( !params[BLOOMTYPE]->IsDefined() )
  30. {
  31. params[BLOOMTYPE]->SetIntValue( 0 );
  32. }
  33. }
  34. SHADER_FALLBACK
  35. {
  36. return 0;
  37. }
  38. SHADER_INIT
  39. {
  40. LoadTexture( BASETEXTURE );
  41. }
  42. SHADER_DRAW
  43. {
  44. // Render targets are pegged as sRGB on OSX, so just force these reads and writes
  45. bool bForceSRGBReadAndWrite = false;
  46. SHADOW_STATE
  47. {
  48. pShaderShadow->EnableDepthWrites( false );
  49. pShaderShadow->EnableAlphaWrites( true );
  50. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  51. // Render targets are pegged as sRGB on OSX, so just force these reads and writes
  52. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
  53. pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
  54. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
  55. pShaderShadow->SetVertexShader( "Downsample_vs20", 0 );
  56. if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
  57. {
  58. DECLARE_STATIC_PIXEL_SHADER( downsample_nohdr_ps20b );
  59. SET_STATIC_PIXEL_SHADER_COMBO( BLOOMTYPE, params[BLOOMTYPE]->GetIntValue() );
  60. SET_STATIC_PIXEL_SHADER_COMBO( SRGB_INPUT_ADAPTER, bForceSRGBReadAndWrite );
  61. SET_STATIC_PIXEL_SHADER_COMBO( PS3REGCOUNT48, 0 );
  62. SET_STATIC_PIXEL_SHADER( downsample_nohdr_ps20b );
  63. }
  64. else
  65. {
  66. DECLARE_STATIC_PIXEL_SHADER( downsample_nohdr_ps20 );
  67. SET_STATIC_PIXEL_SHADER_COMBO( BLOOMTYPE, params[BLOOMTYPE]->GetIntValue() );
  68. #ifdef _GAMECONSOLE
  69. SET_STATIC_PIXEL_SHADER_COMBO( SRGB_INPUT_ADAPTER, bForceSRGBReadAndWrite );
  70. #endif
  71. SET_STATIC_PIXEL_SHADER_COMBO( PS3REGCOUNT48, 0 );
  72. SET_STATIC_PIXEL_SHADER( downsample_nohdr_ps20 );
  73. }
  74. }
  75. DYNAMIC_STATE
  76. {
  77. BindTexture( SHADER_SAMPLER0, bForceSRGBReadAndWrite ? TEXTURE_BINDFLAGS_SRGBREAD : TEXTURE_BINDFLAGS_NONE, BASETEXTURE, -1 );
  78. int width, height;
  79. pShaderAPI->GetBackBufferDimensions( width, height );
  80. float v[4][4];
  81. float dX = 1.0f/width;
  82. float dY = 1.0f/height;
  83. v[0][0] = .5*dX;
  84. v[0][1] = .5*dY;
  85. v[1][0] = 2.5*dX;
  86. v[1][1] = .5*dY;
  87. v[2][0] = .5*dX;
  88. v[2][1] = 2.5*dY;
  89. v[3][0] = 2.5*dX;
  90. v[3][1] = 2.5*dY;
  91. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 );
  92. pShaderAPI->SetVertexShaderIndex( 0 );
  93. float flPixelShaderParams[4] = { r_bloomtintr.GetFloat(),
  94. r_bloomtintg.GetFloat(),
  95. r_bloomtintb.GetFloat(),
  96. r_bloomtintexponent.GetFloat() };
  97. if ( params[ BLOOMTINTENABLE ]->GetIntValue() == 0 )
  98. {
  99. flPixelShaderParams[0] = 1.0f;
  100. flPixelShaderParams[1] = 1.0f;
  101. flPixelShaderParams[2] = 1.0f;
  102. flPixelShaderParams[3] = 1.0f;
  103. }
  104. pShaderAPI->SetPixelShaderConstant( 0, flPixelShaderParams, 1 );
  105. float vPsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  106. vPsConst1[0] = params[BLOOMEXP]->GetFloatValue();
  107. vPsConst1[1] = params[BLOOMSATURATION]->GetFloatValue();
  108. pShaderAPI->SetPixelShaderConstant( 1, vPsConst1, 1 );
  109. if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() )
  110. {
  111. int floatBackBuffer = ( ( g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT ) && !IsX360() ) ? 1 : 0;
  112. DECLARE_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20b );
  113. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLOAT_BACK_BUFFER, floatBackBuffer );
  114. SET_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20b );
  115. }
  116. else
  117. {
  118. DECLARE_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20 );
  119. SET_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20 );
  120. }
  121. }
  122. Draw();
  123. }
  124. END_SHADER