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.

178 lines
5.2 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "worldvertexalpha_ps20.inc"
  10. #include "worldvertexalpha_ps20b.inc"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. BEGIN_VS_SHADER( WorldVertexAlpha, "Help for WorldVertexAlpha" )
  14. BEGIN_SHADER_PARAMS
  15. END_SHADER_PARAMS
  16. SHADER_INIT_PARAMS()
  17. {
  18. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  19. SET_FLAGS2( MATERIAL_VAR2_BLEND_WITH_LIGHTMAP_ALPHA );
  20. }
  21. SHADER_INIT
  22. {
  23. // Load the base texture here!
  24. LoadTexture( BASETEXTURE );
  25. }
  26. SHADER_FALLBACK
  27. {
  28. return 0;
  29. }
  30. SHADER_DRAW
  31. {
  32. if( g_pHardwareConfig->SupportsVertexAndPixelShaders() && !UsingEditor( params ) )
  33. {
  34. // DX 9 version with HDR support
  35. // Pass 1
  36. SHADOW_STATE
  37. {
  38. SetInitialShadowState();
  39. pShaderShadow->EnableAlphaWrites( true );
  40. // Base time lightmap (Need two texture stages)
  41. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  42. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  43. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  44. int fmt = VERTEX_POSITION;
  45. pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 );
  46. pShaderShadow->EnableBlending( true );
  47. // Looks backwards, but this is done so that lightmap alpha = 1 when only
  48. // using 1 texture (needed for translucent displacements).
  49. pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA );
  50. pShaderShadow->EnableBlendingSeparateAlpha( true );
  51. pShaderShadow->BlendFuncSeparateAlpha( SHADER_BLEND_ZERO, SHADER_BLEND_SRC_ALPHA );
  52. worldvertexalpha_Static_Index vshIndex;
  53. pShaderShadow->SetVertexShader( "WorldVertexAlpha", vshIndex.GetIndex() );
  54. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  55. {
  56. DECLARE_STATIC_PIXEL_SHADER( worldvertexalpha_ps20b );
  57. SET_STATIC_PIXEL_SHADER_COMBO( PASS, 0 );
  58. SET_STATIC_PIXEL_SHADER( worldvertexalpha_ps20b );
  59. }
  60. else
  61. {
  62. DECLARE_STATIC_PIXEL_SHADER( worldvertexalpha_ps20 );
  63. SET_STATIC_PIXEL_SHADER_COMBO( PASS, 0 );
  64. SET_STATIC_PIXEL_SHADER( worldvertexalpha_ps20 );
  65. }
  66. FogToFogColor();
  67. }
  68. DYNAMIC_STATE
  69. {
  70. // Bind the base texture (Stage0) and lightmap (Stage1)
  71. BindTexture( SHADER_SAMPLER0, false, BASETEXTURE );
  72. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, false, TEXTURE_LIGHTMAP );
  73. worldvertexalpha_Dynamic_Index vshIndex;
  74. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  75. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  76. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  77. {
  78. DECLARE_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20b );
  79. SET_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20b );
  80. }
  81. else
  82. {
  83. DECLARE_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20 );
  84. SET_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20 );
  85. }
  86. }
  87. Draw();
  88. // Pass 2
  89. SHADOW_STATE
  90. {
  91. SetInitialShadowState();
  92. pShaderShadow->EnableAlphaWrites( true );
  93. pShaderShadow->EnableColorWrites( false );
  94. // Base time lightmap (Need two texture stages)
  95. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  96. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  97. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  98. int fmt = VERTEX_POSITION;
  99. pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 );
  100. pShaderShadow->EnableBlending( true );
  101. // Looks backwards, but this is done so that lightmap alpha = 1 when only
  102. // using 1 texture (needed for translucent displacements).
  103. pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA );
  104. pShaderShadow->EnableBlendingSeparateAlpha( true );
  105. pShaderShadow->BlendFuncSeparateAlpha( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  106. worldvertexalpha_Static_Index vshIndex;
  107. pShaderShadow->SetVertexShader( "WorldVertexAlpha", vshIndex.GetIndex() );
  108. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  109. {
  110. DECLARE_STATIC_PIXEL_SHADER( worldvertexalpha_ps20b );
  111. SET_STATIC_PIXEL_SHADER_COMBO( PASS, 1 );
  112. SET_STATIC_PIXEL_SHADER( worldvertexalpha_ps20b );
  113. }
  114. else
  115. {
  116. DECLARE_STATIC_PIXEL_SHADER( worldvertexalpha_ps20 );
  117. SET_STATIC_PIXEL_SHADER_COMBO( PASS, 1 );
  118. SET_STATIC_PIXEL_SHADER( worldvertexalpha_ps20 );
  119. }
  120. FogToFogColor();
  121. }
  122. DYNAMIC_STATE
  123. {
  124. // Bind the base texture (Stage0) and lightmap (Stage1)
  125. BindTexture( SHADER_SAMPLER0, BASETEXTURE );
  126. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, false, TEXTURE_LIGHTMAP );
  127. worldvertexalpha_Dynamic_Index vshIndex;
  128. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  129. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  130. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  131. {
  132. DECLARE_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20b );
  133. SET_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20b );
  134. }
  135. else
  136. {
  137. DECLARE_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20 );
  138. SET_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20 );
  139. }
  140. }
  141. Draw();
  142. }
  143. }
  144. END_SHADER