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.

113 lines
3.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "worldvertexalpha.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( WorldVertexAlpha, WorldVertexAlpha_DX8 )
  13. BEGIN_VS_SHADER( WorldVertexAlpha_DX8,
  14. "Help for WorldVertexAlpha_DX8" )
  15. BEGIN_SHADER_PARAMS
  16. END_SHADER_PARAMS
  17. SHADER_INIT_PARAMS()
  18. {
  19. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  20. }
  21. SHADER_INIT
  22. {
  23. // Load the base texture here!
  24. LoadTexture( BASETEXTURE );
  25. }
  26. SHADER_DRAW
  27. {
  28. if( g_pHardwareConfig->SupportsVertexAndPixelShaders() && !UsingEditor( params ) )
  29. {
  30. // NOTE: This is the DX8, Non-Hammer version.
  31. SHADOW_STATE
  32. {
  33. // Base time lightmap (Need two texture stages)
  34. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  35. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  36. int fmt = VERTEX_POSITION;
  37. pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 );
  38. pShaderShadow->EnableBlending( true );
  39. // Looks backwards, but this is done so that lightmap alpha = 1 when only
  40. // using 1 texture (needed for translucent displacements).
  41. pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA );
  42. worldvertexalpha_Static_Index vshIndex;
  43. pShaderShadow->SetVertexShader( "WorldVertexAlpha", vshIndex.GetIndex() );
  44. pShaderShadow->SetPixelShader( "WorldVertexAlpha" );
  45. FogToFogColor();
  46. }
  47. DYNAMIC_STATE
  48. {
  49. // Bind the base texture (Stage0) and lightmap (Stage1)
  50. BindTexture( SHADER_SAMPLER0, BASETEXTURE );
  51. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
  52. EnablePixelShaderOverbright( 0, true, true );
  53. worldvertexalpha_Dynamic_Index vshIndex;
  54. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  55. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  56. }
  57. Draw();
  58. }
  59. else
  60. {
  61. // NOTE: This is the DX7, Hammer version.
  62. // FIXME: Gary - you need to write a proper non-fixed function shader for this.
  63. SHADOW_STATE
  64. {
  65. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  66. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  67. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  68. pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, OVERBRIGHT );
  69. pShaderShadow->EnableBlending( true );
  70. // Looks backwards, but this is done so that lightmap alpha = 1 when only
  71. // using 1 texture (needed for translucent displacements).
  72. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  73. // pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA );
  74. // Use vertex color for Hammer because it puts the blending alpha in the vertices.
  75. unsigned int colorFlag = 0;
  76. if( UsingEditor( params ) )
  77. {
  78. colorFlag |= SHADER_DRAW_COLOR;
  79. }
  80. pShaderShadow->DrawFlags( colorFlag | SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 |
  81. SHADER_DRAW_LIGHTMAP_TEXCOORD0 );
  82. }
  83. DYNAMIC_STATE
  84. {
  85. BindTexture( SHADER_SAMPLER1, BASETEXTURE );
  86. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP );
  87. }
  88. Draw();
  89. }
  90. }
  91. END_SHADER