Counter Strike : Global Offensive Source Code
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.

108 lines
3.0 KiB

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