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.

149 lines
4.1 KiB

  1. // based on vertexlit_and_unlit_generic_vs20.fxc
  2. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  3. // STATIC: "VERTEXCOLOR" "0..1"
  4. // STATIC: "LIGHTING_PREVIEW" "0..1" [PC]
  5. // STATIC: "LIGHTING_PREVIEW" "0..0" [CONSOLE]
  6. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  7. #include "common_fog_vs_fxc.h"
  8. // DYNAMIC: "SKINNING" "0..0" [vs20]
  9. // DYNAMIC: "SKINNING" "0..1" [vs30]
  10. // DYNAMIC: "MORPHING" "0..0" [ = false ]
  11. #include "common_vs_fxc.h"
  12. static const bool g_bSkinning = SKINNING ? true : false;
  13. static const int g_FogType = DOWATERFOG;
  14. static const bool g_bVertexColor = VERTEXCOLOR ? true : false;
  15. #if ( defined( SHADER_MODEL_VS_3_0 ) && MORPHING )
  16. #define DECALOFFSET 1
  17. #else
  18. #define DECALOFFSET 0
  19. #endif
  20. const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
  21. #if defined( SHADER_MODEL_VS_3_0 ) && MORPHING
  22. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  23. // cMorphTargetTextureDim.z = 4tuples/morph
  24. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_10 );
  25. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_11 );
  26. sampler2D morphSampler : register( s0 );
  27. #endif
  28. struct VS_INPUT
  29. {
  30. // This is all of the stuff that we ever use.
  31. float4 vPos : POSITION;
  32. float4 vBoneWeights : BLENDWEIGHT;
  33. float4 vBoneIndices : BLENDINDICES;
  34. float4 vNormal : NORMAL;
  35. float4 vColor : COLOR0;
  36. float3 vSpecular : COLOR1;
  37. // make these float2's and stick the [n n 0 1] in the dot math.
  38. float4 vTexCoord0 : TEXCOORD0;
  39. float4 vTexCoord1 : TEXCOORD1;
  40. float4 vTexCoord2 : TEXCOORD2;
  41. float4 vTexCoord3 : TEXCOORD3;
  42. // Position and normal/tangent deltas
  43. float3 vPosFlex : POSITION1;
  44. float3 vNormalFlex : NORMAL1;
  45. #ifdef SHADER_MODEL_VS_3_0
  46. float vVertexID : POSITION2;
  47. #endif
  48. };
  49. struct VS_OUTPUT
  50. {
  51. float4 projPos : POSITION; // Projection-space position
  52. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  53. float fog : FOG;
  54. #endif
  55. float2 baseTexCoord : TEXCOORD0; // Base texture coordinate
  56. float4 worldPos_ProjPosZ : TEXCOORD1;
  57. float4 color : COLOR1; // Vertex color (from lighting or unlit)
  58. };
  59. VS_OUTPUT main( const VS_INPUT v )
  60. {
  61. VS_OUTPUT o = ( VS_OUTPUT )0;
  62. float4 vPosition = v.vPos;
  63. float3 vNormal = 0;
  64. if ( LIGHTING_PREVIEW || DECALOFFSET )
  65. {
  66. // The vertex only contains valid normals if they are actually needed (fetching them when absent makes D3D complain)
  67. DecompressVertex_Normal( v.vNormal, vNormal );
  68. }
  69. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  70. ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal );
  71. #else
  72. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect,
  73. v.vVertexID, v.vTexCoord2, vPosition.xyz, vNormal );
  74. #endif
  75. // Perform skinning
  76. float3 worldNormal, worldPos;
  77. SkinPositionAndNormal(
  78. g_bSkinning,
  79. vPosition, vNormal,
  80. v.vBoneWeights, v.vBoneIndices,
  81. worldPos, worldNormal );
  82. if ( !g_bVertexColor )
  83. {
  84. worldNormal = normalize( worldNormal );
  85. }
  86. #if defined( SHADER_MODEL_VS_3_0 ) && MORPHING
  87. // Avoid z precision errors
  88. worldPos += worldNormal * 0.05f * v.vTexCoord2.z;
  89. #endif
  90. // Transform into projection space
  91. float4 projPos = mul( float4( worldPos, 1 ), cViewProj );
  92. o.projPos = projPos;
  93. #ifdef _PS3
  94. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  95. o.projPos.y = -o.projPos.y;
  96. o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
  97. #endif // _PS3
  98. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  99. o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
  100. #endif
  101. o.worldPos_ProjPosZ.xyz = worldPos.xyz;
  102. o.worldPos_ProjPosZ.w = projPos.z;
  103. if ( g_bVertexColor )
  104. {
  105. // Assume that this is unlitgeneric if you are using vertex color.
  106. o.color.rgb = GammaToLinear( v.vColor.rgb );
  107. o.color.a = v.vColor.a;
  108. }
  109. else
  110. {
  111. o.color = float4( 1.0f, 1.0f, 1.0f, 1.0f );
  112. }
  113. // Base texture coordinates
  114. o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
  115. o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
  116. #if LIGHTING_PREVIEW
  117. float dot=0.5+0.5*worldNormal*float3(0.7071,0.7071,0);
  118. o.color.xyz=float3(dot,dot,dot);
  119. #endif
  120. return o;
  121. }