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.

103 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "BaseVSShader.h"
  8. #include "convar.h"
  9. #include "filmgrain_vs20.inc"
  10. #include "hsl_filmgrain_pass1_ps20.inc"
  11. #include "hsl_filmgrain_pass1_ps20b.inc"
  12. //
  13. // First pass converts from RGB to HSL and tweaks with noise similar to After Effects
  14. //
  15. BEGIN_VS_SHADER( hsl_filmgrain_pass1, "Help for Film Grain" )
  16. BEGIN_SHADER_PARAMS
  17. // Input textures
  18. SHADER_PARAM( INPUT, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  19. SHADER_PARAM( GRAIN, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  20. // Grain parameters to control positioning and noise params
  21. SHADER_PARAM( SCALEBIAS, SHADER_PARAM_TYPE_VEC4, "", "Scale and bias for grain placement" )
  22. SHADER_PARAM( HSLNOISESCALE, SHADER_PARAM_TYPE_VEC4, "", "Strength of film grain" )
  23. END_SHADER_PARAMS
  24. SHADER_INIT
  25. {
  26. LoadTexture( INPUT );
  27. LoadTexture( GRAIN );
  28. }
  29. SHADER_FALLBACK
  30. {
  31. // Requires DX9 + above
  32. if (!g_pHardwareConfig->SupportsVertexAndPixelShaders())
  33. {
  34. Assert( 0 );
  35. return "Wireframe";
  36. }
  37. return 0;
  38. }
  39. SHADER_DRAW
  40. {
  41. SHADOW_STATE
  42. {
  43. pShaderShadow->EnableDepthWrites( false );
  44. pShaderShadow->EnableDepthTest( false );
  45. pShaderShadow->EnableAlphaWrites( false );
  46. pShaderShadow->EnableBlending( false );
  47. pShaderShadow->EnableCulling( false );
  48. // pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE );
  49. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  50. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  51. int fmt = VERTEX_POSITION;
  52. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  53. DECLARE_STATIC_VERTEX_SHADER( filmgrain_vs20 );
  54. SET_STATIC_VERTEX_SHADER( filmgrain_vs20 );
  55. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  56. {
  57. DECLARE_STATIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20b );
  58. SET_STATIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20b );
  59. }
  60. else
  61. {
  62. DECLARE_STATIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20 );
  63. SET_STATIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20 );
  64. }
  65. }
  66. DYNAMIC_STATE
  67. {
  68. BindTexture( SHADER_SAMPLER0, INPUT, -1 );
  69. BindTexture( SHADER_SAMPLER1, GRAIN, -1 );
  70. SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, SCALEBIAS );
  71. SetPixelShaderConstant( 0, HSLNOISESCALE );
  72. DECLARE_DYNAMIC_VERTEX_SHADER( filmgrain_vs20 );
  73. SET_DYNAMIC_VERTEX_SHADER( filmgrain_vs20 );
  74. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  75. {
  76. DECLARE_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20b );
  77. SET_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20b );
  78. }
  79. else
  80. {
  81. DECLARE_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20 );
  82. SET_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20 );
  83. }
  84. }
  85. Draw();
  86. }
  87. END_SHADER