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.

227 lines
7.0 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "DETAIL1" "0..1"
  3. // STATIC: "DETAIL2" "0..1"
  4. // STATIC: "TANGENTTOPACITY" "0..1"
  5. // STATIC: "TANGENTSOPACITY" "0..1"
  6. // STATIC: "FRESNELOPACITY" "0..1"
  7. // STATIC: "VERTEXCOLOR" "0..1"
  8. // STATIC: "FLOWMAP" "0..1"
  9. // STATIC: "MODELFORMAT" "0..1"
  10. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  11. // DYNAMIC: "SKINNING" "0..1"
  12. // DYNAMIC: "VORTEX1" "0..1"
  13. // DYNAMIC: "VORTEX2" "0..1"
  14. // SKIP: ( ( $DETAIL1 == 0 ) && ( $DETAIL2 != 0 ) )
  15. // SKIP: ( $TANGENTTOPACITY && $TANGENTSOPACITY )
  16. // SKIP: ( $FLOWMAP && ( $DETAIL1 || $DETAIL2 ) )
  17. // SKIP: ( ( $FLOWMAP == 0 ) && ( $VORTEX1 || $VORTEX2 ) )
  18. #include "common_fog_vs_fxc.h"
  19. #include "common_vs_fxc.h"
  20. const float4 cBaseTextureTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); // 0-1
  21. const float4 cDetail1TextureTransform[2] : register( SHADER_SPECIFIC_CONST_2 ); // 2-3
  22. const float4 g_vEyePosition : register( SHADER_SPECIFIC_CONST_4 );
  23. #define g_vEyePos g_vEyePosition.xyz
  24. //#define UNUSED g_vEyePosition.w
  25. const float4 cDetail2TextureTransform[2] : register( SHADER_SPECIFIC_CONST_6 ); //6-7
  26. const float4 g_vVortexPos1_NoiseScale : register( SHADER_SPECIFIC_CONST_9 );
  27. #define g_vVortexPos1 g_vVortexPos1_NoiseScale.xyz
  28. #define g_flNoiseScale g_vVortexPos1_NoiseScale.w
  29. const float4 g_vVortexPos2_NormalUVScale : register( SHADER_SPECIFIC_CONST_10 );
  30. #define g_vVortexPos2 g_vVortexPos2_NormalUVScale.xyz
  31. #define g_flNormalUVScale g_vVortexPos2_NormalUVScale.w
  32. // Structs
  33. struct VS_INPUT
  34. {
  35. float4 vPos : POSITION;
  36. float2 vTexCoord : TEXCOORD0;
  37. float4 vNormal : NORMAL;
  38. float3 vTangentS : TANGENT;
  39. float3 vTangentT : BINORMAL;
  40. float4 vUserData : TANGENT;
  41. float4 vBoneWeights : BLENDWEIGHT;
  42. float4 vBoneIndices : BLENDINDICES;
  43. #if ( VERTEXCOLOR )
  44. float4 vColor : COLOR0;
  45. #endif
  46. };
  47. struct VS_OUTPUT
  48. {
  49. float4 vProjPos : POSITION; // Projection-space position
  50. float4 vUV0_UV1 : TEXCOORD0;
  51. float4 vFlowUV_UV2 : TEXCOORD1;
  52. float4 vIteratedProjPos : TEXCOORD2;
  53. #if ( VORTEX1 )
  54. float3 vVortexPositions1 : TEXCOORD3;
  55. #endif
  56. #if ( VORTEX2 )
  57. float3 vVortexPositions2 : TEXCOORD4;
  58. #endif
  59. #if ( TANGENTSOPACITY || TANGENTTOPACITY || FRESNELOPACITY )
  60. float4 vWorldNormal_worldEyeX : TEXCOORD5;
  61. float4 vWorldTangent_worldEyeY : TEXCOORD6;
  62. float4 vTangentAlignedView_worldEyeZ : TEXCOORD7;
  63. #endif
  64. #if ( VERTEXCOLOR )
  65. float4 vColor : COLOR0;
  66. #endif
  67. };
  68. // Main
  69. VS_OUTPUT main( const VS_INPUT i )
  70. {
  71. VS_OUTPUT o;
  72. float4 projPos;
  73. float3 worldPos;
  74. float3 vWorldTangentT = float3( 0.0f, 0.0f, 0.0f );
  75. float3 vWorldTangentS = float3( 0.0f, 0.0f, 0.0f );
  76. float3 vWorldNormal = float3( 0.0f, 0.0f, 0.0f );
  77. //SkinPosition( SKINNING, i.vPos, i.vBoneWeights, i.vBoneIndices, worldPos );
  78. worldPos = mul4x3( i.vPos, cModel[0] );
  79. projPos = mul( float4( worldPos, 1 ), cViewProj );
  80. o.vProjPos = projPos;
  81. #if ( VERTEXCOLOR )
  82. {
  83. o.vColor.rgba = i.vColor.rgba;
  84. }
  85. #endif
  86. float3 vCameraToPositionRayWs = g_vEyePos.xyz - worldPos.xyz;
  87. float3 vCameraToPositionDirWs = float3( 0.0f, 0.0f, 0.0f );
  88. #if( TANGENTTOPACITY || TANGENTSOPACITY || FRESNELOPACITY )
  89. {
  90. vCameraToPositionDirWs = normalize( vCameraToPositionRayWs );
  91. o.vWorldNormal_worldEyeX.w = vCameraToPositionDirWs.x;
  92. o.vWorldTangent_worldEyeY.w = vCameraToPositionDirWs.y;
  93. o.vTangentAlignedView_worldEyeZ.w = vCameraToPositionDirWs.z;
  94. }
  95. #endif
  96. #if ( FRESNELOPACITY || TANGENTTOPACITY || TANGENTSOPACITY || FLOWMAP )
  97. {
  98. #if ( MODELFORMAT )
  99. {
  100. float4 vWorldTangent;
  101. DecompressVertex_NormalTangent( i.vNormal, i.vUserData, vWorldNormal, vWorldTangent );
  102. vWorldTangentT = vWorldTangent.xyz;
  103. vWorldTangentS = normalize( cross( vWorldNormal, vWorldTangentT ) * i.vUserData.w );
  104. #if ( FRESNELOPACITY || TANGENTTOPACITY || TANGENTSOPACITY )
  105. {
  106. o.vWorldNormal_worldEyeX.xyz = vWorldNormal;
  107. }
  108. #endif
  109. }
  110. #else
  111. {
  112. vWorldTangentT = mul3x3( i.vTangentT.xyz, ( const float3x3 )cModel[0] );
  113. vWorldTangentS = mul3x3( i.vTangentS.xyz, ( const float3x3 )cModel[0] );
  114. float3 vObjNormal;
  115. DecompressVertex_Normal( i.vNormal, vObjNormal );
  116. vWorldNormal = mul3x3( vObjNormal, ( float3x3 )cModel[0] );
  117. #if ( FRESNELOPACITY || TANGENTTOPACITY || TANGENTSOPACITY )
  118. {
  119. o.vWorldNormal_worldEyeX.xyz = vWorldNormal;
  120. }
  121. #endif
  122. }
  123. #endif
  124. #if ( TANGENTTOPACITY )
  125. {
  126. o.vWorldTangent_worldEyeY.xyz = vWorldTangentT;
  127. float3 vRightT = cross( vWorldTangentS.xyz, vCameraToPositionDirWs.xyz );
  128. float3 vAlignedViewT = normalize( cross( vWorldTangentS.xyz, vRightT.xyz ) );
  129. o.vTangentAlignedView_worldEyeZ.xyz = vAlignedViewT.xyz;
  130. }
  131. #elif ( TANGENTSOPACITY )
  132. {
  133. float3 vRightS = cross( vWorldTangentT.xyz, vCameraToPositionDirWs.xyz );
  134. float3 vAlignedViewS = normalize( cross( vWorldTangentT.xyz, vRightS.xyz ) );
  135. o.vTangentAlignedView_worldEyeZ.xyz = vAlignedViewS.xyz;
  136. o.vWorldTangent_worldEyeY.xyz = vWorldTangentS;
  137. }
  138. #elif ( FRESNELOPACITY )
  139. {
  140. o.vTangentAlignedView_worldEyeZ.xyz = float3( 0.0f, 0.0f, 0.0f );
  141. o.vWorldTangent_worldEyeY.xyz = float3( 0.0f, 0.0f, 0.0f );
  142. }
  143. #endif
  144. }
  145. #endif
  146. o.vIteratedProjPos = projPos;
  147. #ifdef _PS3
  148. {
  149. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  150. o.vProjPos.y = -o.vProjPos.y;
  151. o.vProjPos.z = 2.0f * o.vProjPos.z - o.vProjPos.w;
  152. }
  153. #endif // _PS3
  154. o.vUV0_UV1.x = dot( i.vTexCoord.xy, cBaseTextureTransform[0].xy ) + cBaseTextureTransform[0].w;
  155. o.vUV0_UV1.y = dot( i.vTexCoord.xy, cBaseTextureTransform[1].xy ) + cBaseTextureTransform[1].w;
  156. #if ( DETAIL1 )
  157. {
  158. o.vUV0_UV1.z = dot( i.vTexCoord.xy, cDetail1TextureTransform[0].xy ) + cDetail1TextureTransform[0].w;
  159. o.vUV0_UV1.w = dot( i.vTexCoord.xy, cDetail1TextureTransform[1].xy ) + cDetail1TextureTransform[1].w;
  160. }
  161. #else
  162. {
  163. o.vUV0_UV1.zw = float2( 0.0f, 0.0f );
  164. }
  165. #endif
  166. #if ( DETAIL2 )
  167. {
  168. o.vFlowUV_UV2.z = dot( i.vTexCoord.xy, cDetail2TextureTransform[0].xy ) + cDetail2TextureTransform[0].w;
  169. o.vFlowUV_UV2.w = dot( i.vTexCoord.xy, cDetail2TextureTransform[1].xy ) + cDetail2TextureTransform[1].w;
  170. }
  171. #else
  172. {
  173. o.vFlowUV_UV2.zw = float2( 0.0f, 0.0f );
  174. }
  175. #endif
  176. #if ( FLOWMAP )
  177. {
  178. float2 vFlowUV = i.vTexCoord.xy;
  179. #if ( !MODELFORMAT )
  180. {
  181. vFlowUV = float2( dot( worldPos.xyz, vWorldTangentS.xyz ), dot( worldPos.xyz, vWorldTangentT.xyz ) );
  182. }
  183. #endif
  184. o.vFlowUV_UV2.xy = vFlowUV.xy;
  185. o.vFlowUV_UV2.zw = vFlowUV.xy * g_flNoiseScale;
  186. o.vUV0_UV1.zw = vFlowUV.xy * g_flNormalUVScale;
  187. #if ( VORTEX1 )
  188. {
  189. float3 vVPos1 = g_vVortexPos1.xyz - worldPos.xyz;
  190. o.vVortexPositions1.xyz = -float3( dot( vVPos1, vWorldTangentS.xyz ), dot( vVPos1, vWorldTangentT.xyz ), dot( vVPos1, vWorldNormal.xyz ) );
  191. }
  192. #endif
  193. #if ( VORTEX2 )
  194. {
  195. float3 vVPos2 = g_vVortexPos2.xyz - worldPos.xyz;
  196. o.vVortexPositions2.xyz = -float3( dot( vVPos2, vWorldTangentS.xyz ), dot( vVPos2.xyz, vWorldTangentT.xyz ), dot( vVPos2.xyz, vWorldNormal.xyz ) );
  197. }
  198. #endif
  199. }
  200. #else
  201. {
  202. o.vFlowUV_UV2.xy = float2( 0.0f, 0.0f );
  203. }
  204. #endif
  205. return o;
  206. }