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.

164 lines
4.1 KiB

  1. //========= Copyright (c) Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "mathlib/vmatrix.h"
  9. #include "common_hlsl_cpp_consts.h" // hack hack hack!
  10. #include "convar.h"
  11. #include "character_ssao_vs20.inc"
  12. #include "character_ssao_vs30.inc"
  13. #include "character_ssao_ps20.inc"
  14. #include "character_ssao_ps20b.inc"
  15. #include "character_ssao_ps30.inc"
  16. #include "shaderlib/commandbuilder.h"
  17. // NOTE: This has to be the last file included!
  18. #include "tier0/memdbgon.h"
  19. // this shader processes a screen-space normal + depth prepass into screen-space AO for later reference
  20. #define NOISE_SAMPLE 0
  21. BEGIN_VS_SHADER( CharacterSSAO, "Help for CharacterSSAO" )
  22. BEGIN_SHADER_PARAMS
  23. #ifdef NOISE_SAMPLE
  24. SHADER_PARAM( NOISEMAP, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  25. #endif
  26. END_SHADER_PARAMS
  27. SHADER_INIT_PARAMS()
  28. {
  29. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_UNLIT );
  30. }
  31. SHADER_FALLBACK
  32. {
  33. return 0;
  34. }
  35. SHADER_INIT
  36. {
  37. if( params[BASETEXTURE]->IsDefined() )
  38. {
  39. LoadTexture( BASETEXTURE, 0 );
  40. }
  41. #ifdef NOISE_SAMPLE
  42. if( params[NOISEMAP]->IsDefined() )
  43. {
  44. LoadTexture( NOISEMAP, 0 );
  45. }
  46. #endif
  47. }
  48. inline void DrawCharacterSSAO( IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, int vertexCompression )
  49. {
  50. SHADOW_STATE
  51. {
  52. SetInitialShadowState( );
  53. if( params[BASETEXTURE]->IsDefined() )
  54. {
  55. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  56. }
  57. #ifdef NOISE_SAMPLE
  58. if( params[NOISEMAP]->IsDefined() )
  59. {
  60. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  61. }
  62. #endif
  63. unsigned int flags = VERTEX_POSITION;
  64. int nTexCoordCount = 1;
  65. int userDataSize = 0;
  66. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  67. DECLARE_STATIC_VERTEX_SHADER( character_ssao_vs20 );
  68. SET_STATIC_VERTEX_SHADER( character_ssao_vs20 );
  69. if( g_pHardwareConfig->SupportsPixelShaders_3_0() )
  70. {
  71. DECLARE_STATIC_PIXEL_SHADER( character_ssao_ps30 );
  72. SET_STATIC_PIXEL_SHADER_COMBO( QUALITY_MODE, 2 );
  73. SET_STATIC_PIXEL_SHADER( character_ssao_ps30 );
  74. }
  75. else if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  76. {
  77. DECLARE_STATIC_PIXEL_SHADER( character_ssao_ps20b );
  78. SET_STATIC_PIXEL_SHADER_COMBO( QUALITY_MODE, 1 );
  79. SET_STATIC_PIXEL_SHADER( character_ssao_ps20b );
  80. }
  81. else
  82. {
  83. DECLARE_STATIC_PIXEL_SHADER( character_ssao_ps20 );
  84. SET_STATIC_PIXEL_SHADER_COMBO( QUALITY_MODE, 0 );
  85. SET_STATIC_PIXEL_SHADER( character_ssao_ps20 );
  86. }
  87. pShaderShadow->EnableAlphaWrites( false );
  88. pShaderShadow->EnableDepthWrites( false );
  89. pShaderShadow->EnableSRGBWrite( false );
  90. #ifdef NOISE_SAMPLE
  91. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  92. pShaderShadow->EnableBlending( true );
  93. #else
  94. pShaderShadow->EnableBlending( false );
  95. #endif
  96. }
  97. DYNAMIC_STATE
  98. {
  99. pShaderAPI->SetDefaultState();
  100. if( params[BASETEXTURE]->IsDefined() )
  101. {
  102. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, BASETEXTURE, -1 );
  103. }
  104. #ifdef NOISE_SAMPLE
  105. if( params[NOISEMAP]->IsDefined() )
  106. {
  107. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, NOISEMAP, -1 );
  108. }
  109. #endif
  110. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  111. #ifdef NOISE_SAMPLE
  112. float c0[4] = { fmod( pShaderAPI->CurrentTime(), 1.0f ) * 14.54321f, fmod( pShaderAPI->CurrentTime(), 1.0f ) * 16.12345f, 0, 0 };
  113. pShaderAPI->SetPixelShaderConstant( 0, c0, 1 );
  114. #endif
  115. DECLARE_DYNAMIC_VERTEX_SHADER( character_ssao_vs20 );
  116. SET_DYNAMIC_VERTEX_SHADER( character_ssao_vs20 );
  117. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  118. {
  119. DECLARE_DYNAMIC_PIXEL_SHADER( character_ssao_ps20b );
  120. SET_DYNAMIC_PIXEL_SHADER( character_ssao_ps20b );
  121. }
  122. else
  123. {
  124. DECLARE_DYNAMIC_PIXEL_SHADER( character_ssao_ps20 );
  125. SET_DYNAMIC_PIXEL_SHADER( character_ssao_ps20 );
  126. }
  127. }
  128. Draw();
  129. }
  130. SHADER_DRAW
  131. {
  132. DrawCharacterSSAO( params, pShaderShadow, pShaderAPI, vertexCompression );
  133. }
  134. END_SHADER