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.

172 lines
4.6 KiB

  1. // STATIC: "ONLY_PROJECT_POSITION" "0..1" [XBOX]
  2. // STATIC: "ONLY_PROJECT_POSITION" "0..0" [PC]
  3. // STATIC: "ONLY_PROJECT_POSITION" "0..0" [SONYPS3]
  4. // STATIC: "TREESWAY" "0..2"
  5. // STATIC: "COLOR_DEPTH" "0..1"
  6. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  7. // DYNAMIC: "SKINNING" "0..1"
  8. // DYNAMIC: "MORPHING" "0..0" [ = false ]
  9. // DYNAMIC: "TESSELLATION" "0..0" [vs30] [PC]
  10. // DYNAMIC: "TESSELLATION" "0..0" [CONSOLE]
  11. // DYNAMIC: "TESSELLATION" "0..0" [vs20] [PC]
  12. // SKIP: ( $MORPHING || $SKINNING || $COMPRESSED_VERTS ) && $TESSELLATION
  13. // Disabling morphing in CS:GO, otherwise this shader causes an Internal Driver Error on the first Present() under Windows XP ATI X1650.
  14. #if MORPHING
  15. #undef MORPHING
  16. #define MORPHING 0
  17. #endif
  18. #include "common_vs_fxc.h"
  19. static const bool g_bSkinning = SKINNING ? true : false;
  20. #if defined( SHADER_MODEL_VS_3_0 ) && MORPHING
  21. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  22. // cMorphTargetTextureDim.z = 4tuples/morph
  23. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 );
  24. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 );
  25. sampler2D morphSampler : register( s0 );
  26. #endif
  27. #if ( TREESWAY )
  28. const float4 g_vTreeSwayParams0 : register( SHADER_SPECIFIC_CONST_2 );
  29. const float4 g_vTreeSwayParams1 : register( SHADER_SPECIFIC_CONST_3 );
  30. const float4 g_vTreeSwayParams2 : register( SHADER_SPECIFIC_CONST_4 );
  31. const float4 g_vTreeSwayParams3 : register( SHADER_SPECIFIC_CONST_5 );
  32. const float4 g_vTreeSwayParams4 : register( SHADER_SPECIFIC_CONST_9 );
  33. #define g_flTime g_vTreeSwayParams0.x
  34. #define g_vWindDir g_vTreeSwayParams0.yz
  35. #define g_flScrumbleFalloffCurve g_vTreeSwayParams1.x
  36. #define g_flSwayFalloffCurve g_vTreeSwayParams1.y
  37. #define g_flScrumbleSpeed g_vTreeSwayParams1.z
  38. #define g_flFastSwaySpeedScale g_vTreeSwayParams1.w
  39. #define g_flHeight g_vTreeSwayParams2.x
  40. #define g_flStartHeight g_vTreeSwayParams2.y
  41. #define g_flRadius g_vTreeSwayParams2.z
  42. #define g_flStartRadius g_vTreeSwayParams2.w
  43. #define g_flSwaySpeed g_vTreeSwayParams3.x
  44. #define g_flSwayIntensity g_vTreeSwayParams3.y
  45. #define g_flScrumbleWaveCount g_vTreeSwayParams3.z
  46. #define g_flScrumbleIntensity g_vTreeSwayParams3.w
  47. #define g_flWindSpeedLerpStart g_vTreeSwayParams4.x
  48. #define g_flWindSpeedLerpEnd g_vTreeSwayParams4.y
  49. #endif
  50. #if TESSELLATION
  51. #include "tessellation_vs_fxc.h"
  52. const float4 g_SubDControls : register( SHADER_SPECIFIC_CONST_8 );
  53. sampler2D BezierSampler : register( s1 );
  54. sampler2D DispSampler : register( s2 );
  55. // VS_INPUT defined in header
  56. #else // no TESSELLATION
  57. struct VS_INPUT
  58. {
  59. float4 vPos : POSITION;
  60. float2 vTexCoord : TEXCOORD0;
  61. float4 vBoneWeights : BLENDWEIGHT;
  62. float4 vBoneIndices : BLENDINDICES;
  63. // Position delta stream
  64. float3 vPosFlex : POSITION1;
  65. #if defined( SHADER_MODEL_VS_3_0 ) && MORPHING
  66. float vVertexID : POSITION2;
  67. #endif
  68. };
  69. #endif // TESSELLATION
  70. struct VS_OUTPUT
  71. {
  72. float4 vProjPos : POSITION;
  73. #if (ONLY_PROJECT_POSITION == 0) //360 sometimes runs without the pixel shader component, but has to patch this output if it does.
  74. float2 texCoord : TEXCOORD0;
  75. #endif
  76. #if COLOR_DEPTH
  77. float4 vWorldPos_projPosZ : TEXCOORD1;
  78. #endif
  79. };
  80. #include "tree_sway.h"
  81. VS_OUTPUT main( const VS_INPUT v )
  82. {
  83. VS_OUTPUT o = ( VS_OUTPUT )0;
  84. float3 worldPos;
  85. #if ( TESSELLATION )
  86. {
  87. float2 detailUV, baseUV;
  88. float3 worldNormal, worldTangentS, worldTangentT;
  89. EvaluateSubdivisionSurface( v, g_SubDControls.x, g_SubDControls.y, g_SubDControls.z, BezierSampler, DispSampler, worldNormal, worldPos, baseUV, detailUV );
  90. #if (ONLY_PROJECT_POSITION == 0)
  91. {
  92. o.texCoord = baseUV;
  93. }
  94. #endif
  95. }
  96. #else // not tessellating
  97. {
  98. float4 vPosition = v.vPos;
  99. #if ( !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING )
  100. {
  101. ApplyMorph( v.vPosFlex, vPosition.xyz );
  102. }
  103. #else
  104. {
  105. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3(0, 0, 0), vPosition.xyz );
  106. }
  107. #endif
  108. #if ( TREESWAY )
  109. {
  110. vPosition.xyz = ComputeTreeSway( vPosition.xyz, g_flTime );
  111. }
  112. #endif
  113. SkinPosition( g_bSkinning, vPosition, v.vBoneWeights, v.vBoneIndices, worldPos );
  114. #if ( ONLY_PROJECT_POSITION == 0 )
  115. {
  116. o.texCoord = v.vTexCoord;
  117. }
  118. #endif
  119. }
  120. #endif
  121. float4 vProjPos = mul( float4( worldPos, 1.0f ), cViewProj );
  122. o.vProjPos = vProjPos;
  123. #if ( COLOR_DEPTH && !ONLY_PROJECT_POSITION )
  124. o.vWorldPos_projPosZ.z = vProjPos.z;
  125. o.vWorldPos_projPosZ.w = vProjPos.w;
  126. #endif
  127. #ifdef _PS3
  128. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  129. o.projPos.y = -o.projPos.y;
  130. o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
  131. #endif // _PS3
  132. return o;
  133. }