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.

121 lines
3.3 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_FLAGS( Sample4x4, "Help for Sample4x4", SHADER_NOT_EDITABLE )
  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. // if ( IsAlphaModulating() )
  61. // {
  62. // pShaderShadow->EnableBlending( true );
  63. // pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA,
  64. // SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  65. // }
  66. // else
  67. // {
  68. // pShaderShadow->EnableBlending( true );
  69. // pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA,
  70. // SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  71. // // pShaderShadow->EnableBlending( false );
  72. // }
  73. }
  74. DYNAMIC_STATE
  75. {
  76. BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
  77. ITexture *src_texture=params[BASETEXTURE]->GetTextureValue();
  78. int width=src_texture->GetActualWidth();
  79. int height=src_texture->GetActualHeight();
  80. float v[4];
  81. float dX = 1.0f / width;
  82. float dY = 1.0f / height;
  83. v[0] = -dX;
  84. v[1] = -dY;
  85. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 );
  86. v[0] = -dX;
  87. v[1] = dY;
  88. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 );
  89. v[0] = dX;
  90. v[1] = -dY;
  91. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 );
  92. v[0] = dX;
  93. v[1] = dY;
  94. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, v, 1 );
  95. pShaderAPI->SetVertexShaderIndex( 0 );
  96. pShaderAPI->SetPixelShaderIndex( 0 );
  97. // store the ALPHA material var into c0
  98. v[0] = ALPHA;
  99. pShaderAPI->SetPixelShaderConstant( 0, v, 1 );
  100. }
  101. Draw();
  102. }
  103. END_SHADER