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.

123 lines
3.7 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1" [vs20] [PC]
  3. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..0" [CONSOLE]
  4. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  5. #include "common_fog_vs_fxc.h"
  6. // DYNAMIC: "SKINNING" "0..1"
  7. // DYNAMIC: "DYNAMIC_LIGHT" "0..1"
  8. // DYNAMIC: "STATIC_LIGHT" "0..1"
  9. // DYNAMIC: "MORPHING" "0..0" [ = false ]
  10. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] [PC]
  11. // DYNAMIC: "NUM_LIGHTS" "0..0" [vs20] [CONSOLE]
  12. // If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
  13. // SKIP: ( $FLATTEN_STATIC_CONTROL_FLOW == 0 ) && ( $NUM_LIGHTS > 0 ) [vs20] [PC]
  14. #include "vortwarp_vs20_helper.h"
  15. static const int g_FogType = DOWATERFOG;
  16. static const bool g_bSkinning = SKINNING ? true : false;
  17. const float4 cTeethLighting : register( SHADER_SPECIFIC_CONST_0 );
  18. #ifdef SHADER_MODEL_VS_3_0
  19. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  20. // cMorphTargetTextureDim.z = 4tuples/morph
  21. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 );
  22. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 );
  23. sampler2D morphSampler : register( s0 );
  24. #endif
  25. struct VS_INPUT
  26. {
  27. // This is all of the stuff that we ever use.
  28. float4 vPos : POSITION;
  29. float4 vBoneWeights : BLENDWEIGHT;
  30. float4 vBoneIndices : BLENDINDICES;
  31. float4 vNormal : NORMAL;
  32. float2 vTexCoord0 : TEXCOORD0;
  33. // Position and normal/tangent deltas
  34. float3 vPosFlex : POSITION1;
  35. float3 vNormalFlex : NORMAL1;
  36. #ifdef SHADER_MODEL_VS_3_0
  37. float vVertexID : POSITION2;
  38. #endif
  39. };
  40. struct VS_OUTPUT
  41. {
  42. float4 projPos : POSITION;
  43. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  44. float fog : FOG;
  45. #endif
  46. float2 baseTexCoord : TEXCOORD0;
  47. float3 vertAtten : TEXCOORD1;
  48. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  49. };
  50. VS_OUTPUT main( const VS_INPUT v )
  51. {
  52. VS_OUTPUT o = ( VS_OUTPUT )0;
  53. bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
  54. bool bStaticLight = STATIC_LIGHT ? true : false;
  55. float4 vPosition = v.vPos;
  56. float3 vNormal;
  57. DecompressVertex_Normal( v.vNormal, vNormal );
  58. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  59. ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal );
  60. #else
  61. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), vPosition.xyz, vNormal );
  62. #endif
  63. // Normalize the flexed normal
  64. vNormal.xyz = normalize( vNormal.xyz );
  65. // Transform the position
  66. float3 worldPos, worldNormal;
  67. SkinPositionAndNormal( g_bSkinning, vPosition, vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal );
  68. // Transform into projection space
  69. o.projPos = mul( float4( worldPos, 1 ), cViewProj );
  70. #ifdef _PS3
  71. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  72. o.projPos.y = -o.projPos.y;
  73. o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
  74. #endif // _PS3
  75. o.worldPos_projPosZ = float4( worldPos.xyz, o.projPos.z );
  76. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  77. o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
  78. #endif
  79. // Compute lighting
  80. #if ( ( FLATTEN_STATIC_CONTROL_FLOW == 0 ) || defined ( SHADER_MODEL_VS_3_0 ) )
  81. float3 linearColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, false );
  82. #else
  83. float3 linearColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, false, NUM_LIGHTS );
  84. #endif
  85. // Forward vector
  86. float3 vForward = cTeethLighting.xyz;
  87. float fIllumFactor = cTeethLighting.w;
  88. // Darken by forward dot normal and illumination factor
  89. linearColor *= fIllumFactor * saturate( dot( worldNormal, vForward ) );
  90. o.vertAtten = linearColor;
  91. o.baseTexCoord = v.vTexCoord0;
  92. return o;
  93. }