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.

135 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "shadow_vs14.inc"
  10. #include "unlitgeneric_vs11.inc"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. DEFINE_FALLBACK_SHADER( Shadow, Shadow_DX8 )
  14. BEGIN_VS_SHADER_FLAGS( Shadow_DX8, "Help for Shadow_DX8", SHADER_NOT_EDITABLE )
  15. BEGIN_SHADER_PARAMS
  16. END_SHADER_PARAMS
  17. SHADER_INIT_PARAMS()
  18. {
  19. // FIXME: Need fallback for dx5, don't fade out shadows, just pop them out
  20. /*
  21. The alpha blending state either must be:
  22. Src Color * Dst Color + Dst Color * 0
  23. (src color = C*A + 1-A)
  24. or
  25. // Can't be this, doesn't work with fog
  26. Src Color * Dst Color + Dst Color * (1-Src Alpha)
  27. (src color = C * A, Src Alpha = A)
  28. */
  29. }
  30. SHADER_FALLBACK
  31. {
  32. if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 )
  33. {
  34. return "Shadow_DX6";
  35. }
  36. return 0;
  37. }
  38. SHADER_INIT
  39. {
  40. LoadTexture( BASETEXTURE );
  41. }
  42. SHADER_DRAW
  43. {
  44. SHADOW_STATE
  45. {
  46. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  47. if ( g_pHardwareConfig->SupportsPixelShaders_1_4() )
  48. {
  49. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  50. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  51. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  52. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  53. }
  54. EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO );
  55. unsigned int flags = VERTEX_POSITION | VERTEX_COLOR;
  56. int numTexCoords = 1;
  57. pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 );
  58. if( g_pHardwareConfig->GetDXSupportLevel() >= 81 )
  59. {
  60. shadow_vs14_Static_Index vshIndex;
  61. pShaderShadow->SetVertexShader( "Shadow_vs14", vshIndex.GetIndex() );
  62. pShaderShadow->SetPixelShader( "Shadow_ps14" );
  63. }
  64. else
  65. {
  66. unlitgeneric_vs11_Static_Index vshIndex;
  67. vshIndex.SetDETAIL( false );
  68. vshIndex.SetENVMAP( false );
  69. vshIndex.SetENVMAPCAMERASPACE( false );
  70. vshIndex.SetENVMAPSPHERE( false );
  71. vshIndex.SetVERTEXCOLOR( true );
  72. vshIndex.SetSEPARATEDETAILUVS( false );
  73. pShaderShadow->SetVertexShader( "UnlitGeneric_vs11", vshIndex.GetIndex() );
  74. pShaderShadow->SetPixelShader( "Shadow" );
  75. }
  76. // We need to fog to *white* regardless of overbrighting...
  77. FogToWhite();
  78. }
  79. DYNAMIC_STATE
  80. {
  81. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  82. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  83. SetPixelShaderConstant( 1, COLOR );
  84. if ( g_pHardwareConfig->GetDXSupportLevel() >= 81 )
  85. {
  86. BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME );
  87. BindTexture( SHADER_SAMPLER2, BASETEXTURE, FRAME );
  88. BindTexture( SHADER_SAMPLER3, BASETEXTURE, FRAME );
  89. BindTexture( SHADER_SAMPLER4, BASETEXTURE, FRAME );
  90. // Get texture dimensions...
  91. int nWidth = 16;
  92. int nHeight = 16;
  93. ITexture *pTexture = params[BASETEXTURE]->GetTextureValue();
  94. if (pTexture)
  95. {
  96. nWidth = pTexture->GetActualWidth();
  97. nHeight = pTexture->GetActualHeight();
  98. }
  99. Vector4D vecJitter( 1.0 / nWidth, 1.0 / nHeight, 0.0, 0.0 );
  100. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vecJitter.Base() );
  101. vecJitter.y *= -1.0f;
  102. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vecJitter.Base() );
  103. shadow_vs14_Dynamic_Index vshIndex;
  104. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  105. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  106. }
  107. else
  108. {
  109. unlitgeneric_vs11_Dynamic_Index vshIndex;
  110. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  111. vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 );
  112. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  113. }
  114. }
  115. Draw( );
  116. }
  117. END_SHADER