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.

108 lines
2.9 KiB

  1. //===== Copyright (c) 1996-2005, 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. return 0;
  31. }
  32. SHADER_DRAW
  33. {
  34. SHADOW_STATE
  35. {
  36. // Set stream format (note that this shader supports compression)
  37. unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
  38. int nTexCoordCount = 1;
  39. int userDataSize = 0;
  40. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  41. DECLARE_STATIC_VERTEX_SHADER( debugdrawdepth_vs20 );
  42. SET_STATIC_VERTEX_SHADER( debugdrawdepth_vs20 );
  43. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  44. {
  45. DECLARE_STATIC_PIXEL_SHADER( debugdrawdepth_ps20b );
  46. SET_STATIC_PIXEL_SHADER( debugdrawdepth_ps20b );
  47. }
  48. else
  49. {
  50. DECLARE_STATIC_PIXEL_SHADER( debugdrawdepth_ps20 );
  51. SET_STATIC_PIXEL_SHADER( debugdrawdepth_ps20 );
  52. }
  53. }
  54. DYNAMIC_STATE
  55. {
  56. DECLARE_DYNAMIC_VERTEX_SHADER( debugdrawdepth_vs20 );
  57. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, s_pShaderAPI->GetCurrentNumBones() > 0 );
  58. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  59. SET_DYNAMIC_VERTEX_SHADER( debugdrawdepth_vs20 );
  60. Vector4D vecZFilter( 0, 0, 0, 1 );
  61. int nDepthMode = mat_debugdepthmode.GetInt();
  62. if ( nDepthMode > 1 )
  63. {
  64. nDepthMode = 0;
  65. }
  66. vecZFilter[nDepthMode] = 1;
  67. s_pShaderAPI->SetPixelShaderConstant( 1, vecZFilter.Base() );
  68. Vector4D vecModulationColor( 0, 0, 0, 1 );
  69. if ( IS_FLAG_SET( MATERIAL_VAR_DECAL ) )
  70. {
  71. vecModulationColor[0] = 0;
  72. vecModulationColor[1] = 1;
  73. vecModulationColor[2] = 1;
  74. }
  75. else
  76. {
  77. vecModulationColor[0] = 1;
  78. vecModulationColor[1] = 1;
  79. vecModulationColor[2] = 1;
  80. }
  81. s_pShaderAPI->SetPixelShaderConstant( 2, vecModulationColor.Base() );
  82. float flDepthFactor = mat_debugdepthval.GetFloat();
  83. float flDepthFactorMax = mat_debugdepthvalmax.GetFloat();
  84. if ( flDepthFactor == 0 )
  85. {
  86. flDepthFactor = 1.0f;
  87. }
  88. Vector4D vecZFactor( (flDepthFactorMax - flDepthFactor), flDepthFactor, 1, 1 );
  89. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vecZFactor.Base() );
  90. }
  91. Draw();
  92. }
  93. END_SHADER