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.

129 lines
3.8 KiB

  1. //===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: A wet version of base * lightmap
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "cable_vs20.inc"
  10. #include "cable_ps20.inc"
  11. #include "cable_ps20b.inc"
  12. #include "cpp_shader_constant_register_map.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. DEFINE_FALLBACK_SHADER( Cable, Cable_DX9 )
  16. BEGIN_VS_SHADER( Cable_DX9,
  17. "Help for Cable shader" )
  18. BEGIN_SHADER_PARAMS
  19. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "cable/cablenormalmap", "bumpmap texture" )
  20. SHADER_PARAM( MINLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.1", "Minimum amount of light (0-1 value)" )
  21. SHADER_PARAM( MAXLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.3", "Maximum amount of light" )
  22. END_SHADER_PARAMS
  23. SHADER_FALLBACK
  24. {
  25. return 0;
  26. }
  27. SHADER_INIT
  28. {
  29. LoadBumpMap( BUMPMAP );
  30. LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
  31. }
  32. SHADER_DRAW
  33. {
  34. BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true );
  35. bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use
  36. SHADOW_STATE
  37. {
  38. // Enable blending?
  39. if ( IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ) )
  40. {
  41. pShaderShadow->EnableDepthWrites( false );
  42. pShaderShadow->EnableBlending( true );
  43. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  44. }
  45. pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) );
  46. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  47. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  48. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  49. int tCoordDimensions[] = {2,2};
  50. pShaderShadow->VertexShaderVertexFormat(
  51. VERTEX_POSITION | VERTEX_COLOR | VERTEX_TANGENT_S | VERTEX_TANGENT_T,
  52. 2, tCoordDimensions, 0 );
  53. DECLARE_STATIC_VERTEX_SHADER( cable_vs20 );
  54. SET_STATIC_VERTEX_SHADER( cable_vs20 );
  55. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  56. {
  57. DECLARE_STATIC_PIXEL_SHADER( cable_ps20b );
  58. SET_STATIC_PIXEL_SHADER( cable_ps20b );
  59. }
  60. else
  61. {
  62. DECLARE_STATIC_PIXEL_SHADER( cable_ps20 );
  63. SET_STATIC_PIXEL_SHADER( cable_ps20 );
  64. }
  65. // we are writing linear values from this shader.
  66. // This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below.
  67. // The COLOR really decides if we are gamma or linear.
  68. pShaderShadow->EnableSRGBWrite( true );
  69. FogToFogColor();
  70. pShaderShadow->EnableAlphaWrites( bFullyOpaque );
  71. }
  72. DYNAMIC_STATE
  73. {
  74. bool bLightingOnly = g_pConfig->nFullbright == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  75. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, BUMPMAP );
  76. if ( bLightingOnly )
  77. {
  78. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, TEXTURE_GREY );
  79. }
  80. else
  81. {
  82. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, BASETEXTURE );
  83. }
  84. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  85. float vEyePos_SpecExponent[4];
  86. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
  87. vEyePos_SpecExponent[3] = 0.0f;
  88. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
  89. DECLARE_DYNAMIC_VERTEX_SHADER( cable_vs20 );
  90. SET_DYNAMIC_VERTEX_SHADER( cable_vs20 );
  91. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  92. {
  93. DECLARE_DYNAMIC_PIXEL_SHADER( cable_ps20b );
  94. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() );
  95. SET_DYNAMIC_PIXEL_SHADER( cable_ps20b );
  96. }
  97. else
  98. {
  99. DECLARE_DYNAMIC_PIXEL_SHADER( cable_ps20 );
  100. SET_DYNAMIC_PIXEL_SHADER( cable_ps20 );
  101. }
  102. }
  103. Draw();
  104. }
  105. END_SHADER