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.

152 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "convar.h"
  9. #include "portalstaticoverlay_vs11.inc"
  10. #include "portalstaticoverlay_ps11.inc"
  11. BEGIN_VS_SHADER( PortalStaticOverlay,
  12. "Help for PortalStaticOverlay shader" )
  13. BEGIN_SHADER_PARAMS
  14. SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE )
  15. SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE )
  16. SHADER_PARAM( STATICAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of the static blend texture to blend into the base texture" )
  17. SHADER_PARAM( STATICBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "When adding static, this is the texture that gets blended in" )
  18. SHADER_PARAM( STATICBLENDTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  19. SHADER_PARAM( ALPHAMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "An alpha mask for odd shaped portals" )
  20. SHADER_PARAM( ALPHAMASKTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  21. SHADER_PARAM( NOCOLORWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  22. END_SHADER_PARAMS
  23. SHADER_INIT_PARAMS()
  24. {
  25. SET_FLAGS( MATERIAL_VAR_TRANSLUCENT );
  26. }
  27. SHADER_FALLBACK
  28. {
  29. if( !g_pHardwareConfig->SupportsVertexAndPixelShaders() )
  30. return "PortalStaticOverlay_DX60";
  31. return 0;
  32. }
  33. SHADER_INIT
  34. {
  35. if( params[STATICBLENDTEXTURE]->IsDefined() )
  36. LoadTexture( STATICBLENDTEXTURE );
  37. if( params[ALPHAMASKTEXTURE]->IsDefined() )
  38. LoadTexture( ALPHAMASKTEXTURE );
  39. if( !params[STATICAMOUNT]->IsDefined() )
  40. params[STATICAMOUNT]->SetFloatValue( 0.0f );
  41. if( !params[STATICBLENDTEXTURE]->IsDefined() )
  42. params[STATICBLENDTEXTURE]->SetIntValue( 0 );
  43. if( !params[STATICBLENDTEXTUREFRAME]->IsDefined() )
  44. params[STATICBLENDTEXTUREFRAME]->SetIntValue( 0 );
  45. if( !params[ALPHAMASKTEXTURE]->IsDefined() )
  46. params[ALPHAMASKTEXTURE]->SetIntValue( 0 );
  47. if( !params[ALPHAMASKTEXTUREFRAME]->IsDefined() )
  48. params[ALPHAMASKTEXTUREFRAME]->SetIntValue( 0 );
  49. if( !params[NOCOLORWRITE]->IsDefined() )
  50. params[NOCOLORWRITE]->SetIntValue( 0 );
  51. }
  52. SHADER_DRAW
  53. {
  54. bool bStaticBlendTexture = params[STATICBLENDTEXTURE]->IsTexture();
  55. bool bAlphaMaskTexture = params[ALPHAMASKTEXTURE]->IsTexture();
  56. bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL );
  57. SHADOW_STATE
  58. {
  59. SetInitialShadowState();
  60. FogToFogColor();
  61. //pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); //a portal is effectively a decal on top of a wall
  62. pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL );
  63. pShaderShadow->EnableDepthWrites( true );
  64. pShaderShadow->EnableBlending( true );
  65. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  66. pShaderShadow->EnableAlphaTest( true );
  67. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f );
  68. pShaderShadow->EnableColorWrites( params[NOCOLORWRITE]->GetIntValue() == 0 );
  69. if( bStaticBlendTexture || bAlphaMaskTexture )
  70. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  71. if( bStaticBlendTexture && bAlphaMaskTexture )
  72. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  73. int fmt = VERTEX_POSITION | VERTEX_NORMAL;
  74. int userDataSize = 0;
  75. if( bIsModel )
  76. {
  77. userDataSize = 4;
  78. }
  79. else
  80. {
  81. fmt |= VERTEX_TANGENT_S | VERTEX_TANGENT_T;
  82. }
  83. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, userDataSize );
  84. DECLARE_STATIC_VERTEX_SHADER( portalstaticoverlay_vs11 );
  85. SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel );
  86. SET_STATIC_VERTEX_SHADER( portalstaticoverlay_vs11 );
  87. DECLARE_STATIC_PIXEL_SHADER( portalstaticoverlay_ps11 );
  88. SET_STATIC_PIXEL_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture );
  89. SET_STATIC_PIXEL_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture );
  90. SET_STATIC_PIXEL_SHADER( portalstaticoverlay_ps11 );
  91. }
  92. DYNAMIC_STATE
  93. {
  94. pShaderAPI->SetDefaultState();
  95. float fStaticAmount = params[STATICAMOUNT]->GetFloatValue();
  96. //x is static, y is inverse static
  97. float pc0[4] = { fStaticAmount, 1.0f - fStaticAmount, 0.0f, 0.0f };
  98. pShaderAPI->SetPixelShaderConstant( 0, pc0 );
  99. if( bStaticBlendTexture )
  100. {
  101. BindTexture( SHADER_SAMPLER0, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME );
  102. if( bAlphaMaskTexture )
  103. BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME );
  104. }
  105. else if( bAlphaMaskTexture )
  106. {
  107. BindTexture( SHADER_SAMPLER0, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME );
  108. }
  109. DECLARE_DYNAMIC_VERTEX_SHADER( portalstaticoverlay_vs11 );
  110. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  111. SET_DYNAMIC_VERTEX_SHADER( portalstaticoverlay_vs11 );
  112. DECLARE_DYNAMIC_PIXEL_SHADER( portalstaticoverlay_ps11 );
  113. SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() );
  114. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  115. SET_DYNAMIC_PIXEL_SHADER( portalstaticoverlay_ps11 );
  116. }
  117. Draw();
  118. }
  119. END_SHADER