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.

138 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "shadow_ps20.inc"
  10. #include "shadow_ps20b.inc"
  11. #include "shadow_vs20.inc"
  12. BEGIN_VS_SHADER_FLAGS( Shadow, "Help for Shadow", SHADER_NOT_EDITABLE )
  13. BEGIN_SHADER_PARAMS
  14. END_SHADER_PARAMS
  15. SHADER_INIT_PARAMS()
  16. {
  17. /*
  18. The alpha blending state either must be:
  19. Src Color * Dst Color + Dst Color * 0
  20. (src color = C*A + 1-A)
  21. or
  22. // Can't be this, doesn't work with fog
  23. Src Color * Dst Color + Dst Color * (1-Src Alpha)
  24. (src color = C * A, Src Alpha = A)
  25. */
  26. }
  27. SHADER_FALLBACK
  28. {
  29. if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  30. {
  31. return "Shadow_DX8";
  32. }
  33. return 0;
  34. }
  35. SHADER_INIT
  36. {
  37. LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
  38. }
  39. SHADER_DRAW
  40. {
  41. SHADOW_STATE
  42. {
  43. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  44. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  45. // NOTE: This is deliberately this way round (instead of "DST_COLOR, ZERO"),
  46. // since these two permutations produce *different* values on 360!!
  47. // This was causing undue darkening of the framebuffer by these
  48. // shadows, which was highly noticeable in very dark areas:
  49. EnableAlphaBlending( SHADER_BLEND_ZERO, SHADER_BLEND_SRC_COLOR );
  50. unsigned int flags = VERTEX_POSITION | VERTEX_COLOR;
  51. int numTexCoords = 1;
  52. pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 );
  53. DECLARE_STATIC_VERTEX_SHADER( shadow_vs20 );
  54. SET_STATIC_VERTEX_SHADER( shadow_vs20 );
  55. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  56. {
  57. DECLARE_STATIC_PIXEL_SHADER( shadow_ps20b );
  58. SET_STATIC_PIXEL_SHADER( shadow_ps20b );
  59. }
  60. else
  61. {
  62. DECLARE_STATIC_PIXEL_SHADER( shadow_ps20 );
  63. SET_STATIC_PIXEL_SHADER( shadow_ps20 );
  64. }
  65. pShaderShadow->EnableSRGBWrite( true );
  66. // We need to fog to *white* regardless of overbrighting...
  67. FogToWhite();
  68. }
  69. DYNAMIC_STATE
  70. {
  71. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  72. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  73. SetPixelShaderConstantGammaToLinear( 1, COLOR );
  74. // Get texture dimensions...
  75. int nWidth = 16;
  76. int nHeight = 16;
  77. ITexture *pTexture = params[BASETEXTURE]->GetTextureValue();
  78. if (pTexture)
  79. {
  80. nWidth = pTexture->GetActualWidth();
  81. nHeight = pTexture->GetActualHeight();
  82. }
  83. Vector4D vecJitter( 1.0 / nWidth, 1.0 / nHeight, 0.0, 0.0 );
  84. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vecJitter.Base() );
  85. vecJitter.y *= -1.0f;
  86. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vecJitter.Base() );
  87. MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode();
  88. int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0;
  89. DECLARE_DYNAMIC_VERTEX_SHADER( shadow_vs20 );
  90. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex );
  91. SET_DYNAMIC_VERTEX_SHADER( shadow_vs20 );
  92. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  93. {
  94. DECLARE_DYNAMIC_PIXEL_SHADER( shadow_ps20b );
  95. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  96. SET_DYNAMIC_PIXEL_SHADER( shadow_ps20b );
  97. }
  98. else
  99. {
  100. DECLARE_DYNAMIC_PIXEL_SHADER( shadow_ps20 );
  101. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  102. SET_DYNAMIC_PIXEL_SHADER( shadow_ps20 );
  103. }
  104. float eyePos[4];
  105. pShaderAPI->GetWorldSpaceCameraPosition( eyePos );
  106. pShaderAPI->SetPixelShaderConstant( 2, eyePos, 1 );
  107. pShaderAPI->SetPixelShaderFogParams( 3 );
  108. }
  109. Draw( );
  110. }
  111. END_SHADER