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.

102 lines
3.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "writez_vs20.inc"
  9. #include "black_ps20.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. // Enables alpha blending workaround for an (apparently) weird color/alpha write disable bug on NVidia GL drivers.
  13. // For NVidia, the actual bug is in glBlitFramebuffer() (it doesn't ignore the currently set colormask), which we fix in glmgr.cpp Blit2(), so I'm disabling this more expensive workaround.
  14. ConVar gl_nvidia_occlusion_workaround( "gl_nvidia_occlusion_workaround", "0" );
  15. ConVar gl_amd_occlusion_workaround( "gl_amd_occlusion_workaround", "1" );
  16. DEFINE_FALLBACK_SHADER( Occlusion, Occlusion_DX9 )
  17. BEGIN_VS_SHADER_FLAGS( Occlusion_DX9, "Help for Occlusion", SHADER_NOT_EDITABLE )
  18. BEGIN_SHADER_PARAMS
  19. END_SHADER_PARAMS
  20. SHADER_INIT_PARAMS()
  21. {
  22. }
  23. SHADER_FALLBACK
  24. {
  25. return 0;
  26. }
  27. SHADER_INIT
  28. {
  29. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  30. }
  31. SHADER_DRAW
  32. {
  33. SHADOW_STATE
  34. {
  35. if ( IsOpenGL() && ( IsPlatformLinux() || IsPlatformWindowsPC() ) && gl_nvidia_occlusion_workaround.GetBool() )
  36. {
  37. // Another workaround is to disable color writes but enable alpha writes (with no blending), which this trashes alpha which may be used in some branches.
  38. // Without either workaround colorwrite enable somehow doesn't get re-enabled in subsequent passes (even though I can clearly see the engine issuing GL calls to set the mask back to 255,255,255,255)
  39. pShaderShadow->EnableColorWrites( true );
  40. pShaderShadow->EnableAlphaWrites( true );
  41. pShaderShadow->EnableBlending( true );
  42. pShaderShadow->BlendFunc( SHADER_BLEND_ZERO, SHADER_BLEND_ONE );
  43. }
  44. else
  45. {
  46. pShaderShadow->EnableColorWrites( false );
  47. pShaderShadow->EnableAlphaWrites( false );
  48. }
  49. pShaderShadow->EnableDepthWrites( false );
  50. DECLARE_STATIC_VERTEX_SHADER( writez_vs20 );
  51. SET_STATIC_VERTEX_SHADER( writez_vs20 );
  52. // No pixel shader on Direct3D, doubles fill rate
  53. if ( g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() )
  54. {
  55. DECLARE_STATIC_PIXEL_SHADER( black_ps20 );
  56. SET_STATIC_PIXEL_SHADER( black_ps20 );
  57. // Workaround for weird AMD bug - if sRGB write isn't enabled here then sRGB write enable in subsequent world rendering passes will randomly not take effect (even though we're enabling it) in the driver.
  58. if ( ( IsPlatformLinux() || IsPlatformWindowsPC() ) && gl_amd_occlusion_workaround.GetBool() )
  59. {
  60. pShaderShadow->EnableSRGBWrite( true );
  61. }
  62. }
  63. // Set stream format (note that this shader supports compression)
  64. unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
  65. int nTexCoordCount = 1;
  66. int userDataSize = 0;
  67. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  68. }
  69. DYNAMIC_STATE
  70. {
  71. DECLARE_DYNAMIC_VERTEX_SHADER( writez_vs20 );
  72. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  73. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  74. SET_DYNAMIC_VERTEX_SHADER( writez_vs20 );
  75. // No pixel shader on Direct3D, doubles fill rate
  76. if ( g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() )
  77. {
  78. DECLARE_DYNAMIC_PIXEL_SHADER( black_ps20 );
  79. SET_DYNAMIC_PIXEL_SHADER( black_ps20 );
  80. }
  81. }
  82. Draw();
  83. }
  84. END_SHADER