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.

131 lines
4.6 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "VERTEXCOLOR" "0..1"
  3. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1" [vs20] [PC]
  4. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..0" [CONSOLE]
  5. // DYNAMIC: "SKINNING" "0..1"
  6. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  7. // DYNAMIC: "DYNAMIC_LIGHT" "0..1"
  8. // DYNAMIC: "STATIC_LIGHT" "0..1"
  9. // DYNAMIC: "NUM_LIGHTS" "0..4"
  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. // Includes =======================================================================================
  13. #include "common_vs_fxc.h"
  14. // Structs ========================================================================================
  15. struct VS_INPUT
  16. {
  17. float4 vPos : POSITION; // Position
  18. float4 vNormal : NORMAL; // Normal
  19. float4 vBoneWeights : BLENDWEIGHT; // Skin weights
  20. float4 vBoneIndices : BLENDINDICES; // Skin indices
  21. float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates
  22. float4 vTangent : TANGENT;
  23. #if ( VERTEXCOLOR )
  24. float4 vVertexColor : COLOR0;
  25. #endif
  26. float3 vSpecularN1 : COLOR1;
  27. float3 vSpecularN2 : TEXCOORD1;
  28. float3 vSpecularN3 : TEXCOORD2;
  29. };
  30. struct VS_OUTPUT
  31. {
  32. float4 vProjPosition : POSITION; // Projection-space position
  33. float3 vUv0 : TEXCOORD0;
  34. float3 vWorldNormal : TEXCOORD1;
  35. float3 vWorldTangent : TEXCOORD2;
  36. float3 vWorldBinormal : TEXCOORD3;
  37. float3 vWorldPosition : TEXCOORD4;
  38. float4 vLightAtten : TEXCOORD5;
  39. float4 vSpecularPack1 : TEXCOORD6;
  40. float4 vSpecularPack2 : TEXCOORD7;
  41. #if ( VERTEXCOLOR )
  42. float4 vVertexColor : COLOR0;
  43. #endif
  44. };
  45. // Main ===========================================================================================
  46. VS_OUTPUT main( const VS_INPUT i )
  47. {
  48. VS_OUTPUT o;
  49. bool bDynamicLight = false;
  50. bool bHalfLambert = false;
  51. float4 vObjPosition = i.vPos;
  52. float4 vObjTangent = i.vTangent;
  53. float3 vObjNormal;
  54. DecompressVertex_Normal( i.vNormal, vObjNormal );
  55. // Transform the position
  56. float3 vWorldPosition = { 0.0f, 0.0f, 0.0f };
  57. float3 vWorldNormal = { 0.0f, 0.0f, 0.0f };
  58. float3 vWorldTangent = { 0.0f, 0.0f, 0.0f };
  59. float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f };
  60. SkinPositionNormalAndTangentSpace( SKINNING, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal );
  61. vWorldNormal.xyz = normalize( vWorldNormal.xyz );
  62. vWorldTangent.xyz = normalize( vWorldTangent.xyz );
  63. vWorldBinormal.xyz = normalize( vWorldBinormal.xyz );
  64. o.vWorldNormal.xyz = vWorldNormal.xyz;
  65. o.vWorldTangent.xyz = vWorldTangent.xyz;
  66. o.vWorldBinormal.xyz = vWorldBinormal.xyz;
  67. o.vWorldPosition.xyz = vWorldPosition.xyz;
  68. // Transform into projection space
  69. float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj );
  70. o.vProjPosition.xyzw = vProjPosition.xyzw;
  71. // View vector
  72. float3 vWorldViewVector = normalize( vWorldPosition.xyz - cEyePos.xyz );
  73. // Texture coordinates
  74. o.vUv0.xy = i.vTexCoord0.xy;
  75. // Scalar light attenuation
  76. #if ( defined ( SHADER_MODEL_VS_2_0 ) && FLATTEN_STATIC_CONTROL_FLOW )
  77. o.vLightAtten = float4( 0, 0 , 0, 0 );
  78. #if ( NUM_LIGHTS > 0 )
  79. o.vLightAtten.x = GetVertexAttenForLight( vWorldPosition, 0, false );
  80. #endif
  81. #if ( NUM_LIGHTS > 1 )
  82. o.vLightAtten.y = GetVertexAttenForLight( vWorldPosition, 1, false );
  83. #endif
  84. #if ( NUM_LIGHTS > 2 )
  85. o.vLightAtten.z = GetVertexAttenForLight( vWorldPosition, 2, false );
  86. #endif
  87. #if ( NUM_LIGHTS > 3 )
  88. o.vLightAtten.w = GetVertexAttenForLight( vWorldPosition, 3, false );
  89. #endif
  90. #else
  91. o.vLightAtten.x = GetVertexAttenForLight( vWorldPosition.xyz, 0, true );
  92. o.vLightAtten.y = GetVertexAttenForLight( vWorldPosition.xyz, 1, true );
  93. o.vLightAtten.z = GetVertexAttenForLight( vWorldPosition.xyz, 2, true );
  94. o.vLightAtten.w = GetVertexAttenForLight( vWorldPosition.xyz, 3, true );
  95. #endif
  96. #if ( VERTEXCOLOR )
  97. {
  98. o.vVertexColor.rgb = GammaToLinear( i.vVertexColor.rgb );
  99. o.vVertexColor.a = i.vVertexColor.a;
  100. }
  101. #endif
  102. float3 cSpecular1 = DoLighting( vWorldPosition, vWorldNormal, i.vSpecularN1, true, bDynamicLight, bHalfLambert );
  103. float3 cSpecular2 = DoLighting( vWorldPosition, vWorldNormal, i.vSpecularN2, true, bDynamicLight, bHalfLambert );
  104. float3 cSpecular3 = DoLighting( vWorldPosition, vWorldNormal, i.vSpecularN3, true, bDynamicLight, bHalfLambert );
  105. // Packing the lighting information
  106. o.vSpecularPack1.xyz = cSpecular1.xyz;
  107. o.vSpecularPack2.xyz = cSpecular2.xyz;
  108. o.vSpecularPack1.w = cSpecular3.x;
  109. o.vSpecularPack2.w = cSpecular3.y;
  110. o.vUv0.z = cSpecular3.z;
  111. return o;
  112. }