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.

104 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "screenspaceeffect_vs20.inc"
  9. #include "IntroScreenSpaceEffect_ps20.inc"
  10. #include "IntroScreenSpaceEffect_ps20b.inc"
  11. BEGIN_VS_SHADER_FLAGS( IntroScreenSpaceEffect, "Help for IntroScreenSpaceEffect", SHADER_NOT_EDITABLE )
  12. BEGIN_SHADER_PARAMS
  13. SHADER_PARAM( MODE, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  14. SHADER_PARAM( ENABLESRGB, SHADER_PARAM_TYPE_BOOL, "0", "" )
  15. END_SHADER_PARAMS
  16. SHADER_INIT_PARAMS()
  17. {
  18. SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE );
  19. if ( !params[ENABLESRGB]->IsDefined() )
  20. {
  21. params[ENABLESRGB]->SetIntValue( 0 );
  22. }
  23. }
  24. SHADER_INIT
  25. {
  26. }
  27. SHADER_FALLBACK
  28. {
  29. // Requires DX9 + above
  30. if ( IsWindows() && ( g_pHardwareConfig->GetDXSupportLevel() < 90 || g_pHardwareConfig->PreferReducedFillrate() ) )
  31. return "IntroScreenSpaceEffect_dx80";
  32. return 0;
  33. }
  34. SHADER_DRAW
  35. {
  36. SHADOW_STATE
  37. {
  38. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  39. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  40. // On OpenGL OSX, we MUST do sRGB reads from the bloom and full framebuffer textures AND sRGB writes on the way out to the framebuffer.
  41. if ( params[ENABLESRGB]->GetIntValue() || IsOSX() )
  42. {
  43. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  44. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  45. pShaderShadow->EnableSRGBWrite( true );
  46. }
  47. // Only need the adapter if the shader expects sRGB values and we're forced to do an sRGB read by the API/Hardware
  48. bool bNeedsSRGBAdapter = ( params[ENABLESRGB]->GetIntValue() == 0 ) && IsOSX() && !g_pHardwareConfig->FakeSRGBWrite() && g_pHardwareConfig->CanDoSRGBReadFromRTs();
  49. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
  50. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  51. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  52. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // GL always goes the ps2b way for this shader, even on "ps20" parts
  53. {
  54. DECLARE_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps20b );
  55. SET_STATIC_PIXEL_SHADER_COMBO( LINEAR_TO_SRGB, bNeedsSRGBAdapter );
  56. SET_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps20b );
  57. }
  58. else
  59. {
  60. DECLARE_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps20 );
  61. SET_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps20 );
  62. }
  63. pShaderShadow->EnableBlending( true );
  64. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  65. }
  66. DYNAMIC_STATE
  67. {
  68. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 );
  69. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1 );
  70. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  71. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  72. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Posix always goes the ps2b way for this shader, even on "ps20" parts
  73. {
  74. DECLARE_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps20b );
  75. SET_DYNAMIC_PIXEL_SHADER_COMBO( MODE, params[MODE]->GetIntValue() );
  76. SET_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps20b );
  77. }
  78. else
  79. {
  80. DECLARE_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps20 );
  81. SET_DYNAMIC_PIXEL_SHADER_COMBO( MODE, params[MODE]->GetIntValue() );
  82. SET_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps20 );
  83. }
  84. SetPixelShaderConstant( 0, ALPHA );
  85. }
  86. Draw();
  87. }
  88. END_SHADER