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.

141 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A wet version of base * lightmap
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "cable_vs20.inc"
  10. #include "cable_ps20.inc"
  11. #include "cable_ps20b.inc"
  12. #include "cpp_shader_constant_register_map.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. extern ConVar mat_fullbright;
  16. DEFINE_FALLBACK_SHADER( Cable, Cable_DX9 )
  17. BEGIN_VS_SHADER( Cable_DX9,
  18. "Help for Cable shader" )
  19. BEGIN_SHADER_PARAMS
  20. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "cable/cablenormalmap", "bumpmap texture" )
  21. SHADER_PARAM( MINLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.1", "Minimum amount of light (0-1 value)" )
  22. SHADER_PARAM( MAXLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.3", "Maximum amount of light" )
  23. END_SHADER_PARAMS
  24. SHADER_FALLBACK
  25. {
  26. if ( !(g_pHardwareConfig->SupportsPixelShaders_2_0() && g_pHardwareConfig->SupportsVertexShaders_2_0()) ||
  27. (g_pHardwareConfig->GetDXSupportLevel() < 90) )
  28. {
  29. return "Cable_DX8";
  30. }
  31. return 0;
  32. }
  33. SHADER_INIT
  34. {
  35. LoadBumpMap( BUMPMAP );
  36. LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
  37. }
  38. SHADER_DRAW
  39. {
  40. BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true );
  41. bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use
  42. SHADOW_STATE
  43. {
  44. // Enable blending?
  45. if ( IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ) )
  46. {
  47. pShaderShadow->EnableDepthWrites( false );
  48. pShaderShadow->EnableBlending( true );
  49. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  50. }
  51. pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) );
  52. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  53. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  54. if ( g_pHardwareConfig->GetDXSupportLevel() >= 90)
  55. {
  56. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  57. }
  58. int tCoordDimensions[] = {2,2};
  59. pShaderShadow->VertexShaderVertexFormat(
  60. VERTEX_POSITION | VERTEX_COLOR | VERTEX_TANGENT_S | VERTEX_TANGENT_T,
  61. 2, tCoordDimensions, 0 );
  62. DECLARE_STATIC_VERTEX_SHADER( cable_vs20 );
  63. SET_STATIC_VERTEX_SHADER( cable_vs20 );
  64. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  65. {
  66. DECLARE_STATIC_PIXEL_SHADER( cable_ps20b );
  67. SET_STATIC_PIXEL_SHADER( cable_ps20b );
  68. }
  69. else
  70. {
  71. DECLARE_STATIC_PIXEL_SHADER( cable_ps20 );
  72. SET_STATIC_PIXEL_SHADER( cable_ps20 );
  73. }
  74. // we are writing linear values from this shader.
  75. // This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below.
  76. // The COLOR really decides if we are gamma or linear.
  77. pShaderShadow->EnableSRGBWrite( true );
  78. FogToFogColor();
  79. pShaderShadow->EnableAlphaWrites( bFullyOpaque );
  80. }
  81. DYNAMIC_STATE
  82. {
  83. bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  84. BindTexture( SHADER_SAMPLER0, BUMPMAP );
  85. if ( bLightingOnly )
  86. {
  87. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY );
  88. }
  89. else
  90. {
  91. BindTexture( SHADER_SAMPLER1, BASETEXTURE );
  92. }
  93. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  94. float vEyePos_SpecExponent[4];
  95. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
  96. vEyePos_SpecExponent[3] = 0.0f;
  97. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
  98. DECLARE_DYNAMIC_VERTEX_SHADER( cable_vs20 );
  99. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  100. SET_DYNAMIC_VERTEX_SHADER( cable_vs20 );
  101. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  102. {
  103. DECLARE_DYNAMIC_PIXEL_SHADER( cable_ps20b );
  104. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  105. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() );
  106. SET_DYNAMIC_PIXEL_SHADER( cable_ps20b );
  107. }
  108. else
  109. {
  110. DECLARE_DYNAMIC_PIXEL_SHADER( cable_ps20 );
  111. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  112. SET_DYNAMIC_PIXEL_SHADER( cable_ps20 );
  113. }
  114. }
  115. Draw();
  116. }
  117. END_SHADER