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.

104 lines
3.5 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "COMPOSITEMODE" "0..2"
  3. // DYNAMIC: "SKINNING" "0..1"
  4. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  5. // DYNAMIC: "NUM_LIGHTS" "0..4"
  6. // SKIP: ( ( $COMPOSITEMODE == 1 ) && ( $SKINNING != 0 ) )
  7. // SKIP: ( ( $COMPOSITEMODE == 1 ) && ( $NUM_LIGHTS != 0 ) )
  8. #include "common_vs_fxc.h"
  9. const float4 g_baseTextureTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); // 0 & 1
  10. const float4 g_wearTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_2 ); // 2 & 3
  11. const float4 g_grungeTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); // 4 & 5
  12. #if ( COMPOSITEMODE != 1 )
  13. static const bool g_bSkinning = SKINNING ? true : false;
  14. #endif
  15. struct VS_INPUT
  16. {
  17. float4 vPos : POSITION;
  18. float2 vTexCoord : TEXCOORD0;
  19. #if ( COMPOSITEMODE != 1 )
  20. float4 vNormal : NORMAL;
  21. float4 vTangent : TANGENT;
  22. float4 vBoneWeights : BLENDWEIGHT;
  23. float4 vBoneIndices : BLENDINDICES;
  24. #endif
  25. };
  26. struct VS_OUTPUT
  27. {
  28. float4 vProjPos_POSITION : POSITION;
  29. float4 vBaseUV_PatternUV : TEXCOORD0;
  30. float4 vWearUV_GrungeUV : TEXCOORD1;
  31. #if ( COMPOSITEMODE != 1 )
  32. float4 lightAtten : TEXCOORD2;
  33. float3 worldPos : TEXCOORD3;
  34. float3x3 tangentSpaceTranspose : TEXCOORD4;
  35. // second row : TEXCOORD5;
  36. // third row : TEXCOORD6;
  37. float4 vProjPos : TEXCOORD7;
  38. #endif
  39. };
  40. // Main
  41. VS_OUTPUT main( const VS_INPUT i )
  42. {
  43. VS_OUTPUT o;
  44. #if ( COMPOSITEMODE == 1 ) // image-space composite mode
  45. o.vProjPos_POSITION = i.vPos;
  46. #else // COMPOSITEMODE != 1 (3d mode)
  47. float4 vPosition, vTangent;
  48. float3 vNormal, worldPos, worldNormal, worldTangentS, worldTangentT;
  49. vPosition = i.vPos;
  50. // Perform skinning
  51. DecompressVertex_NormalTangent( i.vNormal, i.vTangent, vNormal, vTangent );
  52. SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent,
  53. i.vBoneWeights, i.vBoneIndices, worldPos,
  54. worldNormal, worldTangentS, worldTangentT );
  55. worldTangentS = normalize( worldTangentS );
  56. worldTangentT = normalize( worldTangentT );
  57. worldNormal = normalize( worldNormal );
  58. // Tangent space transform
  59. o.tangentSpaceTranspose[0].xyz = float3( worldTangentS.x, worldTangentT.x, worldNormal.x );
  60. o.tangentSpaceTranspose[1].xyz = float3( worldTangentS.y, worldTangentT.y, worldNormal.y );
  61. o.tangentSpaceTranspose[2].xyz = float3( worldTangentS.z, worldTangentT.z, worldNormal.z );
  62. o.worldPos = worldPos;
  63. o.vProjPos = o.vProjPos_POSITION = mul( float4( worldPos, 1.0f ), cViewProj );
  64. o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false );
  65. o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false );
  66. o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false );
  67. o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, false );
  68. #endif
  69. o.vBaseUV_PatternUV.xy = i.vTexCoord;
  70. o.vBaseUV_PatternUV.z = dot ( i.vTexCoord, g_baseTextureTransform[0].xy ) + g_baseTextureTransform[0].w;
  71. o.vBaseUV_PatternUV.w = dot ( i.vTexCoord, g_baseTextureTransform[1].xy ) + g_baseTextureTransform[1].w;
  72. o.vWearUV_GrungeUV.x = dot ( i.vTexCoord, g_wearTexCoordTransform[0].xy ) + g_wearTexCoordTransform[0].w;
  73. o.vWearUV_GrungeUV.y = dot ( i.vTexCoord, g_wearTexCoordTransform[1].xy ) + g_wearTexCoordTransform[1].w;
  74. o.vWearUV_GrungeUV.z = dot ( i.vTexCoord, g_grungeTexCoordTransform[0].xy ) + g_grungeTexCoordTransform[0].w;
  75. o.vWearUV_GrungeUV.w = dot ( i.vTexCoord, g_grungeTexCoordTransform[1].xy ) + g_grungeTexCoordTransform[1].w;
  76. return o;
  77. }