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.

114 lines
3.5 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 "screenspaceeffect_vs20.inc"
  10. #include "accumbuff4sample_ps20.inc"
  11. #include "accumbuff4sample_ps20b.inc"
  12. #include "convar.h"
  13. BEGIN_VS_SHADER_FLAGS( accumbuff4sample, "Help for AccumBuff4Sample", SHADER_NOT_EDITABLE )
  14. BEGIN_SHADER_PARAMS
  15. // Four textures to sample
  16. SHADER_PARAM( TEXTURE0, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  17. SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  18. SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  19. SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  20. // Corresponding weights for the four input textures
  21. SHADER_PARAM( WEIGHTS, SHADER_PARAM_TYPE_VEC4, "", "Weight for Samples" )
  22. END_SHADER_PARAMS
  23. SHADER_INIT
  24. {
  25. LoadTexture( TEXTURE0 );
  26. LoadTexture( TEXTURE1 );
  27. LoadTexture( TEXTURE2 );
  28. LoadTexture( TEXTURE3 );
  29. }
  30. SHADER_FALLBACK
  31. {
  32. // Requires DX9 + above
  33. if (!g_pHardwareConfig->SupportsVertexAndPixelShaders())
  34. {
  35. Assert( 0 );
  36. return "Wireframe";
  37. }
  38. return 0;
  39. }
  40. SHADER_DRAW
  41. {
  42. SHADOW_STATE
  43. {
  44. pShaderShadow->EnableDepthWrites( false );
  45. pShaderShadow->EnableDepthTest( false );
  46. pShaderShadow->EnableAlphaWrites( false );
  47. pShaderShadow->EnableBlending( false );
  48. pShaderShadow->EnableCulling( false );
  49. // pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE );
  50. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  51. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  52. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  53. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  54. int fmt = VERTEX_POSITION;
  55. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  56. // Render targets are pegged as sRGB on OSX togl, so just force these reads and writes
  57. bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
  58. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite );
  59. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, bForceSRGBReadAndWrite );
  60. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, bForceSRGBReadAndWrite );
  61. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, bForceSRGBReadAndWrite );
  62. pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite );
  63. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  64. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  65. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  66. {
  67. DECLARE_STATIC_PIXEL_SHADER( accumbuff4sample_ps20b );
  68. SET_STATIC_PIXEL_SHADER( accumbuff4sample_ps20b );
  69. }
  70. else
  71. {
  72. DECLARE_STATIC_PIXEL_SHADER( accumbuff4sample_ps20 );
  73. SET_STATIC_PIXEL_SHADER( accumbuff4sample_ps20 );
  74. }
  75. }
  76. DYNAMIC_STATE
  77. {
  78. BindTexture( SHADER_SAMPLER0, TEXTURE0, -1 );
  79. BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 );
  80. BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 );
  81. BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 );
  82. SetPixelShaderConstant( 0, WEIGHTS );
  83. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  84. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  85. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  86. {
  87. DECLARE_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20b );
  88. SET_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20b );
  89. }
  90. else
  91. {
  92. DECLARE_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20 );
  93. SET_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20 );
  94. }
  95. }
  96. Draw();
  97. }
  98. END_SHADER