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.

141 lines
5.2 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // $SHADER_SPECIFIC_CONST_0 = eyeball origin
  3. // $SHADER_SPECIFIC_CONST_1 = eyeball up * 0.5
  4. // $SHADER_SPECIFIC_CONST_2 = iris projection U
  5. // $SHADER_SPECIFIC_CONST_3 = iris projection V
  6. // $SHADER_SPECIFIC_CONST_4 = glint projection U
  7. // $SHADER_SPECIFIC_CONST_5 = glint projection V
  8. //===========================================================================//
  9. // STATIC: "HALFLAMBERT" "0..1"
  10. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1" [vs20] [PC]
  11. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..0" [CONSOLE]
  12. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  13. // DYNAMIC: "SKINNING" "0..1"
  14. #include "common_fog_vs_fxc.h"
  15. // DYNAMIC: "DYNAMIC_LIGHT" "0..1"
  16. // DYNAMIC: "STATIC_LIGHT" "0..1"
  17. // DYNAMIC: "MORPHING" "0..0" [ = false ]
  18. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] [PC]
  19. // DYNAMIC: "NUM_LIGHTS" "0..0" [vs20] [CONSOLE]
  20. // If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
  21. // SKIP: ( $FLATTEN_STATIC_CONTROL_FLOW == 0 )&& ( $NUM_LIGHTS > 0 ) [vs20] [PC]
  22. #include "vortwarp_vs20_helper.h"
  23. static const int g_bSkinning = SKINNING ? true : false;
  24. static const int g_FogType = DOWATERFOG;
  25. static const bool g_bHalfLambert = HALFLAMBERT ? true : false;
  26. const float3 cEyeOrigin : register( SHADER_SPECIFIC_CONST_0 );
  27. const float3 cHalfEyeballUp : register( SHADER_SPECIFIC_CONST_1 );
  28. const float4 cIrisProjectionU : register( SHADER_SPECIFIC_CONST_2 );
  29. const float4 cIrisProjectionV : register( SHADER_SPECIFIC_CONST_3 );
  30. const float4 cGlintProjectionU : register( SHADER_SPECIFIC_CONST_4 );
  31. const float4 cGlintProjectionV : register( SHADER_SPECIFIC_CONST_5 );
  32. #ifdef SHADER_MODEL_VS_3_0
  33. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  34. // cMorphTargetTextureDim.z = 4tuples/morph
  35. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_7 );
  36. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_8 );
  37. sampler2D morphSampler : register( s0 );
  38. #endif
  39. struct VS_INPUT
  40. {
  41. float4 vPos : POSITION; // Position
  42. float4 vBoneWeights : BLENDWEIGHT; // Skin weights
  43. float4 vBoneIndices : BLENDINDICES; // Skin indices
  44. float4 vTexCoord0 : TEXCOORD0; // Base (sclera) texture coordinates
  45. float3 vPosFlex : POSITION1; // Delta positions for flexing
  46. #ifdef SHADER_MODEL_VS_3_0
  47. float vVertexID : POSITION2;
  48. #endif
  49. };
  50. struct VS_OUTPUT
  51. {
  52. float4 projPos : POSITION; // Projection-space position
  53. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  54. float fog : FOG; // Fixed-function fog factor
  55. #endif
  56. float2 baseTC : TEXCOORD0; // Base texture coordinate
  57. float2 irisTC : TEXCOORD1; // Iris texture coordinates
  58. float2 glintTC : TEXCOORD2; // Glint texture coordinates
  59. float3 vColor : TEXCOORD3; // Vertex-lit color
  60. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  61. };
  62. VS_OUTPUT main( const VS_INPUT v )
  63. {
  64. VS_OUTPUT o = (VS_OUTPUT)0;
  65. bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
  66. bool bStaticLight = STATIC_LIGHT ? true : false;
  67. float4 vPosition = v.vPos;
  68. float3 dummy = v.vPos.xyz; // dummy values that can't be optimized out
  69. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  70. ApplyMorph( v.vPosFlex, vPosition.xyz );
  71. #else
  72. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, dummy, vPosition.xyz );
  73. #endif
  74. // Transform the position and dummy normal (not doing the dummy normal causes invariance issues with the flashlight!)
  75. float3 worldNormal, worldPos;
  76. SkinPositionAndNormal(
  77. g_bSkinning,
  78. vPosition, dummy,
  79. v.vBoneWeights, v.vBoneIndices,
  80. worldPos, worldNormal );
  81. // Transform into projection space
  82. o.projPos = mul( float4( worldPos, 1 ), cViewProj );
  83. #ifdef _PS3
  84. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  85. o.projPos.y = -o.projPos.y;
  86. o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
  87. #endif // _PS3
  88. o.worldPos_projPosZ = float4( worldPos.xyz, o.projPos.z );
  89. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  90. o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
  91. #endif
  92. // Normal = (Pos - Eye origin) - just step on dummy normal created above
  93. worldNormal = worldPos - cEyeOrigin;
  94. // Normal -= 0.5f * (Normal dot Eye Up) * Eye Up
  95. float normalDotUp = -dot( worldNormal, cHalfEyeballUp) * 0.5f;
  96. worldNormal = normalize(normalDotUp * cHalfEyeballUp + worldNormal);
  97. // Vertex lighting
  98. #if ( ( FLATTEN_STATIC_CONTROL_FLOW == 0 ) || defined ( SHADER_MODEL_VS_3_0 ) )
  99. o.vColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert );
  100. #else
  101. o.vColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS );
  102. #endif
  103. // Texture 0 is the base texture
  104. // Texture 1 is a planar projection used for the iris
  105. // Texture 2 is a planar projection used for the glint
  106. o.baseTC = v.vTexCoord0.xy;
  107. o.irisTC.x = dot( cIrisProjectionU, float4(worldPos, 1) );
  108. o.irisTC.y = dot( cIrisProjectionV, float4(worldPos, 1) );
  109. o.glintTC.x = dot( cGlintProjectionU, float4(worldPos, 1) );
  110. o.glintTC.y = dot( cGlintProjectionV, float4(worldPos, 1) );
  111. return o;
  112. }