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.

90 lines
2.7 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. DEFINE_FALLBACK_SHADER( Shadow, Shadow_DX6 )
  12. BEGIN_SHADER_FLAGS( Shadow_DX6, "Help for Shadow_DX6", SHADER_NOT_EDITABLE )
  13. BEGIN_SHADER_PARAMS
  14. END_SHADER_PARAMS
  15. SHADER_INIT_PARAMS()
  16. {
  17. // FIXME: Need fallback for dx5, don't fade out shadows, just pop them out
  18. /*
  19. The alpha blending state either must be:
  20. Src Color * Dst Color + Dst Color * 0
  21. (src color = C*A + 1-A)
  22. or
  23. // Can't be this, doesn't work with fog
  24. Src Color * Dst Color + Dst Color * (1-Src Alpha)
  25. (src color = C * A, Src Alpha = A)
  26. */
  27. }
  28. SHADER_INIT
  29. {
  30. if (params[BASETEXTURE]->IsDefined())
  31. LoadTexture( BASETEXTURE );
  32. }
  33. SHADER_DRAW
  34. {
  35. SHADOW_STATE
  36. {
  37. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  38. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  39. // To accomplish shadow fading, subtract vertex alpha from texture alpha
  40. // color channel isn't used...
  41. pShaderShadow->EnableCustomPixelPipe( true );
  42. pShaderShadow->CustomTextureStages( 2 );
  43. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  44. SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1,
  45. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR );
  46. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  47. SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SUBTRACT,
  48. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR );
  49. // Blend between white and the vertex color...
  50. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  51. SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA,
  52. SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_TEXTURE );
  53. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  54. SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1,
  55. SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_VERTEXCOLOR );
  56. EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO );
  57. pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR |
  58. SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 );
  59. // We need to fog to *white* regardless of overbrighting...
  60. FogToWhite();
  61. }
  62. DYNAMIC_STATE
  63. {
  64. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  65. BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME );
  66. SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM );
  67. SetFixedFunctionTextureTransform( MATERIAL_TEXTURE1, BASETEXTURETRANSFORM );
  68. // The constant color is the shadow color...
  69. SetColorState( COLOR );
  70. }
  71. Draw( );
  72. }
  73. END_SHADER