Team Fortress 2 Source Code as on 22/4/2020
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.

110 lines
3.5 KiB

  1. //========= Copyright (c) 1996-2006, Valve Corporation, All rights reserved. ============//
  2. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  3. // DYNAMIC: "SKINNING" "0..1"
  4. // Includes
  5. #include "common_vs_fxc.h"
  6. // Globals
  7. static const bool g_bSkinning = SKINNING ? true : false;
  8. const float g_flTime : register( SHADER_SPECIFIC_CONST_0 );
  9. const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
  10. // Structs
  11. struct VS_INPUT
  12. {
  13. float4 vPos : POSITION; // Position
  14. float4 vNormal : NORMAL; // Normal
  15. float4 vBoneWeights : BLENDWEIGHT; // Skin weights
  16. float4 vBoneIndices : BLENDINDICES; // Skin indices
  17. float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates
  18. float4 vTangent : TANGENT;
  19. };
  20. struct VS_OUTPUT
  21. {
  22. float4 vProjPosition : POSITION; // Projection-space position
  23. float3 vWorldNormal : TEXCOORD0; // World-space normal
  24. float3 vWorldTangent : TEXCOORD1;
  25. float3 vWorldBinormal : TEXCOORD2;
  26. float3 vProjPosForRefract : TEXCOORD3;
  27. float3 vWorldViewVector : TEXCOORD4;
  28. float4 vUv0 : TEXCOORD5;
  29. float4 vUv1 : TEXCOORD6;
  30. float2 vUvGroundNoise : TEXCOORD7;
  31. };
  32. // Main
  33. VS_OUTPUT main( const VS_INPUT i )
  34. {
  35. VS_OUTPUT o;
  36. float4 vObjPosition = i.vPos;
  37. float4 vObjTangent = i.vTangent;
  38. float3 vObjNormal;
  39. DecompressVertex_Normal( i.vNormal, vObjNormal );
  40. // Transform the position
  41. float3 vWorldPosition = { 0.0f, 0.0f, 0.0f };
  42. float3 vWorldNormal = { 0.0f, 0.0f, 0.0f };
  43. float3 vWorldTangent = { 0.0f, 0.0f, 0.0f };
  44. float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f };
  45. SkinPositionNormalAndTangentSpace( g_bSkinning, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal );
  46. vWorldNormal.xyz = normalize( vWorldNormal.xyz );
  47. vWorldTangent.xyz = normalize( vWorldTangent.xyz );
  48. vWorldBinormal.xyz = normalize( vWorldBinormal.xyz );
  49. o.vWorldNormal.xyz = vWorldNormal.xyz;
  50. o.vWorldTangent.xyz = vWorldTangent.xyz;
  51. o.vWorldBinormal.xyz = vWorldBinormal.xyz;
  52. // Transform into projection space
  53. float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj );
  54. o.vProjPosition = vProjPosition;
  55. // Map projected position to the refraction texture
  56. float2 vRefractPos;
  57. vRefractPos.x = vProjPosition.x;
  58. vRefractPos.y = -vProjPosition.y; // Invert Y
  59. vRefractPos = (vRefractPos + vProjPosition.w) * 0.5f;
  60. o.vProjPosForRefract.xyz = float3(vRefractPos.x, vRefractPos.y, vProjPosition.w);
  61. // View vector
  62. float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz);
  63. o.vWorldViewVector.xyz = vWorldViewVector.xyz;
  64. // Tangent space transform
  65. //o.mTangentSpaceTranspose[0] = float3( vWorldTangent.x, vWorldBinormal.x, vWorldNormal.x );
  66. //o.mTangentSpaceTranspose[1] = float3( vWorldTangent.y, vWorldBinormal.y, vWorldNormal.y );
  67. //o.mTangentSpaceTranspose[2] = float3( vWorldTangent.z, vWorldBinormal.z, vWorldNormal.z );
  68. // Texture coordinates
  69. float2 vBaseUv;
  70. vBaseUv.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0] );
  71. vBaseUv.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1] );
  72. // Bump layer 0
  73. float2 vUv0 = vBaseUv.xy;
  74. float2 vUv0Scroll = vBaseUv.xy * 3.0f;
  75. vUv0Scroll.y -= g_flTime * 0.1f;
  76. o.vUv0.xy = vUv0.xy;
  77. o.vUv0.wz = vUv0Scroll.xy;
  78. // Bump layer 1
  79. float2 vUv1 = vBaseUv.xy * 8.0f;
  80. float2 vUv1Scroll = vBaseUv.xy * 16.0f;
  81. vUv1Scroll.y -= g_flTime * 0.1f;
  82. o.vUv1.xy = vUv1.xy;
  83. o.vUv1.wz = vUv1Scroll.xy;
  84. // Ground noise
  85. o.vUvGroundNoise.xy = vBaseUv.xy;
  86. o.vUvGroundNoise.x *= 3.5f;
  87. o.vUvGroundNoise.y *= 0.2105f;
  88. o.vUvGroundNoise.y -= g_flTime * 0.04f;
  89. return o;
  90. }