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.

118 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 "floatcombine_ps20.inc"
  10. #include "floatcombine_ps20b.inc"
  11. BEGIN_VS_SHADER_FLAGS( floatcombine, "Help for floatcombine", SHADER_NOT_EDITABLE )
  12. BEGIN_SHADER_PARAMS
  13. SHADER_PARAM( BLOOMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  14. SHADER_PARAM( SHARPNESS, SHADER_PARAM_TYPE_FLOAT, "1", "" )
  15. SHADER_PARAM( WOODCUT, SHADER_PARAM_TYPE_FLOAT, "0", "" )
  16. SHADER_PARAM( VIGNETTE_MIN_BRIGHT,SHADER_PARAM_TYPE_FLOAT,"1","")
  17. SHADER_PARAM( VIGNETTE_POWER,SHADER_PARAM_TYPE_FLOAT,"4","")
  18. SHADER_PARAM( EDGE_SOFTNESS,SHADER_PARAM_TYPE_FLOAT,"0","")
  19. SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
  20. SHADER_PARAM( BLOOMEXPONENT, SHADER_PARAM_TYPE_FLOAT, "2.0", "" )
  21. SHADER_PARAM( ALPHASHARPENFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  22. END_SHADER_PARAMS
  23. SHADER_INIT
  24. {
  25. if( params[BASETEXTURE]->IsDefined() )
  26. {
  27. LoadTexture( BASETEXTURE );
  28. }
  29. if( params[BLOOMTEXTURE]->IsDefined() )
  30. {
  31. LoadTexture( BLOOMTEXTURE );
  32. }
  33. }
  34. SHADER_FALLBACK
  35. {
  36. // Requires DX9 + above
  37. if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  38. {
  39. // Assert( 0 );
  40. return "Wireframe";
  41. }
  42. return 0;
  43. }
  44. SHADER_DRAW
  45. {
  46. SHADOW_STATE
  47. {
  48. pShaderShadow->EnableDepthWrites( false );
  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. // convert from linear to gamma on write.
  54. pShaderShadow->EnableSRGBWrite( true );
  55. // Pre-cache shaders
  56. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  57. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  58. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  59. {
  60. DECLARE_STATIC_PIXEL_SHADER( floatcombine_ps20b );
  61. SET_STATIC_PIXEL_SHADER( floatcombine_ps20b );
  62. }
  63. else
  64. {
  65. DECLARE_STATIC_PIXEL_SHADER( floatcombine_ps20 );
  66. SET_STATIC_PIXEL_SHADER( floatcombine_ps20 );
  67. }
  68. }
  69. DYNAMIC_STATE
  70. {
  71. float c0[4]={params[SHARPNESS]->GetFloatValue(),
  72. params[WOODCUT]->GetFloatValue(),
  73. params[BLOOMAMOUNT]->GetFloatValue(),
  74. params[ALPHASHARPENFACTOR]->GetFloatValue()};
  75. float c1[4]={params[BLOOMEXPONENT]->GetFloatValue(),
  76. params[VIGNETTE_MIN_BRIGHT]->GetFloatValue(),
  77. params[VIGNETTE_POWER]->GetFloatValue(),
  78. params[EDGE_SOFTNESS]->GetFloatValue()};
  79. pShaderAPI->SetPixelShaderConstant( 0, c0, 1 );
  80. pShaderAPI->SetPixelShaderConstant( 1, c1, 1 );
  81. BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
  82. BindTexture( SHADER_SAMPLER1, BLOOMTEXTURE, -1 );
  83. ITexture *base_texture=params[BASETEXTURE]->GetTextureValue();
  84. ITexture *bloom_texture=params[BLOOMTEXTURE]->GetTextureValue();
  85. float v0[4]={ (float)(1.0/base_texture->GetActualWidth()), (float)(1.0/base_texture->GetActualHeight()),
  86. (float)(1.0/bloom_texture->GetActualWidth()), (float)(1.0/bloom_texture->GetActualHeight()) };
  87. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v0, 1 );
  88. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  89. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  90. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  91. {
  92. DECLARE_DYNAMIC_PIXEL_SHADER( floatcombine_ps20b );
  93. SET_DYNAMIC_PIXEL_SHADER( floatcombine_ps20b );
  94. }
  95. else
  96. {
  97. DECLARE_DYNAMIC_PIXEL_SHADER( floatcombine_ps20 );
  98. SET_DYNAMIC_PIXEL_SHADER( floatcombine_ps20 );
  99. }
  100. }
  101. Draw();
  102. }
  103. END_SHADER