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.

111 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "common_hlsl_cpp_consts.h"
  9. BEGIN_VS_SHADER( Sample4x4_Blend, "Help for Sample4x4_Blend" )
  10. BEGIN_SHADER_PARAMS
  11. SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  12. SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "sample4x4_ps20", "Name of the pixel shader to use" )
  13. END_SHADER_PARAMS
  14. SHADER_INIT
  15. {
  16. LoadTexture( BASETEXTURE );
  17. }
  18. SHADER_FALLBACK
  19. {
  20. // Requires DX9 + above
  21. if (!g_pHardwareConfig->SupportsVertexAndPixelShaders())
  22. {
  23. Assert( 0 );
  24. return "Wireframe";
  25. }
  26. return 0;
  27. }
  28. SHADER_DRAW
  29. {
  30. SHADOW_STATE
  31. {
  32. pShaderShadow->EnableDepthWrites( false );
  33. pShaderShadow->EnableAlphaWrites( true );
  34. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  35. int fmt = VERTEX_POSITION;
  36. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  37. pShaderShadow->SetVertexShader( "Downsample_vs20", 0 );
  38. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  39. {
  40. const char *szPixelShader = params[PIXSHADER]->GetStringValue();
  41. size_t iLength = Q_strlen( szPixelShader );
  42. if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader
  43. {
  44. //replace it with the ps20b shader
  45. char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) );
  46. memcpy( szNewName, szPixelShader, sizeof( char ) * iLength );
  47. szNewName[iLength] = 'b';
  48. szNewName[iLength + 1] = '\0';
  49. pShaderShadow->SetPixelShader( szNewName, 0 );
  50. }
  51. else
  52. {
  53. pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  54. }
  55. }
  56. else
  57. {
  58. pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  59. }
  60. pShaderShadow->EnableBlending( true );
  61. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA,
  62. SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  63. }
  64. DYNAMIC_STATE
  65. {
  66. BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
  67. ITexture *src_texture=params[BASETEXTURE]->GetTextureValue();
  68. int width=src_texture->GetActualWidth();
  69. int height=src_texture->GetActualHeight();
  70. float v[4];
  71. float dX = 1.0f / width;
  72. float dY = 1.0f / height;
  73. v[0] = -dX;
  74. v[1] = -dY;
  75. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 );
  76. v[0] = -dX;
  77. v[1] = dY;
  78. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 );
  79. v[0] = dX;
  80. v[1] = -dY;
  81. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 );
  82. v[0] = dX;
  83. v[1] = dY;
  84. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, v, 1 );
  85. pShaderAPI->SetVertexShaderIndex( 0 );
  86. pShaderAPI->SetPixelShaderIndex( 0 );
  87. // store the ALPHA material var into c0
  88. v[0] = ALPHA;
  89. pShaderAPI->SetPixelShaderConstant( 0, v, 1 );
  90. }
  91. Draw();
  92. }
  93. END_SHADER