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.

113 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "shaderlib/cshader.h"
  9. #include "convar.h"
  10. #include "debugdrawdepth_vs20.inc"
  11. #include "debugdrawdepth_ps20.inc"
  12. #include "debugdrawdepth_ps20b.inc"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. static ConVar mat_debugdepthmode( "mat_debugdepthmode", "0" );
  16. static ConVar mat_debugdepthval( "mat_debugdepthval", "128.0f" );
  17. static ConVar mat_debugdepthvalmax( "mat_debugdepthvalmax", "256.0f" );
  18. BEGIN_SHADER_FLAGS( DebugDepth, "Help for DebugDepth", SHADER_NOT_EDITABLE )
  19. BEGIN_SHADER_PARAMS
  20. END_SHADER_PARAMS
  21. SHADER_INIT_PARAMS()
  22. {
  23. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  24. }
  25. SHADER_INIT
  26. {
  27. }
  28. SHADER_FALLBACK
  29. {
  30. if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  31. {
  32. // Assert( 0 );
  33. return "WireFrame";
  34. }
  35. return 0;
  36. }
  37. SHADER_DRAW
  38. {
  39. SHADOW_STATE
  40. {
  41. // Set stream format (note that this shader supports compression)
  42. unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
  43. int nTexCoordCount = 1;
  44. int userDataSize = 0;
  45. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  46. DECLARE_STATIC_VERTEX_SHADER( debugdrawdepth_vs20 );
  47. SET_STATIC_VERTEX_SHADER( debugdrawdepth_vs20 );
  48. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  49. {
  50. DECLARE_STATIC_PIXEL_SHADER( debugdrawdepth_ps20b );
  51. SET_STATIC_PIXEL_SHADER( debugdrawdepth_ps20b );
  52. }
  53. else
  54. {
  55. DECLARE_STATIC_PIXEL_SHADER( debugdrawdepth_ps20 );
  56. SET_STATIC_PIXEL_SHADER( debugdrawdepth_ps20 );
  57. }
  58. }
  59. DYNAMIC_STATE
  60. {
  61. DECLARE_DYNAMIC_VERTEX_SHADER( debugdrawdepth_vs20 );
  62. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, s_pShaderAPI->GetCurrentNumBones() > 0 );
  63. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  64. SET_DYNAMIC_VERTEX_SHADER( debugdrawdepth_vs20 );
  65. Vector4D vecZFilter( 0, 0, 0, 1 );
  66. int nDepthMode = mat_debugdepthmode.GetInt();
  67. if ( nDepthMode > 1 )
  68. {
  69. nDepthMode = 0;
  70. }
  71. vecZFilter[nDepthMode] = 1;
  72. s_pShaderAPI->SetPixelShaderConstant( 1, vecZFilter.Base() );
  73. Vector4D vecModulationColor( 0, 0, 0, 1 );
  74. if ( IS_FLAG_SET( MATERIAL_VAR_DECAL ) )
  75. {
  76. vecModulationColor[0] = 0;
  77. vecModulationColor[1] = 1;
  78. vecModulationColor[2] = 1;
  79. }
  80. else
  81. {
  82. vecModulationColor[0] = 1;
  83. vecModulationColor[1] = 1;
  84. vecModulationColor[2] = 1;
  85. }
  86. s_pShaderAPI->SetPixelShaderConstant( 2, vecModulationColor.Base() );
  87. float flDepthFactor = mat_debugdepthval.GetFloat();
  88. float flDepthFactorMax = mat_debugdepthvalmax.GetFloat();
  89. if ( flDepthFactor == 0 )
  90. {
  91. flDepthFactor = 1.0f;
  92. }
  93. Vector4D vecZFactor( (flDepthFactorMax - flDepthFactor), flDepthFactor, 1, 1 );
  94. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vecZFactor.Base() );
  95. }
  96. Draw();
  97. }
  98. END_SHADER