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.

153 lines
4.5 KiB

  1. //========= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. //Note: Not upgraded to vs/ps 2.0 fxc's because this shader is unused and there are no test cases to verify against.
  9. #include "BaseVSShader.h"
  10. #if !defined( _X360 ) && !defined( _PS3 )
  11. #include "shadowmodel_ps20.inc"
  12. #include "shadowmodel_vs20.inc"
  13. #endif
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. DEFINE_FALLBACK_SHADER( ShadowModel, ShadowModel_DX9 )
  17. #if !defined( _X360 ) && !defined( _PS3 ) //not used for anything at time of 360/PS3 ship, and we want to avoid storing/loading assembly shaders
  18. //PC version
  19. BEGIN_VS_SHADER_FLAGS( ShadowModel_DX9, "Help for ShadowModel", SHADER_NOT_EDITABLE )
  20. BEGIN_SHADER_PARAMS
  21. SHADER_PARAM( BASETEXTUREOFFSET, SHADER_PARAM_TYPE_VEC2, "[0 0]", "$baseTexture texcoord offset" )
  22. SHADER_PARAM( BASETEXTURESCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "$baseTexture texcoord scale" )
  23. SHADER_PARAM( FALLOFFOFFSET, SHADER_PARAM_TYPE_FLOAT, "0", "Distance at which shadow starts to fade" )
  24. SHADER_PARAM( FALLOFFDISTANCE, SHADER_PARAM_TYPE_FLOAT, "100", "Max shadow distance" )
  25. SHADER_PARAM( FALLOFFAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.9", "Amount to brighten the shadow at max dist" )
  26. END_SHADER_PARAMS
  27. SHADER_INIT_PARAMS()
  28. {
  29. if (!params[BASETEXTURESCALE]->IsDefined())
  30. {
  31. Vector2D scale(1, 1);
  32. params[BASETEXTURESCALE]->SetVecValue( scale.Base(), 2 );
  33. }
  34. if (!params[FALLOFFDISTANCE]->IsDefined())
  35. params[FALLOFFDISTANCE]->SetFloatValue( 100.0f );
  36. if (!params[FALLOFFAMOUNT]->IsDefined())
  37. params[FALLOFFAMOUNT]->SetFloatValue( 0.9f );
  38. }
  39. SHADER_FALLBACK
  40. {
  41. return 0;
  42. }
  43. SHADER_INIT
  44. {
  45. if (params[BASETEXTURE]->IsDefined())
  46. {
  47. LoadTexture( BASETEXTURE );
  48. }
  49. }
  50. SHADER_DRAW
  51. {
  52. SHADOW_STATE
  53. {
  54. // Base texture on stage 0
  55. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  56. // Multiplicative blending state...
  57. EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO );
  58. int fmt = VERTEX_POSITION | VERTEX_NORMAL;
  59. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  60. DECLARE_STATIC_VERTEX_SHADER( shadowmodel_vs20 );
  61. SET_STATIC_VERTEX_SHADER( shadowmodel_vs20 );
  62. DECLARE_STATIC_PIXEL_SHADER( shadowmodel_ps20 );
  63. SET_STATIC_PIXEL_SHADER( shadowmodel_ps20 );
  64. // We need to fog to *white* regardless of overbrighting...
  65. FogToWhite();
  66. // The constant color is the shadow color...
  67. PI_BeginCommandBuffer();
  68. PI_SetModulationVertexShaderDynamicState();
  69. PI_EndCommandBuffer();
  70. }
  71. DYNAMIC_STATE
  72. {
  73. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, BASETEXTURE, FRAME );
  74. SetVertexShaderMatrix3x4( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  75. SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, BASETEXTUREOFFSET );
  76. SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURESCALE );
  77. Vector4D shadow;
  78. shadow[0] = params[FALLOFFOFFSET]->GetFloatValue();
  79. shadow[1] = params[FALLOFFDISTANCE]->GetFloatValue() + shadow[0];
  80. if (shadow[1] != 0.0f)
  81. shadow[1] = 1.0f / shadow[1];
  82. shadow[2] = params[FALLOFFAMOUNT]->GetFloatValue();
  83. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, shadow.Base(), 1 );
  84. DECLARE_DYNAMIC_VERTEX_SHADER( shadowmodel_vs20 );
  85. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  86. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  87. SET_DYNAMIC_VERTEX_SHADER( shadowmodel_vs20 );
  88. DECLARE_DYNAMIC_PIXEL_SHADER( shadowmodel_ps20 );
  89. SET_DYNAMIC_PIXEL_SHADER( shadowmodel_ps20 );
  90. }
  91. Draw( );
  92. }
  93. END_SHADER
  94. #else
  95. //360 and PS3 version
  96. BEGIN_VS_SHADER_FLAGS( ShadowModel_DX9, "Help for ShadowModel", SHADER_NOT_EDITABLE )
  97. BEGIN_SHADER_PARAMS
  98. SHADER_PARAM( BASETEXTUREOFFSET, SHADER_PARAM_TYPE_VEC2, "[0 0]", "$baseTexture texcoord offset" )
  99. SHADER_PARAM( BASETEXTURESCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "$baseTexture texcoord scale" )
  100. SHADER_PARAM( FALLOFFOFFSET, SHADER_PARAM_TYPE_FLOAT, "0", "Distance at which shadow starts to fade" )
  101. SHADER_PARAM( FALLOFFDISTANCE, SHADER_PARAM_TYPE_FLOAT, "100", "Max shadow distance" )
  102. SHADER_PARAM( FALLOFFAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.9", "Amount to brighten the shadow at max dist" )
  103. END_SHADER_PARAMS
  104. SHADER_INIT_PARAMS()
  105. {
  106. }
  107. SHADER_FALLBACK
  108. {
  109. return 0;
  110. }
  111. SHADER_INIT
  112. {
  113. }
  114. SHADER_DRAW
  115. {
  116. Draw( false );
  117. }
  118. END_SHADER
  119. #endif