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.

113 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "BaseVSShader.h"
  8. #ifdef STDSHADER_DX9_DLL_EXPORT
  9. #include "screenspaceeffect_vs20.inc"
  10. #include "filmgrain_ps20.inc"
  11. #else
  12. #include "screenspaceeffect_vs11.inc"
  13. #include "filmgrain_ps11.inc"
  14. #endif
  15. #include "../materialsystem_global.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. #ifdef STDSHADER_DX9_DLL_EXPORT
  19. DEFINE_FALLBACK_SHADER( FilmGrain, FilmGrain_dx9 )
  20. BEGIN_VS_SHADER_FLAGS( FilmGrain_dx9, "Help for FilmGrain", SHADER_NOT_EDITABLE )
  21. #else
  22. DEFINE_FALLBACK_SHADER( FilmGrain, FilmGrain_dx8 )
  23. BEGIN_VS_SHADER_FLAGS( FilmGrain_dx8, "Help for FilmGrain", SHADER_NOT_EDITABLE )
  24. #endif
  25. BEGIN_SHADER_PARAMS
  26. SHADER_PARAM( GRAIN_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "0", "Film grain texture" )
  27. SHADER_PARAM( NOISESCALE, SHADER_PARAM_TYPE_VEC4, "", "Strength of film grain" )
  28. END_SHADER_PARAMS
  29. SHADER_INIT_PARAMS()
  30. {
  31. SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE );
  32. }
  33. SHADER_FALLBACK
  34. {
  35. #ifdef STDSHADER_DX9_DLL_EXPORT
  36. // Requires DX9 + above
  37. if ( g_pHardwareConfig->GetDXSupportLevel() < 90)
  38. {
  39. return "FilmGrain_dx8";
  40. }
  41. #else // We're DX8
  42. // Requires DX8 + above
  43. if ( g_pHardwareConfig->GetDXSupportLevel() < 80)
  44. {
  45. return "FilmGrain_dx7";
  46. }
  47. #endif
  48. return 0;
  49. }
  50. SHADER_INIT
  51. {
  52. LoadTexture( GRAIN_TEXTURE );
  53. }
  54. SHADER_DRAW
  55. {
  56. SHADOW_STATE
  57. {
  58. pShaderShadow->EnableBlending( true );
  59. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_SRC_ALPHA );
  60. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  61. int fmt = VERTEX_POSITION;
  62. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  63. #ifdef STDSHADER_DX9_DLL_EXPORT
  64. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  65. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  66. DECLARE_STATIC_PIXEL_SHADER( filmgrain_ps20 );
  67. SET_STATIC_PIXEL_SHADER( filmgrain_ps20 );
  68. #else
  69. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 );
  70. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 );
  71. DECLARE_STATIC_PIXEL_SHADER( filmgrain_ps11 );
  72. SET_STATIC_PIXEL_SHADER( filmgrain_ps11 );
  73. #endif
  74. }
  75. DYNAMIC_STATE
  76. {
  77. BindTexture( SHADER_SAMPLER0, GRAIN_TEXTURE, -1 );
  78. SetPixelShaderConstant( 0, NOISESCALE );
  79. #ifdef STDSHADER_DX9_DLL_EXPORT
  80. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  81. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  82. DECLARE_DYNAMIC_PIXEL_SHADER( filmgrain_ps20 );
  83. SET_DYNAMIC_PIXEL_SHADER( filmgrain_ps20 );
  84. #else
  85. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 );
  86. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 );
  87. DECLARE_DYNAMIC_PIXEL_SHADER( filmgrain_ps11 );
  88. SET_DYNAMIC_PIXEL_SHADER( filmgrain_ps11 );
  89. #endif
  90. }
  91. Draw();
  92. }
  93. END_SHADER