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.

110 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "BaseVSShader.h"
  8. #include "common_hlsl_cpp_consts.h"
  9. #include "Downsample_ps20.inc"
  10. #include "Downsample_ps20b.inc"
  11. BEGIN_VS_SHADER_FLAGS( Downsample, "Help for Downsample", SHADER_NOT_EDITABLE )
  12. BEGIN_SHADER_PARAMS
  13. END_SHADER_PARAMS
  14. SHADER_INIT
  15. {
  16. LoadTexture( BASETEXTURE );
  17. }
  18. SHADER_FALLBACK
  19. {
  20. // Requires DX9 + above
  21. if ( !g_pHardwareConfig->SupportsVertexAndPixelShaders() )
  22. {
  23. // Assert( 0 );
  24. return "Wireframe";
  25. }
  26. return 0;
  27. }
  28. SHADER_DRAW
  29. {
  30. SHADOW_STATE
  31. {
  32. pShaderShadow->EnableDepthWrites( false );
  33. pShaderShadow->EnableAlphaWrites( true );
  34. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  35. // Render targets are pegged as sRGB on OSX GL, so just force these reads and writes
  36. bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
  37. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
  38. pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
  39. int fmt = VERTEX_POSITION;
  40. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  41. pShaderShadow->SetVertexShader( "Downsample_vs20", 0 );
  42. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  43. {
  44. DECLARE_STATIC_PIXEL_SHADER( downsample_ps20b );
  45. SET_STATIC_PIXEL_SHADER( downsample_ps20b );
  46. }
  47. else
  48. {
  49. DECLARE_STATIC_PIXEL_SHADER( downsample_ps20 );
  50. SET_STATIC_PIXEL_SHADER( downsample_ps20 );
  51. }
  52. }
  53. DYNAMIC_STATE
  54. {
  55. BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
  56. int width, height;
  57. pShaderAPI->GetBackBufferDimensions( width, height );
  58. float v[4];
  59. float dX = 1.0f / width;
  60. float dY = 1.0f / height;
  61. v[0] = -dX;
  62. v[1] = -dY;
  63. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 );
  64. v[0] = -dX;
  65. v[1] = dY;
  66. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 );
  67. v[0] = dX;
  68. v[1] = -dY;
  69. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 );
  70. v[0] = dX;
  71. v[1] = dY;
  72. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, v, 1 );
  73. // Setup luminance threshold (all values are scaled down by max luminance)
  74. // v[0] = 1.0f / MAX_HDR_OVERBRIGHT;
  75. v[0] = 0.0f;
  76. pShaderAPI->SetPixelShaderConstant( 0, v, 1 );
  77. pShaderAPI->SetVertexShaderIndex( 0 );
  78. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  79. {
  80. DECLARE_DYNAMIC_PIXEL_SHADER( downsample_ps20b );
  81. SET_DYNAMIC_PIXEL_SHADER( downsample_ps20b );
  82. }
  83. else
  84. {
  85. DECLARE_DYNAMIC_PIXEL_SHADER( downsample_ps20 );
  86. SET_DYNAMIC_PIXEL_SHADER( downsample_ps20 );
  87. }
  88. }
  89. Draw();
  90. }
  91. END_SHADER