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.

168 lines
5.0 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. // STATIC: "BASETEXTURE" "0..1"
  3. // STATIC: "MULTITEXTURE" "0..1"
  4. // STATIC: "FLASHLIGHT" "0..1"
  5. // STATIC: "LIGHTMAPWATERFOG" "0..1"
  6. // STATIC: "FLOWMAP" "0..1"
  7. // Multitexture and basetexture are mutually exclusive.
  8. // SKIP: $MULTITEXTURE && $BASETEXTURE
  9. // flowmap doesn't play with multitexture or basetexture
  10. // SKIP: $FLOWMAP && $MULTITEXTURE
  11. // Have to have the flashlight on to get flashlightshadows.
  12. // SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 )
  13. // basetexture doesn't work with flashlight or lightmapwaterfog. multitexture doesn't either. We don't use basetexture or multitexture in newer code and instead use flowmap and flashlight.
  14. // SKIP: ( $FLASHLIGHT || $LIGHTMAPWATERFOG ) && ( ( $BASETEXTURE && !$FLOWMAP ) || $MULTITEXTURE )
  15. #include "common_vs_fxc.h"
  16. const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
  17. const float4 TexOffsets : register( SHADER_SPECIFIC_CONST_3 );
  18. #if FLASHLIGHT
  19. const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_4 );
  20. #endif
  21. struct VS_INPUT
  22. {
  23. float4 vPos : POSITION;
  24. float4 vNormal : NORMAL;
  25. float4 vBaseTexCoord : TEXCOORD0;
  26. float2 vLightmapTexCoord : TEXCOORD1;
  27. float2 vLightmapTexCoordOffset : TEXCOORD2;
  28. float3 vTangentS : TANGENT;
  29. float3 vTangentT : BINORMAL0;
  30. };
  31. struct VS_OUTPUT
  32. {
  33. float4 vProjPos_POSITION : POSITION;
  34. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  35. float fog : FOG;
  36. #endif
  37. float2 vBumpTexCoord : TEXCOORD0;
  38. float3 vPositionToCameraRayWs : TEXCOORD1;
  39. float4 vReflectXY_vRefractYX : TEXCOORD2;
  40. float4 vProjPos : TEXCOORD3;
  41. float3 worldPos : TEXCOORD4;
  42. #if FLASHLIGHT
  43. float4 flashlightSpacePos : TEXCOORD5;
  44. #endif
  45. #if MULTITEXTURE
  46. float4 vExtraBumpTexCoord : TEXCOORD5;
  47. #endif
  48. #if ( BASETEXTURE && !FLOWMAP )
  49. float4 lightmapTexCoord1And2 : TEXCOORD5;
  50. float2 lightmapTexCoord3 : TEXCOORD6;
  51. #endif
  52. #if LIGHTMAPWATERFOG
  53. float2 lightmapTexCoord : TEXCOORD7;
  54. #endif
  55. };
  56. VS_OUTPUT main( const VS_INPUT v )
  57. {
  58. VS_OUTPUT o;
  59. float3 vObjNormal;
  60. DecompressVertex_Normal( v.vNormal, vObjNormal );
  61. // Projected position
  62. float3 vWorldPos = mul4x3( v.vPos, cModel[0] );
  63. float4 vProjPos = mul( float4( vWorldPos, 1 ), cViewProj );
  64. o.vProjPos = o.vProjPos_POSITION = vProjPos;
  65. // Project tangent basis
  66. float2 vProjTangentS = mul( v.vTangentS, cViewProj ).xy;
  67. float2 vProjTangentT = mul( v.vTangentT, cViewProj ).xy;
  68. // Map projected position to the reflection texture
  69. float2 vReflectPos;
  70. vReflectPos = (vProjPos.xy + vProjPos.w) * 0.5f;
  71. // Map projected position to the refraction texture
  72. float2 vRefractPos;
  73. vRefractPos.x = vProjPos.x;
  74. vRefractPos.y = -vProjPos.y; // invert Y
  75. vRefractPos = (vRefractPos + vProjPos.w) * 0.5f;
  76. // Reflection transform
  77. o.vReflectXY_vRefractYX = float4( vReflectPos.x, vReflectPos.y, vRefractPos.y, vRefractPos.x );
  78. #ifdef _PS3
  79. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  80. o.vProjPos_POSITION.y = -o.vProjPos_POSITION.y;
  81. o.vProjPos_POSITION.z = 2.0f * o.vProjPos_POSITION.z - o.vProjPos_POSITION.w;
  82. #endif // _PS3
  83. // Compute fog based on the position
  84. o.worldPos = vWorldPos;
  85. #if ( !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 ) )
  86. {
  87. o.fog = CalcFixedFunctionFog( vWorldPos, FOGTYPE_RANGE );
  88. }
  89. #endif
  90. // Eye vector
  91. float3 vPositionToCameraRayWs = cEyePos.xyz - vWorldPos.xyz;
  92. // Transform to the tangent space
  93. //o.vTangentEyeVect.x = dot( vPositionToCameraRayWs, v.vTangentS );
  94. //o.vTangentEyeVect.y = dot( vPositionToCameraRayWs, v.vTangentT );
  95. //o.vTangentEyeVect.z = dot( vPositionToCameraRayWs, vObjNormal );
  96. o.vPositionToCameraRayWs.xyz = vPositionToCameraRayWs.xyz;
  97. // Tranform bump coordinates
  98. o.vBumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] );
  99. o.vBumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] );
  100. float f45x=v.vBaseTexCoord.x+v.vBaseTexCoord.y;
  101. float f45y=v.vBaseTexCoord.y-v.vBaseTexCoord.x;
  102. #if ( MULTITEXTURE )
  103. {
  104. o.vExtraBumpTexCoord.x=f45x*0.1+TexOffsets.x;
  105. o.vExtraBumpTexCoord.y=f45y*0.1+TexOffsets.y;
  106. o.vExtraBumpTexCoord.z=v.vBaseTexCoord.y*0.45+TexOffsets.z;
  107. o.vExtraBumpTexCoord.w=v.vBaseTexCoord.x*0.45+TexOffsets.w;
  108. }
  109. #endif
  110. #if ( BASETEXTURE && !FLOWMAP )
  111. {
  112. o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord + v.vLightmapTexCoordOffset;
  113. float2 lightmapTexCoord2 = o.lightmapTexCoord1And2.xy + v.vLightmapTexCoordOffset;
  114. float2 lightmapTexCoord3 = lightmapTexCoord2 + v.vLightmapTexCoordOffset;
  115. // reversed component order
  116. o.lightmapTexCoord1And2.w = lightmapTexCoord2.x;
  117. o.lightmapTexCoord1And2.z = lightmapTexCoord2.y;
  118. o.lightmapTexCoord3.xy = lightmapTexCoord3;
  119. }
  120. #endif
  121. #if LIGHTMAPWATERFOG
  122. {
  123. o.lightmapTexCoord.xy = v.vLightmapTexCoord.xy;
  124. }
  125. #endif
  126. #if FLASHLIGHT
  127. {
  128. o.flashlightSpacePos = TransformFlashlightWorldToTexture( vWorldPos, g_FlashlightWorldToTexture );
  129. }
  130. #endif
  131. return o;
  132. }