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.

109 lines
4.0 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "MIRROR" "0..1"
  3. // STATIC: "NORMALMAP" "0..1"
  4. // DYNAMIC: "SKINNING" "0..1"
  5. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  6. // DYNAMIC: "NUM_LIGHTS" "0..4"
  7. #include "common_vs_fxc.h"
  8. const float4 g_patternTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); // 0 & 1
  9. const float4 g_const2 : register( SHADER_SPECIFIC_CONST_2 );
  10. #define g_flAspectRatioHeight g_const2.x
  11. static const bool g_bSkinning = SKINNING ? true : false;
  12. struct VS_INPUT
  13. {
  14. float4 vPos : POSITION;
  15. float2 vTexCoord : TEXCOORD0;
  16. float4 vNormal : NORMAL;
  17. #if ( NORMALMAP == 1 )
  18. float4 vTangent : TANGENT;
  19. #endif
  20. float4 vBoneWeights : BLENDWEIGHT;
  21. float4 vBoneIndices : BLENDINDICES;
  22. };
  23. struct VS_OUTPUT
  24. {
  25. float4 vProjPos : POSITION;
  26. float4 vBaseUV_PatternUV : TEXCOORD0;
  27. float4 lightAtten : TEXCOORD2;
  28. float3 worldPos : TEXCOORD3;
  29. #if ( NORMALMAP == 1 )
  30. float3x3 tangentSpaceTranspose : TEXCOORD4;
  31. // second row : TEXCOORD5;
  32. // third row : TEXCOORD6;
  33. #else
  34. float3 vWorldNormal : TEXCOORD4;
  35. #endif
  36. };
  37. // Main
  38. VS_OUTPUT main( const VS_INPUT i )
  39. {
  40. VS_OUTPUT o;
  41. float4 vPosition, vTangent;
  42. float3 vNormal, worldPos, worldNormal, worldTangentS, worldTangentT;
  43. vPosition = i.vPos;
  44. // Perform skinning
  45. #if ( NORMALMAP == 0 )
  46. DecompressVertex_Normal( i.vNormal, vNormal );
  47. SkinPositionAndNormal( g_bSkinning, vPosition, vNormal, i.vBoneWeights, i.vBoneIndices, worldPos, worldNormal );
  48. worldNormal = normalize( worldNormal );
  49. o.vWorldNormal = worldNormal;
  50. #else
  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. #endif
  63. // Bump out the decal so it doesn't z-fight with coplanar polys.
  64. // This means we don't have to push decal faces in content, and may dial this value globally if needed.
  65. worldPos -= normalize( worldPos.xyz - cEyePos.xyz ) * 0.05;
  66. o.worldPos = worldPos;
  67. o.vProjPos = mul( float4( worldPos, 1.0f ), cViewProj );
  68. o.lightAtten.x = GetVertexAttenForLight( worldPos, 0 );
  69. o.lightAtten.y = GetVertexAttenForLight( worldPos, 1 );
  70. o.lightAtten.z = GetVertexAttenForLight( worldPos, 2 );
  71. o.lightAtten.w = GetVertexAttenForLight( worldPos, 3 );
  72. o.vBaseUV_PatternUV.xy = i.vTexCoord;
  73. #if (MIRROR == 0)
  74. o.vBaseUV_PatternUV.z = dot ( i.vTexCoord, g_patternTexCoordTransform[0].xy ) + g_patternTexCoordTransform[0].w;
  75. o.vBaseUV_PatternUV.w = dot ( i.vTexCoord, g_patternTexCoordTransform[1].xy ) + g_patternTexCoordTransform[1].w;
  76. #else
  77. float2 flippedTexCoord = float2( 1.0f - i.vTexCoord.x, i.vTexCoord.y );
  78. o.vBaseUV_PatternUV.z = dot ( flippedTexCoord, g_patternTexCoordTransform[0].xy ) + g_patternTexCoordTransform[0].w;
  79. o.vBaseUV_PatternUV.w = dot ( flippedTexCoord, g_patternTexCoordTransform[1].xy ) + g_patternTexCoordTransform[1].w;
  80. #endif
  81. //maintain input texture aspect ratio
  82. o.vBaseUV_PatternUV.zw = float2( o.vBaseUV_PatternUV.z, ( (o.vBaseUV_PatternUV.w - 0.5f) * g_flAspectRatioHeight ) + 0.5f );
  83. //o.vWearUV_GrungeUV.x = dot ( i.vTexCoord, g_wearTexCoordTransform[0].xy ) + g_wearTexCoordTransform[0].w;
  84. //o.vWearUV_GrungeUV.y = dot ( i.vTexCoord, g_wearTexCoordTransform[1].xy ) + g_wearTexCoordTransform[1].w;
  85. //o.vWearUV_GrungeUV.z = dot ( i.vTexCoord, g_grungeTexCoordTransform[0].xy ) + g_grungeTexCoordTransform[0].w;
  86. //o.vWearUV_GrungeUV.w = dot ( i.vTexCoord, g_grungeTexCoordTransform[1].xy ) + g_grungeTexCoordTransform[1].w;
  87. return o;
  88. }