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.

97 lines
2.7 KiB

  1. //========= Copyright � 1996-2005, 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. // NOTE: This has to be the last file included!
  13. #include "tier0/memdbgon.h"
  14. BEGIN_VS_SHADER_FLAGS( floattoscreen, "Help for floattoscreen", SHADER_NOT_EDITABLE )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  17. SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "floattoscreen_ps20", "Name of the pixel shader to use" )
  18. END_SHADER_PARAMS
  19. SHADER_INIT
  20. {
  21. if( params[FBTEXTURE]->IsDefined() )
  22. {
  23. LoadTexture( FBTEXTURE );
  24. }
  25. }
  26. SHADER_FALLBACK
  27. {
  28. return 0;
  29. }
  30. SHADER_DRAW
  31. {
  32. SHADOW_STATE
  33. {
  34. pShaderShadow->EnableDepthWrites( false );
  35. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  36. int fmt = VERTEX_POSITION;
  37. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  38. // convert from linear to gamma on write.
  39. if ( !IsX360() ) // The 360 is using this shader when it shouldn't...this is just a quick hack to keep things looking right on the 360
  40. {
  41. pShaderShadow->EnableSRGBWrite( true );
  42. }
  43. // Pre-cache shaders
  44. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  45. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  46. // DECLARE_STATIC_PIXEL_SHADER( floattoscreen_ps20 );
  47. // SET_STATIC_PIXEL_SHADER( floattoscreen_ps20 );
  48. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  49. {
  50. const char *szPixelShader = params[PIXSHADER]->GetStringValue();
  51. size_t iLength = Q_strlen( szPixelShader );
  52. if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader
  53. {
  54. //replace it with the ps20b shader
  55. char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) );
  56. memcpy( szNewName, szPixelShader, sizeof( char ) * iLength );
  57. szNewName[iLength] = 'b';
  58. szNewName[iLength + 1] = '\0';
  59. pShaderShadow->SetPixelShader( szNewName, 0 );
  60. }
  61. else
  62. {
  63. pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  64. }
  65. }
  66. else
  67. {
  68. pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  69. }
  70. }
  71. DYNAMIC_STATE
  72. {
  73. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, FBTEXTURE, -1 );
  74. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  75. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  76. // DECLARE_DYNAMIC_PIXEL_SHADER( floattoscreen_ps20 );
  77. // SET_DYNAMIC_PIXEL_SHADER( floattoscreen_ps20 );
  78. pShaderAPI->SetPixelShaderIndex( 0 );
  79. }
  80. Draw();
  81. }
  82. END_SHADER