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.

152 lines
4.1 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "fillrate_vs20.inc"
  10. #include "fillrate_ps20.inc"
  11. #include "fillrate_ps20b.inc"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. BEGIN_VS_SHADER_FLAGS( Fillrate, "Help for Fillrate", SHADER_NOT_EDITABLE )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM( PASSCOUNT, SHADER_PARAM_TYPE_INTEGER, "1", "Number of passes for this material" )
  17. END_SHADER_PARAMS
  18. SHADER_INIT_PARAMS()
  19. {
  20. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  21. }
  22. SHADER_INIT
  23. {
  24. }
  25. SHADER_FALLBACK
  26. {
  27. return 0;
  28. }
  29. SHADER_DRAW
  30. {
  31. SHADOW_STATE
  32. {
  33. pShaderShadow->EnableDepthTest( false );
  34. pShaderShadow->EnableDepthWrites( false );
  35. pShaderShadow->EnableBlending( true );
  36. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  37. // Set stream format (note that this shader supports compression)
  38. unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
  39. int nTexCoordCount = 1;
  40. int userDataSize = 0;
  41. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  42. DECLARE_STATIC_VERTEX_SHADER( fillrate_vs20 );
  43. SET_STATIC_VERTEX_SHADER( fillrate_vs20 );
  44. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  45. {
  46. DECLARE_STATIC_PIXEL_SHADER( fillrate_ps20b );
  47. SET_STATIC_PIXEL_SHADER( fillrate_ps20b );
  48. }
  49. else
  50. {
  51. DECLARE_STATIC_PIXEL_SHADER( fillrate_ps20 );
  52. SET_STATIC_PIXEL_SHADER( fillrate_ps20 );
  53. }
  54. }
  55. DYNAMIC_STATE
  56. {
  57. int numPasses = params[PASSCOUNT]->GetIntValue();
  58. float color[4];
  59. if (g_pConfig->bMeasureFillRate)
  60. {
  61. // have to multiply by 2/255 since pixel shader constant are 1.7.
  62. // Will divide the 2 out in the pixel shader.
  63. color[0] = numPasses * ( 2.0f / 255.0f );
  64. }
  65. else
  66. {
  67. color[0] = ( 16 * numPasses ) * ( 2.0f / 255.0f );
  68. }
  69. color[1] = 0.0f;
  70. color[2] = 0.0f;
  71. color[3] = 0.0f;
  72. pShaderAPI->SetPixelShaderConstant( 0, color, 1 );
  73. DECLARE_DYNAMIC_VERTEX_SHADER( fillrate_vs20 );
  74. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  75. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  76. SET_DYNAMIC_VERTEX_SHADER( fillrate_vs20 );
  77. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  78. {
  79. DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps20b );
  80. SET_DYNAMIC_PIXEL_SHADER( fillrate_ps20b );
  81. }
  82. else
  83. {
  84. DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps20 );
  85. SET_DYNAMIC_PIXEL_SHADER( fillrate_ps20 );
  86. }
  87. }
  88. Draw();
  89. SHADOW_STATE
  90. {
  91. pShaderShadow->EnableDepthTest( false );
  92. pShaderShadow->EnableDepthWrites( false );
  93. pShaderShadow->EnableBlending( true );
  94. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  95. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
  96. pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE );
  97. DECLARE_STATIC_VERTEX_SHADER( fillrate_vs20 );
  98. SET_STATIC_VERTEX_SHADER( fillrate_vs20 );
  99. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  100. {
  101. DECLARE_STATIC_PIXEL_SHADER( fillrate_ps20b );
  102. SET_STATIC_PIXEL_SHADER( fillrate_ps20b );
  103. }
  104. else
  105. {
  106. DECLARE_STATIC_PIXEL_SHADER( fillrate_ps20 );
  107. SET_STATIC_PIXEL_SHADER( fillrate_ps20 );
  108. }
  109. }
  110. DYNAMIC_STATE
  111. {
  112. float color[4] = { 0.0f, 0.05f, 0.05f, 0.0f };
  113. pShaderAPI->SetPixelShaderConstant( 0, color, 1 );
  114. DECLARE_DYNAMIC_VERTEX_SHADER( fillrate_vs20 );
  115. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  116. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  117. SET_DYNAMIC_VERTEX_SHADER( fillrate_vs20 );
  118. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  119. {
  120. DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps20b );
  121. SET_DYNAMIC_PIXEL_SHADER( fillrate_ps20b );
  122. }
  123. else
  124. {
  125. DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps20 );
  126. SET_DYNAMIC_PIXEL_SHADER( fillrate_ps20 );
  127. }
  128. }
  129. Draw();
  130. }
  131. END_SHADER