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.

140 lines
4.7 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "USEBOUNCECOLOR" "0..0" [vs20]
  3. // STATIC: "USEBOUNCECOLOR" "0..1" [vs30]
  4. // STATIC: "FLASHLIGHT" "0..1"
  5. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1"
  6. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  7. // DYNAMIC: "SKINNING" "0..1"
  8. // DYNAMIC: "NUM_LIGHTS" "0..4" [vs30]
  9. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20]
  10. // If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
  11. // SKIP: ( $FLATTEN_STATIC_CONTROL_FLOW == 0 ) && ( $NUM_LIGHTS > 0 ) [vs20] [PC]
  12. #include "common_fog_vs_supportsvertexfog_fxc.h"
  13. #include "common_vs_fxc.h"
  14. static const bool g_bSkinning = SKINNING ? true : false;
  15. static const int g_FogType = DOWATERFOG;
  16. const float3 g_vBounceCenter : register( SHADER_SPECIFIC_CONST_0 );
  17. const float3 g_vEntityOrigin : register( SHADER_SPECIFIC_CONST_1 );
  18. #define g_vShadowRimMin 0.01f
  19. #define g_vShadowRimMax 0.05f
  20. #define g_vViewFakeRimDir float3( 0.7f, 1.0f, 0.0f )
  21. struct VS_INPUT
  22. {
  23. float4 vPos : POSITION;
  24. float2 vTexCoord0 : TEXCOORD0;
  25. float4 vBoneWeights : BLENDWEIGHT;
  26. float4 vBoneIndices : BLENDINDICES;
  27. float4 vNormal : NORMAL;
  28. float4 vColor : COLOR0;
  29. float3 vTangentS : TANGENT;
  30. float3 vTangentT : BINORMAL;
  31. float4 vUserData : TANGENT;
  32. };
  33. struct VS_OUTPUT
  34. {
  35. float4 vProjPos : POSITION;
  36. float4 vTexCoord0 : TEXCOORD0;
  37. float4 lightAtten : TEXCOORD1;
  38. float4 tangentSpaceTranspose0_FakeRimx : TEXCOORD2;
  39. float4 tangentSpaceTranspose1_FakeRimy : TEXCOORD3;
  40. float4 tangentSpaceTranspose2_FakeRimz : TEXCOORD4;
  41. float4 vWorldPos_projZ : TEXCOORD5;
  42. float4 cAmbient_fRimBoost : TEXCOORD6;
  43. #if defined( SHADER_MODEL_VS_3_0 )
  44. float4 vWorldTangentS_vBounceCenterx : TEXCOORD7;
  45. float4 vWorldTangentT_vBounceCentery : TEXCOORD8;
  46. float4 vBounceCenterDir_vBounceCenterz : TEXCOORD9;
  47. #endif
  48. };
  49. VS_OUTPUT main( const VS_INPUT i )
  50. {
  51. VS_OUTPUT o = ( VS_OUTPUT )0;
  52. float4 vPosition, vTangent, vTexCoords;
  53. float3 vNormal, worldPos, worldNormal, worldTangentS, worldTangentT;
  54. vPosition = i.vPos;
  55. DecompressVertex_NormalTangent( i.vNormal, i.vUserData, vNormal, vTangent );
  56. // Perform skinning
  57. SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent,
  58. i.vBoneWeights, i.vBoneIndices, worldPos,
  59. worldNormal, worldTangentS, worldTangentT );
  60. // Tangent space transform
  61. o.tangentSpaceTranspose0_FakeRimx.xyz = float3( worldTangentS.x, worldTangentT.x, worldNormal.x );
  62. o.tangentSpaceTranspose1_FakeRimy.xyz = float3( worldTangentS.y, worldTangentT.y, worldNormal.y );
  63. o.tangentSpaceTranspose2_FakeRimz.xyz = float3( worldTangentS.z, worldTangentT.z, worldNormal.z );
  64. #if defined( SHADER_MODEL_VS_3_0 )
  65. o.vWorldTangentS_vBounceCenterx.xyz = worldTangentS.xyz;
  66. o.vWorldTangentT_vBounceCentery.xyz = worldTangentT.xyz;
  67. #endif
  68. o.vTexCoord0.xy = i.vTexCoord0.xy;
  69. // Transform into projection space
  70. o.vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  71. o.vWorldPos_projZ.xyz = worldPos.xyz;
  72. o.vWorldPos_projZ.w = o.vProjPos.z;
  73. #if( USEBOUNCECOLOR )
  74. o.vBounceCenterDir_vBounceCenterz.xyz = normalize( g_vEntityOrigin + g_vBounceCenter - worldPos );
  75. float3 vBounceCenter = g_vEntityOrigin + g_vBounceCenter;
  76. o.vWorldTangentS_vBounceCenterx.w = vBounceCenter.x;
  77. o.vWorldTangentT_vBounceCentery.w = vBounceCenter.y;
  78. o.vBounceCenterDir_vBounceCenterz.w = vBounceCenter.z;
  79. #endif
  80. #if ( FLASHLIGHT )
  81. o.tangentSpaceTranspose0_FakeRimx.w = o.vProjPos.x;
  82. o.tangentSpaceTranspose1_FakeRimy.w = o.vProjPos.y;
  83. o.tangentSpaceTranspose2_FakeRimz.w = o.vProjPos.z;
  84. #else
  85. float3 vWorldFakeRimDir = normalize( mul( cViewProj, float4( g_vViewFakeRimDir, 1 ) ).xyz );
  86. o.tangentSpaceTranspose0_FakeRimx.w = vWorldFakeRimDir.x;
  87. o.tangentSpaceTranspose1_FakeRimy.w = vWorldFakeRimDir.y;
  88. o.tangentSpaceTranspose2_FakeRimz.w = vWorldFakeRimDir.z;
  89. #endif
  90. // Compute lighting attenuations
  91. #if ( FLATTEN_STATIC_CONTROL_FLOW )
  92. {
  93. #if ( NUM_LIGHTS > 0 )
  94. o.lightAtten.x = GetVertexAttenForLight( worldPos.xyz, 0, false );
  95. #endif
  96. #if ( NUM_LIGHTS > 1 )
  97. o.lightAtten.y = GetVertexAttenForLight( worldPos.xyz, 1, false );
  98. #endif
  99. }
  100. #else
  101. {
  102. o.lightAtten.x = GetVertexAttenForLight( worldPos, 0 );
  103. o.lightAtten.y = GetVertexAttenForLight( worldPos, 1 );
  104. #if defined( SHADER_MODEL_VS_3_0 )
  105. o.lightAtten.z = GetVertexAttenForLight( worldPos, 2 );
  106. o.lightAtten.w = GetVertexAttenForLight( worldPos, 3 );
  107. #endif
  108. }
  109. #endif
  110. float3 cAmbient = AmbientLight( worldNormal );
  111. o.cAmbient_fRimBoost.xyz = cAmbient;
  112. float3 lum = float3( 0.299, 0.587, 0.114 );
  113. float fAmbientLightLum = dot( lum, cAmbient );
  114. o.cAmbient_fRimBoost.w = smoothstep( g_vShadowRimMax, g_vShadowRimMin, fAmbientLightLum );
  115. return o;
  116. }