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.

132 lines
3.9 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "TEETH" "0..1"
  3. // DYNAMIC: "SKINNING" "0..1"
  4. #include "common_fog_vs_supportsvertexfog_fxc.h"
  5. #include "common_vs_fxc.h"
  6. static const bool g_bSkinning = SKINNING ? true : false;
  7. static const int g_FogType = DOWATERFOG;
  8. static const bool g_bTeeth = TEETH ? true: false;
  9. const float4 cLightPosition : register( SHADER_SPECIFIC_CONST_0 );
  10. const float4 cWorldToTextureTransform[4] : register( SHADER_SPECIFIC_CONST_1 );
  11. const float4 cAttenuationFactors : register( SHADER_SPECIFIC_CONST_5 );
  12. const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_6 );
  13. const float4 cNormalMapOrDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_8 );
  14. const float4 cTeethAttenuationConst : register( SHADER_SPECIFIC_CONST_10 );
  15. struct VS_INPUT
  16. {
  17. // This is all of the stuff that we ever use.
  18. float4 vPos : POSITION;
  19. float4 vBoneWeights : BLENDWEIGHT;
  20. float4 vBoneIndices : BLENDINDICES;
  21. float4 vNormal : NORMAL;
  22. float2 vBaseTexCoord : TEXCOORD0;
  23. };
  24. struct VS_OUTPUT
  25. {
  26. float4 vProjPos : POSITION; // Projection-space position
  27. #if !defined( _X360 ) && !defined( _PS3 ) && !defined( SHADER_MODEL_VS_3_0 )
  28. float fog : FOG;
  29. #endif
  30. float4 spotTexCoord : TEXCOORD0;
  31. float2 baseTexCoord : TEXCOORD1;
  32. float3 vWorldToLight : TEXCOORD2;
  33. float3 worldNormal : TEXCOORD3;
  34. //float2 detailCoords : TEXCOORD4;
  35. float3 worldPos : TEXCOORD5;
  36. #if HARDWAREFOGBLEND || DOPIXELFOG
  37. float3 projPos_fogFactorW : TEXCOORD6;
  38. #else
  39. float4 projPos_fogFactorW : TEXCOORD6;
  40. #endif
  41. float4 vDiffuse : COLOR0;
  42. };
  43. VS_OUTPUT main( const VS_INPUT v )
  44. {
  45. VS_OUTPUT o = ( VS_OUTPUT )0;
  46. // Perform skinning
  47. float3 worldNormal, worldPos;
  48. SkinPositionAndNormal(
  49. g_bSkinning,
  50. v.vPos, v.vNormal.xyz,
  51. v.vBoneWeights, v.vBoneIndices,
  52. worldPos, worldNormal );
  53. if( g_bSkinning )
  54. {
  55. worldNormal = normalize( worldNormal );
  56. }
  57. o.vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  58. #ifdef _PS3
  59. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  60. o.vProjPos.y = -o.vProjPos.y;
  61. o.vProjPos.z = 2.0f * o.vProjPos.z - o.vProjPos.w;
  62. #endif // _PS3
  63. o.worldPos = worldPos;
  64. o.projPos_fogFactorW.xyz = o.vProjPos.xyz;
  65. #if HARDWAREFOGBLEND
  66. o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
  67. #endif
  68. #if !DOPIXELFOG && !HARDWAREFOGBLEND
  69. o.projPos_fogFactorW.w = CalcNonFixedFunctionFog( worldPos, g_FogType );
  70. #endif
  71. o.spotTexCoord.x = dot( worldPos, cWorldToTextureTransform[0].xyz ) + cWorldToTextureTransform[0].w;
  72. o.spotTexCoord.y = dot( worldPos, cWorldToTextureTransform[1].xyz ) + cWorldToTextureTransform[1].w;
  73. o.spotTexCoord.z = dot( worldPos, cWorldToTextureTransform[2].xyz ) + cWorldToTextureTransform[2].w;
  74. o.spotTexCoord.w = dot( worldPos, cWorldToTextureTransform[3].xyz ) + cWorldToTextureTransform[3].w;
  75. o.baseTexCoord.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0].xy ) + cBaseTexCoordTransform[0].w;
  76. o.baseTexCoord.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1].xy ) + cBaseTexCoordTransform[1].w;
  77. float3 vWorldPosToLight = cLightPosition.xyz - worldPos;
  78. o.vWorldToLight = vWorldPosToLight;
  79. float3 distatten;
  80. distatten.z = dot( vWorldPosToLight, vWorldPosToLight );
  81. distatten.y = rsqrt( distatten.z );
  82. distatten.x = 1.0f;
  83. float dist = distatten.z * distatten.y;
  84. distatten.z = 1 / distatten.z;
  85. float endFalloffFactor = dist - cAttenuationFactors.w;
  86. endFalloffFactor *= cLightPosition.w;
  87. endFalloffFactor = saturate( endFalloffFactor );
  88. float vertAtten = dot( distatten, cAttenuationFactors.xyz ) * endFalloffFactor;
  89. if( g_bTeeth )
  90. {
  91. float mouthAtten = dot( worldNormal.xyz, cTeethAttenuationConst.xyz );
  92. mouthAtten = max( mouthAtten, 0.0f );
  93. mouthAtten *= cTeethAttenuationConst.w;
  94. vertAtten *= mouthAtten;
  95. }
  96. o.vDiffuse = vertAtten;
  97. o.worldNormal = worldNormal;
  98. return o;
  99. }