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.

135 lines
3.7 KiB

  1. // STATIC: "HASALPHAMASK" "0..1"
  2. // STATIC: "HASSTATICTEXTURE" "0..1"
  3. // STATIC: "USEALTERNATEVIEW" "0..1"
  4. // DYNAMIC: "SKINNING" "0..1"
  5. // DYNAMIC: "ADDSTATIC" "0..1"
  6. #define USESTATICTEXTURE (((ADDSTATIC == 1) && (HASSTATICTEXTURE == 1)))
  7. #include "common_vs_fxc.h"
  8. static const bool g_bSkinning = SKINNING ? true : false;
  9. #if ( USEALTERNATEVIEW == 1 )
  10. const float4x4 g_CustomViewProj : register( SHADER_SPECIFIC_CONST_0 );
  11. #endif
  12. const float4 g_vViewportMad : register( SHADER_SPECIFIC_CONST_4 );
  13. const float g_vIsRecursivePortalView : register( SHADER_SPECIFIC_CONST_5 );
  14. struct VS_INPUT
  15. {
  16. float4 vPos : POSITION;
  17. float4 vNormal : NORMAL;
  18. float4 vBoneWeights : BLENDWEIGHT;
  19. float4 vBoneIndices : BLENDINDICES;
  20. float2 vMappingTexCoord : TEXCOORD0;
  21. float flDecalOffset : TEXCOORD1; // How far to move each vertex along the normal
  22. };
  23. struct VS_OUTPUT
  24. {
  25. float4 vProjPos : POSITION;
  26. float3 vPortalTexCoord : TEXCOORD0;
  27. #if( (HASALPHAMASK == 1) || (USESTATICTEXTURE) )
  28. float2 vSecondaryTexCoord : TEXCOORD1;
  29. #if( (HASALPHAMASK == 1) && (USESTATICTEXTURE) )
  30. float2 vTertiaryTexCoord : TEXCOORD2;
  31. #endif
  32. #endif
  33. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  34. float fog : FOG;
  35. #endif
  36. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  37. };
  38. VS_OUTPUT main( const VS_INPUT v )
  39. {
  40. VS_OUTPUT o = ( VS_OUTPUT )0;
  41. float3 worldPos;
  42. // Move the portal decal away from the base surface a bit to avoid z fighting
  43. float3 vObjNormal;
  44. DecompressVertex_Normal( v.vNormal, vObjNormal );
  45. float4 vObjPos = v.vPos.xyzw;
  46. float flDecalOffset = 1.0f; // This offset is used in recursive portal views when using fast clipping (e.g. on the PS3).
  47. // It prevents ugly Z fighting between the portal and the surface it's on due to reduced Z precision when
  48. // a player is really really close to a portal.
  49. if ( g_vIsRecursivePortalView == 0.0f )
  50. {
  51. flDecalOffset = v.flDecalOffset;
  52. }
  53. vObjPos.xyz += flDecalOffset * vObjNormal.xyz;
  54. SkinPosition(
  55. g_bSkinning,
  56. vObjPos,
  57. v.vBoneWeights, v.vBoneIndices,
  58. worldPos );
  59. float4 vTextureProjectedPos;
  60. o.vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  61. #ifdef _PS3
  62. {
  63. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  64. o.vProjPos.y = -o.vProjPos.y;
  65. o.vProjPos.z = 2.0f * o.vProjPos.z - o.vProjPos.w;
  66. }
  67. #endif // _PS3
  68. #if ( USEALTERNATEVIEW == 1 )
  69. {
  70. vTextureProjectedPos = mul( float4( worldPos, 1 ), g_CustomViewProj );
  71. }
  72. #else
  73. {
  74. vTextureProjectedPos = o.vProjPos;
  75. }
  76. #endif
  77. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  78. {
  79. o.fog = CalcFixedFunctionFog( worldPos, FOGTYPE_RANGE );
  80. }
  81. #endif
  82. o.worldPos_projPosZ = float4( worldPos.xyz, o.vProjPos.z );
  83. //Screen coordinates mapped back to texture coordinates for the portal texture
  84. o.vPortalTexCoord.x = vTextureProjectedPos.x;
  85. o.vPortalTexCoord.y = -vTextureProjectedPos.y; // invert Y
  86. o.vPortalTexCoord.xy = (o.vPortalTexCoord.xy + vTextureProjectedPos.w) * 0.5f;
  87. o.vPortalTexCoord.z = vTextureProjectedPos.w;
  88. #if ( USEALTERNATEVIEW == 1 )
  89. {
  90. o.vPortalTexCoord.xy = saturate( o.vPortalTexCoord.xy / vTextureProjectedPos.w ) * vTextureProjectedPos.w; //stretch instead of clipping.
  91. }
  92. #endif
  93. //handle non-fullscreen viewports
  94. o.vPortalTexCoord.xy = ( ( ( o.vPortalTexCoord.xy / vTextureProjectedPos.w ) * g_vViewportMad.xy ) + g_vViewportMad.zw ) * vTextureProjectedPos.w; //handle non-fullscreen viewports
  95. #if( (HASALPHAMASK == 1) || (USESTATICTEXTURE) )
  96. {
  97. o.vSecondaryTexCoord = v.vMappingTexCoord.xy;
  98. #if( (HASALPHAMASK == 1) && (USESTATICTEXTURE) )
  99. {
  100. o.vTertiaryTexCoord = v.vMappingTexCoord.xy;
  101. }
  102. #endif
  103. }
  104. #endif
  105. return o;
  106. }