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.

121 lines
3.9 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 "floatcombine_autoexpose_ps20.inc"
  10. #include "floatcombine_autoexpose_ps20b.inc"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. BEGIN_VS_SHADER( floatcombine_autoexpose, "Help for floatcombine_autoexpose" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( BLOOMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  16. SHADER_PARAM( SHARPNESS, SHADER_PARAM_TYPE_FLOAT, "1", "" )
  17. SHADER_PARAM( WOODCUT, SHADER_PARAM_TYPE_FLOAT, "0", "" )
  18. SHADER_PARAM( VIGNETTE_MIN_BRIGHT,SHADER_PARAM_TYPE_FLOAT,"1","")
  19. SHADER_PARAM( VIGNETTE_POWER,SHADER_PARAM_TYPE_FLOAT,"4","")
  20. SHADER_PARAM( EDGE_SOFTNESS,SHADER_PARAM_TYPE_FLOAT,"0","")
  21. SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
  22. SHADER_PARAM( BLOOMEXPONENT, SHADER_PARAM_TYPE_FLOAT, "2.0", "" )
  23. SHADER_PARAM( ALPHASHARPENFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  24. SHADER_PARAM( EXPOSURE_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  25. SHADER_PARAM( AUTOEXPOSE_MIN, SHADER_PARAM_TYPE_FLOAT, ".5", "" )
  26. SHADER_PARAM( AUTOEXPOSE_MAX, SHADER_PARAM_TYPE_FLOAT, "2", "" )
  27. END_SHADER_PARAMS
  28. SHADER_INIT
  29. {
  30. if( params[BASETEXTURE]->IsDefined() )
  31. {
  32. LoadTexture( BASETEXTURE );
  33. }
  34. if( params[BLOOMTEXTURE]->IsDefined() )
  35. {
  36. LoadTexture( BLOOMTEXTURE );
  37. }
  38. if( params[EXPOSURE_TEXTURE]->IsDefined() )
  39. {
  40. LoadTexture( EXPOSURE_TEXTURE );
  41. }
  42. }
  43. SHADER_FALLBACK
  44. {
  45. return 0;
  46. }
  47. SHADER_DRAW
  48. {
  49. SHADOW_STATE
  50. {
  51. pShaderShadow->EnableDepthWrites( false );
  52. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  53. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  54. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  55. int fmt = VERTEX_POSITION;
  56. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  57. // convert from linear to gamma on write.
  58. pShaderShadow->EnableSRGBWrite( true );
  59. // Pre-cache shaders
  60. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  61. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  62. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  63. {
  64. DECLARE_STATIC_PIXEL_SHADER( floatcombine_autoexpose_ps20b );
  65. SET_STATIC_PIXEL_SHADER( floatcombine_autoexpose_ps20b );
  66. }
  67. else
  68. {
  69. DECLARE_STATIC_PIXEL_SHADER( floatcombine_autoexpose_ps20 );
  70. SET_STATIC_PIXEL_SHADER( floatcombine_autoexpose_ps20 );
  71. }
  72. }
  73. DYNAMIC_STATE
  74. {
  75. float c0[4]={params[SHARPNESS]->GetFloatValue(),
  76. params[WOODCUT]->GetFloatValue(),
  77. params[BLOOMAMOUNT]->GetFloatValue(),
  78. params[ALPHASHARPENFACTOR]->GetFloatValue()};
  79. float c1[4]={params[BLOOMEXPONENT]->GetFloatValue(),
  80. params[VIGNETTE_MIN_BRIGHT]->GetFloatValue(),
  81. params[VIGNETTE_POWER]->GetFloatValue(),
  82. params[EDGE_SOFTNESS]->GetFloatValue()};
  83. float c2[4]={params[AUTOEXPOSE_MIN]->GetFloatValue(),
  84. params[AUTOEXPOSE_MAX]->GetFloatValue(),
  85. 0,0};
  86. pShaderAPI->SetPixelShaderConstant( 0, c0, 1 );
  87. pShaderAPI->SetPixelShaderConstant( 1, c1, 1 );
  88. pShaderAPI->SetPixelShaderConstant( 2, c2, 1 );
  89. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, BASETEXTURE, -1 );
  90. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, BLOOMTEXTURE, -1 );
  91. BindTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_NONE, EXPOSURE_TEXTURE, -1 );
  92. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  93. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 );
  94. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  95. {
  96. DECLARE_DYNAMIC_PIXEL_SHADER( floatcombine_autoexpose_ps20b );
  97. SET_DYNAMIC_PIXEL_SHADER( floatcombine_autoexpose_ps20b );
  98. }
  99. else
  100. {
  101. DECLARE_DYNAMIC_PIXEL_SHADER( floatcombine_autoexpose_ps20 );
  102. SET_DYNAMIC_PIXEL_SHADER( floatcombine_autoexpose_ps20 );
  103. }
  104. }
  105. Draw();
  106. }
  107. END_SHADER