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.

98 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Visualize shadow z buffers. Designed to be used when drawing a screen-aligned
  4. // quad with a floating-point z-buffer so that the large z-range is divided down
  5. // into visual range of grayscale colors.
  6. //
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #include "convar.h"
  10. #include "BaseVSShader.h"
  11. #include "showz_vs20.inc"
  12. #include "showz_ps20.inc"
  13. #include "showz_ps20b.inc"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. static ConVar r_showz_power( "r_showz_power", "1.0f", FCVAR_CHEAT );
  17. BEGIN_VS_SHADER_FLAGS( showz, "Help for ShowZ", SHADER_NOT_EDITABLE )
  18. BEGIN_SHADER_PARAMS
  19. SHADER_PARAM( ALPHADEPTH, SHADER_PARAM_TYPE_INTEGER, "0", "Depth is stored in alpha channel" )
  20. END_SHADER_PARAMS
  21. SHADER_INIT_PARAMS()
  22. {
  23. if ( !params[ALPHADEPTH]->IsDefined() )
  24. {
  25. params[ALPHADEPTH]->SetIntValue( 0 );
  26. }
  27. }
  28. SHADER_FALLBACK
  29. {
  30. // if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  31. // return "Wireframe";
  32. return 0;
  33. }
  34. SHADER_INIT
  35. {
  36. }
  37. SHADER_DRAW
  38. {
  39. SHADOW_STATE
  40. {
  41. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  42. DECLARE_STATIC_VERTEX_SHADER( showz_vs20 );
  43. SET_STATIC_VERTEX_SHADER( showz_vs20 );
  44. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  45. {
  46. DECLARE_STATIC_PIXEL_SHADER( showz_ps20b );
  47. SET_STATIC_PIXEL_SHADER_COMBO( DEPTH_IN_ALPHA, params[ALPHADEPTH]->GetIntValue() );
  48. SET_STATIC_PIXEL_SHADER( showz_ps20b );
  49. }
  50. else
  51. {
  52. DECLARE_STATIC_PIXEL_SHADER( showz_ps20 );
  53. SET_STATIC_PIXEL_SHADER_COMBO( DEPTH_IN_ALPHA, params[ALPHADEPTH]->GetIntValue() );
  54. SET_STATIC_PIXEL_SHADER( showz_ps20 );
  55. }
  56. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
  57. pShaderShadow->EnableSRGBWrite( true ); // The back buffer is sRGB, we should always set this true!
  58. }
  59. DYNAMIC_STATE
  60. {
  61. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); // Bind shadow depth map
  62. DECLARE_DYNAMIC_VERTEX_SHADER( showz_vs20 );
  63. SET_DYNAMIC_VERTEX_SHADER( showz_vs20 );
  64. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  65. {
  66. DECLARE_DYNAMIC_PIXEL_SHADER( showz_ps20b );
  67. SET_DYNAMIC_PIXEL_SHADER( showz_ps20b );
  68. }
  69. else
  70. {
  71. DECLARE_DYNAMIC_PIXEL_SHADER( showz_ps20 );
  72. SET_DYNAMIC_PIXEL_SHADER( showz_ps20 );
  73. }
  74. Vector4D C0;
  75. C0.x = r_showz_power.GetFloat();
  76. pShaderAPI->SetPixelShaderConstant( 0, C0.Base(), 1 );
  77. }
  78. Draw();
  79. }
  80. END_SHADER