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.

116 lines
3.7 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. // STATIC: "BASETEXTURE" "0..1"
  3. #include "common_vs_fxc.h"
  4. const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
  5. const float4 cBaseTextureTransform[2] : register( SHADER_SPECIFIC_CONST_3 );
  6. struct VS_INPUT
  7. {
  8. float4 vPos : POSITION;
  9. float4 vNormal : NORMAL;
  10. float4 vBaseTexCoord : TEXCOORD0;
  11. float2 vLightmapTexCoord : TEXCOORD1;
  12. float2 vLightmapTexCoordOffset : TEXCOORD2;
  13. float3 vTangentS : TANGENT;
  14. float3 vTangentT : BINORMAL0;
  15. };
  16. struct VS_OUTPUT
  17. {
  18. float4 vProjPos_POSITION : POSITION;
  19. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  20. float fog : FOG;
  21. #endif
  22. float4 vBumpTexCoordXY_vTexCoordXY : TEXCOORD0;
  23. float4 vPositionToCameraRayTs_projW : TEXCOORD1;
  24. float4 vReflectXY_vRefractYX : TEXCOORD2;
  25. float4 vProjPos : TEXCOORD4;
  26. float3 worldPos : TEXCOORD5;
  27. #if BASETEXTURE
  28. float4 lightmapTexCoord1And2 : TEXCOORD6;
  29. float4 lightmapTexCoord3 : TEXCOORD7;
  30. #endif
  31. };
  32. VS_OUTPUT main( const VS_INPUT v )
  33. {
  34. VS_OUTPUT o = ( VS_OUTPUT )0;
  35. float3 vObjNormal;
  36. DecompressVertex_Normal( v.vNormal, vObjNormal );
  37. // Projected position
  38. float3 vWorldPos = mul4x3( v.vPos, cModel[0] );
  39. float4 vProjPos = mul( float4( vWorldPos, 1 ), cViewProj );
  40. #ifdef _PS3
  41. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  42. vProjPos.y = -vProjPos.y;
  43. vProjPos.z = 2.0f * vProjPos.z - vProjPos.w;
  44. #endif // _PS3
  45. o.vProjPos = o.vProjPos_POSITION = vProjPos;
  46. // Project tangent basis
  47. float2 vProjTangentS = mul( v.vTangentS, cViewProj ).xy;
  48. float2 vProjTangentT = mul( v.vTangentT, cViewProj ).xy;
  49. // Map projected position to the reflection texture
  50. float2 vReflectPos;
  51. vReflectPos.x = -vProjPos.x;
  52. vReflectPos.y = -vProjPos.y; // invert Y
  53. vReflectPos = ( vReflectPos + vProjPos.w ) * 0.5f;
  54. // Map projected position to the refraction texture
  55. float2 vRefractPos;
  56. vRefractPos.x = vProjPos.x;
  57. vRefractPos.y = -vProjPos.y; // invert Y
  58. vRefractPos = ( vRefractPos + vProjPos.w ) * 0.5f;
  59. // Reflection transform
  60. o.vReflectXY_vRefractYX = float4( vReflectPos.x, vReflectPos.y, vRefractPos.y, vRefractPos.x );
  61. o.vPositionToCameraRayTs_projW.w = vProjPos.w;
  62. // Compute fog based on the position
  63. o.worldPos = vWorldPos;
  64. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  65. o.fog = CalcFixedFunctionFog( vWorldPos, FOGTYPE_RANGE );
  66. #endif
  67. // Eye vector
  68. float3 vPositionToCameraRayWs = cEyePos.xyz - vWorldPos.xyz;
  69. // Transform to the tangent space
  70. o.vPositionToCameraRayTs_projW.x = dot( vPositionToCameraRayWs.xyz, v.vTangentS.xyz );
  71. o.vPositionToCameraRayTs_projW.y = dot( vPositionToCameraRayWs.xyz, v.vTangentT.xyz );
  72. o.vPositionToCameraRayTs_projW.z = dot( vPositionToCameraRayWs.xyz, vObjNormal.xyz );
  73. // Tranform bump coordinates
  74. o.vBumpTexCoordXY_vTexCoordXY.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] );
  75. o.vBumpTexCoordXY_vTexCoordXY.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] );
  76. #if BASETEXTURE
  77. o.vBumpTexCoordXY_vTexCoordXY.z = dot( v.vBaseTexCoord, cBaseTextureTransform[0] );
  78. o.vBumpTexCoordXY_vTexCoordXY.w = dot( v.vBaseTexCoord, cBaseTextureTransform[1] );
  79. o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord + v.vLightmapTexCoordOffset;
  80. float2 lightmapTexCoord2 = o.lightmapTexCoord1And2.xy + v.vLightmapTexCoordOffset;
  81. float2 lightmapTexCoord3 = lightmapTexCoord2 + v.vLightmapTexCoordOffset;
  82. // reversed component order
  83. o.lightmapTexCoord1And2.w = lightmapTexCoord2.x;
  84. o.lightmapTexCoord1And2.z = lightmapTexCoord2.y;
  85. o.lightmapTexCoord3.xy = lightmapTexCoord3;
  86. #else
  87. o.vBumpTexCoordXY_vTexCoordXY.z = 0.0f;
  88. o.vBumpTexCoordXY_vTexCoordXY.w = 0.0f;
  89. #endif
  90. return o;
  91. }