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.

96 lines
2.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "shaderlib/cshader.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. // FIXME!! This version doesn't support vertexalpha to make it blend to white!!!
  12. DEFINE_FALLBACK_SHADER( Modulate, Modulate_DX6 )
  13. BEGIN_SHADER( Modulate_DX6,
  14. "Help for Modulate_DX6" )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM( WRITEZ, SHADER_PARAM_TYPE_BOOL, "0", "Forces z to be written if set" )
  17. SHADER_PARAM( MOD2X, SHADER_PARAM_TYPE_BOOL, "0", "forces a 2x modulate so that you can brighten and darken things" )
  18. END_SHADER_PARAMS
  19. SHADER_INIT_PARAMS()
  20. {
  21. }
  22. SHADER_INIT
  23. {
  24. if (params[BASETEXTURE]->IsDefined())
  25. LoadTexture( BASETEXTURE );
  26. }
  27. SHADER_DRAW
  28. {
  29. bool bMod2X = params[MOD2X]->IsDefined() && params[MOD2X]->GetIntValue();
  30. SHADOW_STATE
  31. {
  32. if( bMod2X )
  33. {
  34. EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR );
  35. }
  36. else
  37. {
  38. EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO );
  39. }
  40. if (params[WRITEZ]->GetIntValue() != 0)
  41. {
  42. // This overrides the disabling of depth writes performed in
  43. // EnableAlphaBlending
  44. pShaderShadow->EnableDepthWrites(true);
  45. }
  46. pShaderShadow->EnableConstantColor( true );
  47. int drawFlags = SHADER_DRAW_POSITION;
  48. if (params[BASETEXTURE]->IsTexture())
  49. {
  50. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  51. drawFlags |= SHADER_DRAW_TEXCOORD0;
  52. }
  53. if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR))
  54. {
  55. drawFlags |= SHADER_DRAW_COLOR;
  56. }
  57. pShaderShadow->DrawFlags( drawFlags );
  58. // We need to fog to *white* regardless of overbrighting...
  59. if( bMod2X )
  60. {
  61. FogToGrey();
  62. }
  63. else
  64. {
  65. FogToOOOverbright();
  66. }
  67. }
  68. DYNAMIC_STATE
  69. {
  70. if (params[BASETEXTURE]->IsTexture())
  71. {
  72. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  73. SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM );
  74. }
  75. // The constant color is the modulation color...
  76. SetColorState( COLOR );
  77. }
  78. Draw( );
  79. }
  80. END_SHADER