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.

177 lines
6.1 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "HALFLAMBERT" "0..1"
  3. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1" [vs20] [PC]
  4. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..0" [CONSOLE]
  5. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  6. #include "common_fog_vs_fxc.h"
  7. // DYNAMIC: "SKINNING" "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. // SKIP: $DOWATERFOG
  14. #include "vortwarp_vs20_helper.h"
  15. static const bool g_bSkinning = SKINNING ? true : false;
  16. static const int g_FogType = DOWATERFOG;
  17. const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
  18. const float4 const4 : register( SHADER_SPECIFIC_CONST_4 );
  19. #define g_Time const4.w
  20. #define modelOrigin const4.xyz
  21. #ifdef SHADER_MODEL_VS_3_0
  22. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  23. // cMorphTargetTextureDim.z = 4tuples/morph
  24. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 );
  25. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 );
  26. sampler2D morphSampler : register( s0 );
  27. #endif
  28. //-----------------------------------------------------------------------------
  29. // Input vertex format
  30. //-----------------------------------------------------------------------------
  31. struct VS_INPUT
  32. {
  33. // This is all of the stuff that we ever use.
  34. float4 vPos : POSITION;
  35. float4 vBoneWeights : BLENDWEIGHT;
  36. float4 vBoneIndices : BLENDINDICES;
  37. float4 vNormal : NORMAL;
  38. float4 vColor : COLOR0;
  39. float3 vSpecular : COLOR1;
  40. // make these float2's and stick the [n n 0 1] in the dot math.
  41. float4 vTexCoord0 : TEXCOORD0;
  42. float4 vTexCoord1 : TEXCOORD1;
  43. float4 vTexCoord2 : TEXCOORD2;
  44. float4 vTexCoord3 : TEXCOORD3;
  45. float3 vTangentS : TANGENT;
  46. float3 vTangentT : BINORMAL;
  47. float4 vUserData : TANGENT;
  48. // Position and normal/tangent deltas
  49. float3 vPosFlex : POSITION1;
  50. float3 vNormalFlex : NORMAL1;
  51. #ifdef SHADER_MODEL_VS_3_0
  52. float vVertexID : POSITION2;
  53. #endif
  54. };
  55. //-----------------------------------------------------------------------------
  56. // Output vertex format
  57. //-----------------------------------------------------------------------------
  58. struct VS_OUTPUT
  59. {
  60. float4 projPos : POSITION;
  61. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  62. float fog : FOG;
  63. #endif
  64. float4 baseTexCoord2_tangentSpaceVertToEyeVectorXY : TEXCOORD0;
  65. // bump mapping and a separate envmap mask texture are mutually exclusive.
  66. float4 lightAtten : TEXCOORD1;
  67. float4 worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ : TEXCOORD2;
  68. float3x3 tangentSpaceTranspose : TEXCOORD3;
  69. // second row : TEXCOORD4;
  70. // third row : TEXCOORD5;
  71. float4 worldPos_projPosZ : TEXCOORD6;
  72. };
  73. //-----------------------------------------------------------------------------
  74. // Main shader entry point
  75. //-----------------------------------------------------------------------------
  76. VS_OUTPUT main( const VS_INPUT v )
  77. {
  78. VS_OUTPUT o = ( VS_OUTPUT )0;
  79. float4 vPosition = v.vPos;
  80. float3 vNormal;
  81. float4 vTangent;
  82. DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent );
  83. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  84. ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal, vTangent.xyz );
  85. #else
  86. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ),
  87. vPosition.xyz, vNormal, vTangent.xyz );
  88. #endif
  89. // Perform skinning
  90. float3 worldNormal, worldPos, worldTangentS, worldTangentT;
  91. SkinPositionNormalAndTangentSpace(
  92. g_bSkinning,
  93. vPosition, vNormal, vTangent,
  94. v.vBoneWeights, v.vBoneIndices,
  95. worldPos, worldNormal, worldTangentS, worldTangentT );
  96. WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, worldNormal, worldTangentS, worldTangentT );
  97. // Always normalize since flex path is controlled by runtime
  98. // constant not a shader combo and will always generate the normalization
  99. worldNormal = normalize( worldNormal );
  100. worldTangentS = normalize( worldTangentS );
  101. worldTangentT = normalize( worldTangentT );
  102. // Transform into projection space
  103. float4 projPos = mul( float4( worldPos, 1 ), cViewProj );
  104. o.projPos = projPos;
  105. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  106. o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
  107. #endif
  108. // Needed for water fog alpha and diffuse lighting
  109. // FIXME: we shouldn't have to compute this all the time.
  110. o.worldPos_projPosZ = float4( worldPos, projPos.z );
  111. // Needed for cubemapping + parallax mapping
  112. // FIXME: We shouldn't have to compute this all the time.
  113. o.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz = VSHADER_VECT_SCALE * (cEyePos - worldPos);
  114. #if ( defined ( SHADER_MODEL_VS_2_0 ) && ( FLATTEN_STATIC_CONTROL_FLOW ) )
  115. o.lightAtten = float4(0,0,0,0);
  116. #if ( NUM_LIGHTS > 0 )
  117. o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false );
  118. #endif
  119. #if ( NUM_LIGHTS > 1 )
  120. o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false );
  121. #endif
  122. #if ( NUM_LIGHTS > 2 )
  123. o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false );
  124. #endif
  125. #if ( NUM_LIGHTS > 3 )
  126. o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, false );
  127. #endif
  128. #else
  129. // Scalar light attenuation
  130. o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, true );
  131. o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, true );
  132. o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, true );
  133. o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, true );
  134. #endif
  135. // Base texture coordinate transform
  136. o.baseTexCoord2_tangentSpaceVertToEyeVectorXY.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
  137. o.baseTexCoord2_tangentSpaceVertToEyeVectorXY.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
  138. // Tangent space transform
  139. o.tangentSpaceTranspose[0] = float3( worldTangentS.x, worldTangentT.x, worldNormal.x );
  140. o.tangentSpaceTranspose[1] = float3( worldTangentS.y, worldTangentT.y, worldNormal.y );
  141. o.tangentSpaceTranspose[2] = float3( worldTangentS.z, worldTangentT.z, worldNormal.z );
  142. return o;
  143. }