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.

93 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "screenspaceeffect_vs20.inc"
  9. #include "floattoscreen_ps20.inc"
  10. #include "floattoscreen_ps20b.inc"
  11. #include "convar.h"
  12. BEGIN_VS_SHADER_FLAGS( floattoscreen, "Help for floattoscreen", SHADER_NOT_EDITABLE )
  13. BEGIN_SHADER_PARAMS
  14. SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  15. SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "floattoscreen_ps20", "Name of the pixel shader to use" )
  16. END_SHADER_PARAMS
  17. SHADER_INIT
  18. {
  19. if( params[FBTEXTURE]->IsDefined() )
  20. {
  21. LoadTexture( FBTEXTURE );
  22. }
  23. }
  24. SHADER_FALLBACK
  25. {
  26. // Requires DX9 + above
  27. if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  28. return "Wireframe";
  29. return 0;
  30. }
  31. SHADER_DRAW
  32. {
  33. SHADOW_STATE
  34. {
  35. pShaderShadow->EnableDepthWrites( false );
  36. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  37. int fmt = VERTEX_POSITION;
  38. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  39. // convert from linear to gamma on write.
  40. pShaderShadow->EnableSRGBWrite( true );
  41. // Pre-cache shaders
  42. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  43. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  44. // DECLARE_STATIC_PIXEL_SHADER( floattoscreen_ps20 );
  45. // SET_STATIC_PIXEL_SHADER( floattoscreen_ps20 );
  46. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  47. {
  48. const char *szPixelShader = params[PIXSHADER]->GetStringValue();
  49. size_t iLength = Q_strlen( szPixelShader );
  50. if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader
  51. {
  52. //replace it with the ps20b shader
  53. char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) );
  54. memcpy( szNewName, szPixelShader, sizeof( char ) * iLength );
  55. szNewName[iLength] = 'b';
  56. szNewName[iLength + 1] = '\0';
  57. pShaderShadow->SetPixelShader( szNewName, 0 );
  58. }
  59. else
  60. {
  61. pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  62. }
  63. }
  64. else
  65. {
  66. pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  67. }
  68. }
  69. DYNAMIC_STATE
  70. {
  71. BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 );
  72. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  73. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  74. // DECLARE_DYNAMIC_PIXEL_SHADER( floattoscreen_ps20 );
  75. // SET_DYNAMIC_PIXEL_SHADER( floattoscreen_ps20 );
  76. pShaderAPI->SetPixelShaderIndex( 0 );
  77. }
  78. Draw();
  79. }
  80. END_SHADER