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.

90 lines
3.1 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. // STATIC: "STAGE" "0..2"
  3. // Includes
  4. #include "common_vs_fxc.h"
  5. // Globals
  6. const float g_flTime : register( SHADER_SPECIFIC_CONST_0 );
  7. const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
  8. const float2 g_vConst3 : register( SHADER_SPECIFIC_CONST_3 );
  9. #define g_flPortalOpenAmount g_vConst3.x
  10. #define g_flPortalStaticAmount g_vConst3.y
  11. // Structs
  12. struct VS_INPUT
  13. {
  14. float4 vPos : POSITION; // Position
  15. float4 vNormal : NORMAL; // Normal
  16. float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates
  17. float4 vTangent : TANGENT; // Flip in w
  18. };
  19. struct VS_OUTPUT
  20. {
  21. float4 vProjPosition : POSITION; // Projection-space position
  22. float2 vUv0 : TEXCOORD0;
  23. float3 vWorldTangent : TEXCOORD1;
  24. float3 vWorldBinormal : TEXCOORD2;
  25. float4 vWorldPosition : TEXCOORD3; // Proj pos z in w
  26. float3 vProjPosForRefract : TEXCOORD4;
  27. float4 vNoiseTexCoord : TEXCOORD5;
  28. };
  29. // Main
  30. VS_OUTPUT main( const VS_INPUT i )
  31. {
  32. float kFlPortalOuterBorder = 0.075f; // Must match PS!
  33. VS_OUTPUT o;
  34. float3 vObjNormal;
  35. DecompressVertex_Normal( i.vNormal, vObjNormal );
  36. // Transform the position
  37. float3 vWorldPosition = mul( i.vPos, cModel[0] );
  38. float3 vWorldNormal = normalize( mul( vObjNormal, ( float3x3 )cModel[0] ) );
  39. float3 vWorldTangent = normalize( mul( i.vTangent, ( float3x3 )cModel[0] ) );
  40. float3 vWorldBinormal = normalize( cross( vWorldNormal, vWorldTangent ) * i.vTangent.w );
  41. o.vWorldPosition.xyz = vWorldPosition.xyz;
  42. //o.vWorldNormal.xyz = vWorldNormal.xyz;
  43. o.vWorldTangent.xyz = vWorldTangent.xyz + vWorldPosition.xyz;
  44. o.vWorldBinormal.xyz = vWorldBinormal.xyz + vWorldPosition.xyz;
  45. // Transform into projection space
  46. float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj );
  47. o.vProjPosition.xyzw = vProjPosition.xyzw;
  48. o.vWorldPosition.w = vProjPosition.z;
  49. // Map projected position to the refraction texture
  50. float2 vRefractPos;
  51. vRefractPos.x = vProjPosition.x;
  52. vRefractPos.y = -vProjPosition.y; // Invert Y
  53. vRefractPos = ( vRefractPos + vProjPosition.w ) * 0.5f;
  54. o.vProjPosForRefract.xyz = float3(vRefractPos.x, vRefractPos.y, vProjPosition.w);
  55. // View vector
  56. float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz);
  57. // Texture coordinates
  58. float2 vBaseUv;
  59. vBaseUv.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0] );
  60. vBaseUv.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1] );
  61. //o.vUv0.xy = vBaseUv.xy;
  62. o.vUv0.xy = vBaseUv.xy * ( 1.0f + kFlPortalOuterBorder ) - ( kFlPortalOuterBorder * 0.5f ); // Adjust uv's for shrunken portal
  63. // Portal open time
  64. float flPortalOpenAmount = saturate( g_flPortalOpenAmount + 0.001f ); // 0.001f to avoid divide by zero
  65. // Noise UV
  66. float kFlBorderNoiseScale = 0.3f;
  67. float kFlNoiseUvScroll = g_flTime * 0.0275f;
  68. float2 vNoiseUv = ( ( vBaseUv.xy - 0.5f ) / flPortalOpenAmount ) + 0.5f;
  69. o.vNoiseTexCoord.xy = ( vNoiseUv.xy * kFlBorderNoiseScale ) + float2( kFlNoiseUvScroll, 0 );
  70. o.vNoiseTexCoord.zw = ( vNoiseUv.xy * kFlBorderNoiseScale ) - float2( kFlNoiseUvScroll, 0 ); // Will fetch as wz to avoid matching layers
  71. return o;
  72. }