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.

148 lines
5.0 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1" [vs20] [PC]
  3. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..0" [CONSOLE]
  4. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  5. #include "common_fog_vs_fxc.h"
  6. // DYNAMIC: "SKINNING" "0..1"
  7. // DYNAMIC: "STATIC_LIGHT" "0..1"
  8. // DYNAMIC: "MORPHING" "0..0" [ = false ]
  9. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] [PC]
  10. // DYNAMIC: "NUM_LIGHTS" "0..0" [vs20] [CONSOLE]
  11. // If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
  12. // SKIP: ( $FLATTEN_STATIC_CONTROL_FLOW == 0 ) && ( $NUM_LIGHTS > 0 ) [vs20] [PC]
  13. #include "vortwarp_vs20_helper.h"
  14. static const int g_FogType = DOWATERFOG;
  15. static const bool g_bSkinning = SKINNING ? true : false;
  16. const float4 cTeethLighting : register( SHADER_SPECIFIC_CONST_0 );
  17. #ifdef SHADER_MODEL_VS_3_0
  18. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  19. // cMorphTargetTextureDim.z = 4tuples/morph
  20. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 );
  21. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 );
  22. sampler2D morphSampler : register( s0 );
  23. #endif
  24. struct VS_INPUT
  25. {
  26. // This is all of the stuff that we ever use.
  27. float4 vPos : POSITION;
  28. float4 vBoneWeights : BLENDWEIGHT;
  29. float4 vBoneIndices : BLENDINDICES;
  30. float4 vNormal : NORMAL;
  31. float2 vTexCoord0 : TEXCOORD0;
  32. float4 vUserData : TANGENT; // Sign for cross product in w
  33. // Position and normal/tangent deltas
  34. float3 vPosFlex : POSITION1;
  35. float3 vNormalFlex : NORMAL1;
  36. #ifdef SHADER_MODEL_VS_3_0
  37. float vVertexID : POSITION2;
  38. #endif
  39. };
  40. struct VS_OUTPUT
  41. {
  42. float4 projPos : POSITION;
  43. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  44. float fog : FOG;
  45. #endif
  46. float2 baseTexCoord : TEXCOORD0;
  47. float4 worldVertToEyeVector_Darkening : TEXCOORD1;
  48. float3x3 tangentSpaceTranspose : TEXCOORD2;
  49. // second row : TEXCOORD3;
  50. // third row : TEXCOORD4;
  51. float4 worldPos_projPosZ : TEXCOORD5;
  52. float4 lightAtten0123 : TEXCOORD6;
  53. };
  54. VS_OUTPUT main( const VS_INPUT v )
  55. {
  56. VS_OUTPUT o = ( VS_OUTPUT )0;
  57. float4 vPosition = v.vPos;
  58. float3 vNormal;
  59. float4 vTangent;
  60. DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent );
  61. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  62. ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal, vTangent.xyz );
  63. #else
  64. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ),
  65. vPosition.xyz, vNormal, vTangent.xyz );
  66. #endif
  67. // Perform skinning
  68. float3 worldNormal, worldPos, worldTangentS, worldTangentT;
  69. SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent,
  70. v.vBoneWeights, v.vBoneIndices, worldPos,
  71. worldNormal, worldTangentS, worldTangentT );
  72. // Always normalize since flex path is controlled by runtime
  73. // constant not a shader combo and will always generate the normalization
  74. worldNormal = normalize( worldNormal );
  75. worldTangentS = normalize( worldTangentS );
  76. worldTangentT = normalize( worldTangentT );
  77. // Transform into projection space
  78. o.projPos = mul( float4( worldPos, 1 ), cViewProj );
  79. #ifdef _PS3
  80. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  81. o.projPos.y = -o.projPos.y;
  82. o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
  83. #endif // _PS3
  84. o.worldPos_projPosZ = float4( worldPos, o.projPos.z );
  85. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  86. o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
  87. #endif
  88. // Needed for specular
  89. o.worldVertToEyeVector_Darkening.xyz = cEyePos - worldPos;
  90. // Special darkening of lights for mouth open/close
  91. o.worldVertToEyeVector_Darkening.w = cTeethLighting.w * saturate( dot( worldNormal, cTeethLighting.xyz ) );;
  92. // Scalar light attenuation (mouth darkening applied in pixel shader)
  93. #if ( defined( SHADER_MODEL_VS_2_0 ) && FLATTEN_STATIC_CONTROL_FLOW )
  94. o.lightAtten0123.xyzw = float4(0,0,0,0);
  95. #if ( NUM_LIGHTS > 0 )
  96. o.lightAtten0123.x = GetVertexAttenForLight( worldPos, 0, false );
  97. #endif
  98. #if ( NUM_LIGHTS > 1 )
  99. o.lightAtten0123.y = GetVertexAttenForLight( worldPos, 1, false );
  100. #endif
  101. #if ( NUM_LIGHTS > 2 )
  102. o.lightAtten0123.z = GetVertexAttenForLight( worldPos, 2, false );
  103. #endif
  104. #if ( NUM_LIGHTS > 3 )
  105. o.lightAtten0123.w = GetVertexAttenForLight( worldPos, 3, false );
  106. #endif
  107. #else
  108. o.lightAtten0123.x = GetVertexAttenForLight( worldPos, 0, true );
  109. o.lightAtten0123.y = GetVertexAttenForLight( worldPos, 1, true );
  110. o.lightAtten0123.z = GetVertexAttenForLight( worldPos, 2, true );
  111. o.lightAtten0123.w = GetVertexAttenForLight( worldPos, 3, true );
  112. #endif
  113. o.baseTexCoord = v.vTexCoord0;
  114. // Tangent space transform
  115. o.tangentSpaceTranspose[0] = float3( worldTangentS.x, worldTangentT.x, worldNormal.x );
  116. o.tangentSpaceTranspose[1] = float3( worldTangentS.y, worldTangentT.y, worldNormal.y );
  117. o.tangentSpaceTranspose[2] = float3( worldTangentS.z, worldTangentT.z, worldNormal.z );
  118. return o;
  119. }