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.

117 lines
2.9 KiB

  1. // STATIC: "MODEL" "0..1"
  2. // STATIC: "PORTALGHOSTOVERLAY" "0..2"
  3. // DYNAMIC: "SKINNING" "0..1"
  4. #include "common_vs_fxc.h"
  5. static const bool g_bSkinning = SKINNING ? true : false;
  6. static const bool g_bModel = MODEL ? true : false;
  7. struct VS_INPUT
  8. {
  9. float4 vPos : POSITION;
  10. float3 vNormal : NORMAL;
  11. #if ( PORTALGHOSTOVERLAY )
  12. float4 vGhostTintColor : COLOR;
  13. #endif
  14. float4 vBoneWeights : BLENDWEIGHT;
  15. float4 vBoneIndices : BLENDINDICES;
  16. float2 vTexCoord : TEXCOORD0;
  17. };
  18. struct VS_OUTPUT
  19. {
  20. float4 vProjPos : POSITION;
  21. float4 vColor : COLOR;
  22. float2 vTexCoord1 : TEXCOORD0;
  23. float2 vTexCoord2 : TEXCOORD1; //just a copy of vTexCoord1, ps11 compatibility issue
  24. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  25. float fog : FOG;
  26. #endif
  27. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  28. };
  29. VS_OUTPUT main( VS_INPUT v )
  30. {
  31. VS_OUTPUT o = ( VS_OUTPUT )0;
  32. #if ( PORTALGHOSTOVERLAY )
  33. {
  34. // Offset these by one unit so we can do a z-fail render and force it to be in front of the wall.
  35. // I don't want to modify the mesh since we're getting close to shipping. This ensures the offset
  36. // is isolated to the ghost render only and not the other portal render passes.
  37. v.vPos.xyz += v.vNormal.xyz;
  38. }
  39. #endif
  40. float3 worldPos;
  41. if( MODEL == 1 )
  42. {
  43. SkinPosition(
  44. g_bSkinning,
  45. v.vPos,
  46. v.vBoneWeights, v.vBoneIndices,
  47. worldPos );
  48. }
  49. else
  50. {
  51. worldPos = mul3x3( v.vPos.xyz, ( float3x3 )cModel[0] );
  52. }
  53. o.vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  54. #ifdef _PS3
  55. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  56. o.vProjPos.y = -o.vProjPos.y;
  57. o.vProjPos.z = 2.0f * o.vProjPos.z - o.vProjPos.w;
  58. #endif // _PS3
  59. o.worldPos_projPosZ = float4( worldPos.xyz, o.vProjPos.z );
  60. o.vTexCoord1 = v.vTexCoord.xy;
  61. o.vTexCoord2 = v.vTexCoord.xy;
  62. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  63. o.fog = CalcFixedFunctionFog( worldPos, FOGTYPE_RANGE );
  64. #endif
  65. o.vColor.rgba = float4( 1, 1, 1, 1 );
  66. #if ( PORTALGHOSTOVERLAY )
  67. {
  68. #if ( PORTALGHOSTOVERLAY == 1 )
  69. {
  70. o.vColor.rgba = float4( v.vGhostTintColor.rgb, 1 );
  71. }
  72. #endif
  73. float3 vViewRayWs = worldPos.xyz - cEyePos.xyz;
  74. // If we're facing away, always be full strength
  75. float flDot = dot( v.vNormal.xyz, vViewRayWs.xyz );
  76. if ( flDot <= 0.0f )
  77. {
  78. // if we're facing towards the viewer, take distance into account
  79. float flDistSqr = dot( vViewRayWs.xyz, vViewRayWs.xyz );
  80. o.vColor.a = saturate( ( flDistSqr - ( 120.0f * 120.0f ) ) / ( ( 240.0f * 240.0f ) - ( 120.0f * 120.0f ) ) ); // Remap 120..240 distance to 0..1
  81. }
  82. // Factor how "open" this portal is, but don't lerp in the visibility until the portal is 85% open...otherwise
  83. // the colored oval becomes visible before the portal's firey border is fully open.
  84. o.vColor.a *= v.vGhostTintColor.a;
  85. }
  86. #endif
  87. return o;
  88. }