Counter Strike : Global Offensive Source Code
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.

99 lines
2.7 KiB

  1. //===== Copyright (c) 1996-2005, 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. return 0;
  31. }
  32. SHADER_INIT
  33. {
  34. }
  35. SHADER_DRAW
  36. {
  37. SHADOW_STATE
  38. {
  39. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  40. DECLARE_STATIC_VERTEX_SHADER( showz_vs20 );
  41. SET_STATIC_VERTEX_SHADER( showz_vs20 );
  42. ShadowFilterMode_t nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode( false /* bForceLowQuality */, false /* bPS30 */ ); // Based upon vendor and device dependent formats
  43. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  44. {
  45. DECLARE_STATIC_PIXEL_SHADER( showz_ps20b );
  46. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  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, TEXTURE_BINDFLAGS_NONE, 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