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.

127 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "shaderlib/cshader.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include "tier0/memdbgon.h"
  9. BEGIN_SHADER_FLAGS( Decal, "Help for Decal", SHADER_NOT_EDITABLE )
  10. BEGIN_SHADER_PARAMS
  11. END_SHADER_PARAMS
  12. SHADER_INIT_PARAMS()
  13. {
  14. SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  15. }
  16. SHADER_INIT
  17. {
  18. LoadTexture( BASETEXTURE );
  19. }
  20. SHADER_DRAW
  21. {
  22. // vertex alpha 0 = mod2x, vertex alpha 1 = src_alpha,1-src_alpha
  23. // need to set constant color to grey
  24. SHADOW_STATE
  25. {
  26. // common stuff
  27. pShaderShadow->EnableDepthWrites( false );
  28. pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
  29. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  30. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  31. pShaderShadow->EnableBlending( true );
  32. }
  33. // MOD2X pass
  34. SHADOW_STATE
  35. {
  36. pShaderShadow->EnableCustomPixelPipe( true );
  37. pShaderShadow->CustomTextureStages( 2 );
  38. // color = texture
  39. // alpha = vertexalpha
  40. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  41. SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1,
  42. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE );
  43. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  44. SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1,
  45. SHADER_TEXARG_SPECULARCOLOR, SHADER_TEXARG_NONE );
  46. // color = texture
  47. // alpha = blend
  48. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  49. SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA,
  50. SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_PREVIOUSSTAGE );
  51. pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR );
  52. FogToGrey();
  53. pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_SPECULAR
  54. | SHADER_DRAW_LIGHTMAP_TEXCOORD1 );
  55. }
  56. DYNAMIC_STATE
  57. {
  58. pShaderAPI->Color3f( 0.5f, 0.5f, 0.5f );
  59. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  60. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
  61. }
  62. Draw();
  63. // srcalpha,1-srcalpha pass
  64. SHADOW_STATE
  65. {
  66. pShaderShadow->EnableCustomPixelPipe( true );
  67. pShaderShadow->CustomTextureStages( 2 );
  68. // color = texture
  69. // alpha = texture
  70. if (IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ))
  71. {
  72. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  73. SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE,
  74. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR );
  75. }
  76. else
  77. {
  78. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  79. SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1,
  80. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE );
  81. }
  82. if( IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ) )
  83. {
  84. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  85. SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE,
  86. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR );
  87. }
  88. else
  89. {
  90. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  91. SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1,
  92. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE );
  93. }
  94. // color = texture [* vertex color] * lightmap color
  95. // alpha = texture alpha [* vertex alpha] * specular alpha
  96. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  97. SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE2X,
  98. SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_TEXTURE );
  99. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  100. SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE,
  101. SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_SPECULARCOLOR );
  102. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  103. FogToFogColor();
  104. }
  105. DYNAMIC_STATE
  106. {
  107. SetColorState( COLOR );
  108. }
  109. Draw();
  110. }
  111. END_SHADER