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.

602 lines
21 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "SFM" "0..0" [vs20] [PC]
  3. // STATIC: "SFM" "0..1" [vs30] [PC]
  4. // STATIC: "SFM" "0..0" [CONSOLE]
  5. // STATIC: "VERTEXCOLOR" "0..1"
  6. // STATIC: "CUBEMAP" "0..1"
  7. // STATIC: "HALFLAMBERT" "0..1"
  8. // STATIC: "FLASHLIGHT" "0..1"
  9. // disable separate detail UVs & seamless base/detail (does not appear to be used)
  10. // STATIC: "SEPARATE_DETAIL_UVS" "0..0"
  11. // STATIC: "SEAMLESS_BASE" "0..0"
  12. // STATIC: "SEAMLESS_DETAIL" "0..0"
  13. // STATIC: "DECAL" "0..1"
  14. // STATIC: "LIGHTING_PREVIEW" "0..1" [PC] // Disabled. Unused on CS:GO --Thorsten
  15. // STATIC: "LIGHTING_PREVIEW" "0..0" [CONSOLE]
  16. // STATIC: "TREESWAY" "0..0" [vs20] [PC]
  17. // STATIC: "TREESWAY" "0..2" [vs30] [PC]
  18. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1" [vs20] [PC]
  19. // STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..0" [CONSOLE]
  20. // STATIC: "CASCADED_SHADOW_MAPPING" "0..1" [vs20] [PC]
  21. // STATIC: "CASCADED_SHADOW_MAPPING" "0..0" [vs30] [PC]
  22. // STATIC: "CSM_BLENDING" "0..1"
  23. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  24. // DYNAMIC: "DYNAMIC_LIGHT" "0..1"
  25. // DYNAMIC: "SKINNING" "0..1"
  26. // DYNAMIC: "MORPHING" "0..0" [ = false ]
  27. // DYNAMIC: "TESSELLATION" "0..0" [vs30] [PC]
  28. // DYNAMIC: "TESSELLATION" "0..0" [CONSOLE]
  29. // DYNAMIC: "TESSELLATION" "0..0" [vs20] [PC]
  30. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] [PC]
  31. // DYNAMIC: "NUM_LIGHTS" "0..0" [vs20] [CONSOLE]
  32. // DYNAMIC: "STATICLIGHT3" "0..2"
  33. // If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
  34. // SKIP: ( $FLATTEN_STATIC_CONTROL_FLOW == 0 ) && ( $NUM_LIGHTS > 0 ) [vs20] [PC]
  35. // SKIP: ($SEPARATE_DETAIL_UVS) && ($SEAMLESS_DETAIL)
  36. // SKIP: ($TREESWAY) && ($MORPHING)
  37. // SKIP: ($TREESWAY) && ($TESSELLATION)
  38. // SKIP: ( $TREESWAY ) && ( $SEAMLESS_DETAIL || $SEAMLESS_BASE )
  39. // SKIP: ( $SFM == 0 ) && ( $MORPHING )
  40. // SKIP: ( $SFM == 0 ) && ( $TESSELLATION )
  41. // This blows instruction limits and isn't used
  42. // That is, non-static-control flow is only on MacOS, which doesn't use HARDWAREFOGBLEND
  43. // SKIP: ( $FLATTEN_STATIC_CONTROL_FLOW == 1 ) && ( $HARDWAREFOGBLEND )
  44. #include "common_fog_vs_supportsvertexfog_fxc.h"
  45. // When tessellating, we don't have room in the super-prim vertices for more colors, tex coords or objects space positions
  46. // SKIP: ( $STATICLIGHT3 || $VERTEXCOLOR || $SEAMLESS_BASE || $SEAMLESS_DETAIL || $SEPARATE_DETAIL_UVS || $MORPHING || $SKINNING || $COMPRESSED_VERTS ) && $TESSELLATION
  47. #include "common_vs_fxc.h"
  48. static const bool g_bSkinning = SKINNING ? true : false;
  49. static const int g_FogType = DOWATERFOG;
  50. static const bool g_bVertexColor = VERTEXCOLOR ? true : false;
  51. static const bool g_bCubemap = CUBEMAP ? true : false;
  52. static const bool g_bFlashlight = FLASHLIGHT ? true : false;
  53. static const bool g_bHalfLambert = HALFLAMBERT ? true : false;
  54. #if (defined( SHADER_MODEL_VS_3_0 ) && MORPHING && DECAL)
  55. static const bool g_bDecalOffset = true;
  56. #else
  57. static const bool g_bDecalOffset = false;
  58. #endif
  59. const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); // 0 & 1
  60. #if ( LIGHTING_PREVIEW == 3 )
  61. const float4 g_vEyeVector : register( SHADER_SPECIFIC_CONST_2 );
  62. #define g_flStaticLightEnabled 0
  63. #else
  64. const float4 g_flStaticLightEnabled_vCSMLightColor : register( SHADER_SPECIFIC_CONST_2 );
  65. #define g_flStaticLightEnabled (g_flStaticLightEnabled_vCSMLightColor.x)
  66. #define g_vCSMLightColor (g_flStaticLightEnabled_vCSMLightColor.yzw)
  67. #endif
  68. #if ( CASCADED_SHADOW_MAPPING == 0 )
  69. const float4 g_vMiscParams1 : register( SHADER_SPECIFIC_CONST_3 );
  70. #if ( SEAMLESS_DETAIL || SEAMLESS_BASE )
  71. #define SEAMLESS_SCALE g_vMiscParams1.x
  72. #elif TESSELLATION
  73. #define g_SubDControls g_vMiscParams1
  74. #endif
  75. #endif // CASCADED_SHADOW_MAPPING
  76. const float4 cDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); // 4 & 5
  77. const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_6 ); // 6, 7, 8, 9
  78. const float4 g_vMiscParams2 : register( SHADER_SPECIFIC_CONST_12 );
  79. #define cSinglePassFlashlight g_vMiscParams2.x
  80. const float4 g_vMiscParams3 : register( SHADER_SPECIFIC_CONST_10 );
  81. const float4 g_vMiscParams4 : register( SHADER_SPECIFIC_CONST_11 );
  82. #if ( CASCADED_SHADOW_MAPPING )
  83. const float4x4 g_matWorldToShadowTexMatrices[2] : register( SHADER_SPECIFIC_CONST_CSM_0 );
  84. const float4 g_matWorldToShadowTexMatrix0_z : register( SHADER_SPECIFIC_CONST_CSM_1 );
  85. #endif
  86. #if ( TREESWAY )
  87. #define g_flTime g_vMiscParams2.y
  88. #define g_vWindDir g_vMiscParams2.zw
  89. #define g_flFastSwaySpeedScale g_vMiscParams1.x
  90. #define g_flScrumbleFalloffCurve g_vMiscParams1.y
  91. #define g_flSwayFalloffCurve g_vMiscParams1.z
  92. #define g_flScrumbleSpeed g_vMiscParams1.w
  93. #define g_flHeight g_vMiscParams3.x
  94. #define g_flStartHeight g_vMiscParams3.y
  95. #define g_flRadius g_vMiscParams3.z
  96. #define g_flStartRadius g_vMiscParams3.w
  97. #define g_flSwaySpeed g_vMiscParams4.x
  98. #define g_flSwayIntensity g_vMiscParams4.y
  99. #define g_flScrumbleWaveCount g_vMiscParams4.z
  100. #define g_flScrumbleIntensity g_vMiscParams4.w
  101. #define g_flWindSpeedLerpStart cDetailTexCoordTransform[0].x
  102. #define g_flWindSpeedLerpEnd cDetailTexCoordTransform[0].y
  103. #endif
  104. #if ( MORPHING )
  105. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  106. // cMorphTargetTextureDim.z = 4tuples/morph
  107. #define cMorphTargetTextureDim g_vMiscParams3
  108. #define cMorphSubrect g_vMiscParams4
  109. sampler2D morphSampler : register( s0 );
  110. #endif
  111. #if ( TESSELLATION )
  112. // VS_INPUT defined in header
  113. #include "tessellation_vs_fxc.h"
  114. sampler2D BezierSampler : register( s1 );
  115. sampler2D DispSampler : register( s2 );
  116. #else // no TESSELLATION
  117. struct VS_INPUT
  118. {
  119. float4 vPos : POSITION;
  120. float4 vBoneWeights : BLENDWEIGHT;
  121. float4 vBoneIndices : BLENDINDICES;
  122. float4 vNormal : NORMAL;
  123. #if VERTEXCOLOR
  124. float4 vColor : COLOR0;
  125. #else
  126. #if DECAL
  127. float4 vStaticLight : COLOR0;
  128. #else
  129. float4 vStaticLight : COLOR1;
  130. #endif
  131. #if STATICLIGHT3
  132. float4 vStaticLight2 : COLOR2;
  133. float4 vStaticLight3 : COLOR3;
  134. #endif
  135. #endif
  136. // make these float2's and stick the [n n 0 1] in the dot math.
  137. float4 vTexCoord0 : TEXCOORD0;
  138. float4 vTexCoord1 : TEXCOORD1;
  139. float4 vTexCoord2 : TEXCOORD2;
  140. float4 vTexCoord3 : TEXCOORD3;
  141. // Position and normal/tangent deltas
  142. float3 vPosFlex : POSITION1;
  143. float3 vNormalFlex : NORMAL1;
  144. #if ( SFM )
  145. float vVertexID : POSITION2;
  146. #endif
  147. };
  148. #endif // TESSELLATION
  149. struct VS_OUTPUT
  150. {
  151. // Stuff that isn't seen by the pixel shader
  152. float4 projPos : POSITION;
  153. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  154. float fog : FOG;
  155. #endif
  156. // Stuff that is seen by the pixel shader
  157. float4 baseTexCoord_baseTexCoord2u : TEXCOORD0; // Base texture coordinates in .xy, seamless in .xyz, 2nd (decal) uv set 'u' in .w
  158. float4 detailTexCoord_baseTexCoord2v : TEXCOORD1; // Detail texture coordinates in .xy, seamless in .xyz, 2nd (decal) uv set 'v' in .w
  159. float4 vWorldNormal_fogFactorW : TEXCOORD2; // world space normal in .xyz, fog factor in .w
  160. float4 vWorldPos_csmXform0z : TEXCOORD3; // world pos in .xyz, csm lightToWorldxformcascade0.z in .w
  161. float4 directionalLightingColor_flShadowDimScalar : TEXCOORD4;
  162. float4 csmXform0or1_csmXform2 : TEXCOORD5; // csm lightToWorldxformcascade0 or 1.xy in .xy lightToWorldxformcascade2.xy in .zw
  163. float4 color : TEXCOORD6; // vertex color from lighting or unlit in .xyz
  164. float4 vProjPos : TEXCOORD7; // proj pos .xyzw
  165. #if FLASHLIGHT && defined( SHADER_MODEL_VS_3_0 )
  166. float4 flashlightSpacePos : TEXCOORD8;
  167. #endif
  168. #if SEAMLESS_DETAIL || SEAMLESS_BASE
  169. float3 SeamlessWeights : COLOR0; // x y z projection weights
  170. #endif
  171. };
  172. #include "tree_sway.h"
  173. float Luminance( float3 cColor )
  174. {
  175. // Formula for calculating luminance based on NTSC standard
  176. return dot( cColor.rgb, float3( 0.2125, 0.7154, 0.0721 ) );
  177. }
  178. VS_OUTPUT main( const VS_INPUT v )
  179. {
  180. VS_OUTPUT o = ( VS_OUTPUT ) 0 ;
  181. bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
  182. bool bStaticLight = g_flStaticLightEnabled ? true : false;
  183. bool bDoLighting = !g_bVertexColor && ( bDynamicLight || bStaticLight);
  184. float3 worldPos;
  185. #if ( TESSELLATION )
  186. {
  187. EvaluateSubdivisionSurface( v, g_SubDControls.x, g_SubDControls.y, g_SubDControls.z,
  188. BezierSampler, DispSampler,
  189. o.vWorldNormal_fogFactorW.xyz, worldPos,
  190. o.baseTexCoord_baseTexCoord2u.xy, o.detailTexCoord_baseTexCoord2v.xy );
  191. float3 vDummySpecular = float3(0,0,0);
  192. o.color_csmXform0z.xyz = DoLighting( worldPos, o.vWorldNormal_fogFactorW.xyz, vDummySpecular, bStaticLight, bDynamicLight, g_bHalfLambert );
  193. }
  194. #else // no TESSELLATION
  195. {
  196. float4 vPosition = v.vPos;
  197. float3 vNormal = 0;
  198. if ( bDoLighting || FLASHLIGHT || SEAMLESS_BASE || SEAMLESS_DETAIL || LIGHTING_PREVIEW || g_bDecalOffset || CUBEMAP )
  199. {
  200. // The vertex only contains valid normals if they are actually needed (fetching them when absent makes D3D complain)
  201. DecompressVertex_Normal( v.vNormal, vNormal );
  202. }
  203. else
  204. {
  205. if ( SEAMLESS_BASE || SEAMLESS_DETAIL || g_bDecalOffset || g_bFlashlight )
  206. {
  207. // The vertex only contains valid normals if they are actually needed (fetching them when absent makes D3D complain)
  208. DecompressVertex_Normal( v.vNormal, vNormal );
  209. }
  210. }
  211. #if ( SEAMLESS_BASE || SEAMLESS_DETAIL )
  212. {
  213. // compute blend weights in rgb
  214. float3 NNormal = normalize( vNormal );
  215. o.SeamlessWeights.xyz = NNormal * NNormal; // sums to 1.
  216. }
  217. #endif
  218. #if ( !MORPHING )
  219. {
  220. ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal );
  221. }
  222. #else
  223. {
  224. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, v.vTexCoord2, vPosition.xyz, vNormal );
  225. }
  226. #endif
  227. #if ( TREESWAY )
  228. {
  229. vPosition.xyz = ComputeTreeSway( vPosition.xyz, g_flTime );
  230. }
  231. #endif
  232. SkinPositionAndNormal( g_bSkinning, vPosition, vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, o.vWorldNormal_fogFactorW.xyz );
  233. if ( !g_bVertexColor )
  234. {
  235. o.vWorldNormal_fogFactorW.xyz = normalize( o.vWorldNormal_fogFactorW.xyz );
  236. }
  237. #if ( MORPHING && DECAL )
  238. {
  239. // Avoid z precision errors
  240. worldPos += o.vWorldNormal_fogFactorW.xyz * 0.05f * v.vTexCoord2.z;
  241. }
  242. #endif
  243. o.color = float4( 0.0f, 0.0f, 0.0f, 0.0f );
  244. #if ( !FLASHLIGHT ) && ( defined( _GAMECONSOLE ) || defined ( SHADER_MODEL_VS_3_0 ) || ( CASCADED_SHADOW_MAPPING == 1 ) )
  245. {
  246. o.directionalLightingColor_flShadowDimScalar = float4( 0.0f, 0.0f, 0.0f, 0.0f );
  247. }
  248. #endif
  249. #if ( VERTEXCOLOR )
  250. {
  251. // Assume that this is unlitgeneric if you are using vertex color.
  252. o.color.rgb = GammaToLinear( v.vColor.rgb );
  253. o.color.a = v.vColor.a;
  254. }
  255. #else
  256. {
  257. float4 staticLightColor;
  258. float3 vDirectLighting = float3(0.0f, 0.0f, 0.0f);
  259. // Compute vertex lighting
  260. #if ( STATICLIGHT3 != 0 )
  261. {
  262. // We always assume three incoming streams.
  263. // They will not be equal if bumped data is taking this path as part of a lower gpu_level setting.
  264. // They will be equal otherwise.
  265. // Take the average of incoming streams for PS to use (after converting to linear space).
  266. staticLightColor.rgb = GammaToLinear( v.vStaticLight.rgb * cOverbright );
  267. staticLightColor.rgb += GammaToLinear( v.vStaticLight2.rgb * cOverbright );
  268. staticLightColor.rgb += GammaToLinear( v.vStaticLight3.rgb * cOverbright );
  269. // .a already in linear space
  270. staticLightColor.a = ( v.vStaticLight.a + v.vStaticLight2.a + v.vStaticLight3.a );
  271. staticLightColor /= 3.0f;
  272. #if ( ( FLATTEN_STATIC_CONTROL_FLOW == 0 ) || defined ( SHADER_MODEL_VS_3_0 ) )
  273. {
  274. float3 dynamicLighting = float3( 0.0f, 0.0f, 0.0f );
  275. #if ( STATICLIGHT3 == 1 )
  276. // explicitly add dynamic lights (without adding ambient cube)
  277. if ( bDynamicLight )
  278. {
  279. for ( int i = 0; i < g_nLightCount; i++ )
  280. {
  281. dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, i, g_bHalfLambert );
  282. }
  283. }
  284. // Sunlight light baked into static light.
  285. #if ( CSM_BLENDING == 1 )
  286. // Remove sunlight from baked lighting, leaving only indirect.
  287. o.directionalLightingColor_flShadowDimScalar.rgb = g_vCSMLightColor * staticLightColor.a;
  288. staticLightColor.rgb -= o.directionalLightingColor_flShadowDimScalar.rgb;
  289. #else
  290. o.directionalLightingColor_flShadowDimScalar.rgb = float3( 0.0f, 0.0f, 0.0f );
  291. #endif
  292. #else
  293. // STATICLIGHT3 == 2 => indirect lighting only is baked (model classified as phong as far as static lighting is concerned if any materials contain $phong)
  294. // explicitly add dynamic lights (without adding ambient cube)
  295. // dynamic lighting, 0th light is CSM light in this path. We skip it and apply in the pixel shader using baked direct lighting intensity
  296. // stored in o.directionalLightingColor_flShadowDimScalar.a (from baked lighting data)
  297. for ( int i = 0; i < g_nLightCount; i++ )
  298. {
  299. if (i > 0) // starting loop at i == 1 causes warning about forcing the loop to unroll
  300. {
  301. dynamicLighting.rgb += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, i, g_bHalfLambert );
  302. }
  303. }
  304. o.directionalLightingColor_flShadowDimScalar.rgb = cLightInfo[0].color.rgb * staticLightColor.a;
  305. #endif
  306. o.color.rgb = staticLightColor.rgb + dynamicLighting.rgb;
  307. }
  308. #else
  309. {
  310. float3 dynamicLighting = float3( 0.0f, 0.0f, 0.0f );
  311. #if ( STATICLIGHT3 == 1 )
  312. // explicitly add dynamic lights (without adding ambient cube)
  313. if( bDynamicLight ) // Ambient light
  314. {
  315. if ( NUM_LIGHTS >= 1 )
  316. dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 0, g_bHalfLambert );
  317. if ( NUM_LIGHTS >= 2 )
  318. dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 1, g_bHalfLambert );
  319. if ( NUM_LIGHTS >= 3 )
  320. dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 2, g_bHalfLambert );
  321. if ( NUM_LIGHTS >= 4 )
  322. dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 3, g_bHalfLambert );
  323. }
  324. // Sunlight light baked into static light.
  325. #if ( CSM_BLENDING == 1 )
  326. // Remove sunlight from baked lighting, leaving only indirect.
  327. o.directionalLightingColor_flShadowDimScalar.rgb = g_vCSMLightColor * staticLightColor.a;
  328. staticLightColor.rgb -= o.directionalLightingColor_flShadowDimScalar.rgb;
  329. #else
  330. o.directionalLightingColor_flShadowDimScalar.rgb = float3( 0.0f, 0.0f, 0.0f );
  331. #endif
  332. #else
  333. // STATICLIGHT3 == 2 => indirect lighting only is baked (model classified as phong as far as static lighting is concerned if any materials contain $phong)
  334. // explicitly add dynamic lights (without adding ambient cube)
  335. // dynamic lighting, 0th light is CSM light in this path. We skip it and apply in the pixel shader using baked direct lighting intensity
  336. // stored in o.directionalLightingColor_flShadowDimScalar.a (from baked lighting data)
  337. if ( NUM_LIGHTS >= 2 )
  338. dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 1, g_bHalfLambert );
  339. if ( NUM_LIGHTS >= 3 )
  340. dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 2, g_bHalfLambert );
  341. if ( NUM_LIGHTS >= 4 )
  342. dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 3, g_bHalfLambert );
  343. o.directionalLightingColor_flShadowDimScalar.rgb = cLightInfo[0].color.rgb * staticLightColor.a;
  344. #endif
  345. o.color.rgb = staticLightColor.rgb + dynamicLighting.rgb;
  346. }
  347. #endif
  348. }
  349. #else
  350. {
  351. // Single vertex light stream. Typically dynamic props and static props in very old maps.
  352. staticLightColor = v.vStaticLight;
  353. // Note: PS3 treats the color as a 4-vector, big-endian RGBA (as in .rgba <=> .xyzw), hence we need to build the color channels in correct order for PS3 (see e.g. imesh.h)
  354. #if ( ( FLATTEN_STATIC_CONTROL_FLOW == 0 ) || defined ( SHADER_MODEL_VS_3_0 ) )
  355. {
  356. if ( bStaticLight )
  357. {
  358. o.color.xyz = DoLighting( worldPos, o.vWorldNormal_fogFactorW.xyz, staticLightColor.xyz, bStaticLight, bDynamicLight, g_bHalfLambert );
  359. }
  360. else
  361. {
  362. // dynamic lighting only => 0th dlight is the csm casting light
  363. o.color.xyz = DoLightingSeparateDirectional( worldPos, o.vWorldNormal_fogFactorW.xyz, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, vDirectLighting.rgb );
  364. #if ( DECAL==0 )
  365. o.directionalLightingColor_flShadowDimScalar.rgb = vDirectLighting.rgb;
  366. #endif
  367. }
  368. }
  369. #else
  370. {
  371. o.color.xyz = DoLightingUnrolled( worldPos, o.vWorldNormal_fogFactorW.xyz, staticLightColor.xyz, bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS );
  372. }
  373. #endif
  374. }
  375. #endif
  376. #if ( !FLASHLIGHT ) && ( defined( _GAMECONSOLE ) || defined ( SHADER_MODEL_VS_3_0 ) || ( CASCADED_SHADOW_MAPPING == 1 ) )
  377. {
  378. #if (DECAL)
  379. #if ( CSM_BLENDING == 1 )
  380. float flSunAmount = CosineTermInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 0, g_bHalfLambert ) * v.vStaticLight.w;
  381. o.directionalLightingColor_flShadowDimScalar.rgb *= v.vStaticLight.w;
  382. o.directionalLightingColor_flShadowDimScalar.a = flSunAmount;
  383. #else
  384. o.directionalLightingColor_flShadowDimScalar.a = 0.0;
  385. #endif
  386. #else
  387. if ( bStaticLight )
  388. {
  389. #if ( CSM_BLENDING == 1 )
  390. o.directionalLightingColor_flShadowDimScalar.a = staticLightColor.a;
  391. #else
  392. float flSunPercent = 1.0 - staticLightColor.a;
  393. float flSunAmount = flSunPercent * Luminance( GammaToLinear( staticLightColor.rgb * cOverbright ) );
  394. o.directionalLightingColor_flShadowDimScalar.a = flSunAmount;
  395. #endif
  396. }
  397. else
  398. {
  399. o.directionalLightingColor_flShadowDimScalar.a = 0.0;
  400. }
  401. #endif
  402. }
  403. #endif
  404. }
  405. #endif
  406. #if ( SEAMLESS_BASE )
  407. {
  408. o.baseTexCoord_baseTexCoord2u.xyz = SEAMLESS_SCALE * v.vPos.xyz;
  409. }
  410. #else
  411. {
  412. // Base texture coordinates
  413. o.baseTexCoord_baseTexCoord2u.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
  414. o.baseTexCoord_baseTexCoord2u.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
  415. }
  416. #endif
  417. #if ( SEAMLESS_DETAIL )
  418. {
  419. // FIXME: detail texcoord as a 2d xform doesn't make much sense here, so I just do enough so
  420. // that scale works. More smartness could allow 3d xform.
  421. o.detailTexCoord_baseTexCoord2v.xyz = (SEAMLESS_SCALE*cDetailTexCoordTransform[0].x) * v.vPos.xyz;
  422. }
  423. #else
  424. {
  425. #if ( TREE_SWAY )
  426. {
  427. o.detailTexCoord_baseTexCoord2v.xy = v.vTexCoord0;
  428. }
  429. #else
  430. {
  431. // Detail texture coordinates
  432. // FIXME: This shouldn't have to be computed all the time.
  433. o.detailTexCoord_baseTexCoord2v.x = dot( v.vTexCoord0, cDetailTexCoordTransform[0] );
  434. o.detailTexCoord_baseTexCoord2v.y = dot( v.vTexCoord0, cDetailTexCoordTransform[1] );
  435. }
  436. #endif
  437. }
  438. #endif
  439. #if ( SEPARATE_DETAIL_UVS )
  440. {
  441. o.detailTexCoord_baseTexCoord2v.xy = v.vTexCoord1.xy;
  442. }
  443. #else
  444. {
  445. // 2nd uv set, pass through for now
  446. o.baseTexCoord_baseTexCoord2u.w = v.vTexCoord1.x;
  447. o.detailTexCoord_baseTexCoord2v.w = v.vTexCoord1.y;
  448. }
  449. #endif
  450. }
  451. #endif // TESSELLATION
  452. #if ( !defined( _GAMECONSOLE ) && FLASHLIGHT )
  453. {
  454. //zero out the vertex color in additive two-pass flashlight mode
  455. o.color.rgb *= cSinglePassFlashlight.x;
  456. }
  457. #endif
  458. // Transform into projection space
  459. o.projPos = mul( float4( worldPos, 1 ), cViewProj );
  460. #ifdef _PS3
  461. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  462. o.projPos.y = -o.projPos.y;
  463. o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
  464. #endif // _PS3
  465. o.vProjPos = o.projPos;
  466. o.vWorldPos_csmXform0z.xyz = worldPos;
  467. #if ( LIGHTING_PREVIEW == 3 )
  468. {
  469. o.vProjPos.z = dot( g_vEyeVector, worldPos.xyz - cEyePos.xyz ); // Linear depth
  470. }
  471. #endif
  472. #if ( LIGHTING_PREVIEW )
  473. {
  474. float d = 0.2 + abs( dot( normalize(worldPos.xyz - cEyePos.xyz), o.vWorldNormal_fogFactorW.xyz ) );
  475. o.color.xyz = float3( d, d, d );
  476. }
  477. #endif
  478. #if ( FLASHLIGHT ) && defined( SHADER_MODEL_VS_3_0 )
  479. {
  480. o.flashlightSpacePos = TransformFlashlightWorldToTexture( worldPos, g_FlashlightWorldToTexture );
  481. }
  482. #endif
  483. #if ( HARDWAREFOGBLEND )
  484. {
  485. o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
  486. }
  487. #endif
  488. #if ( !DOPIXELFOG && !HARDWAREFOGBLEND )
  489. {
  490. o.vWorldNormal_fogFactorW.w = CalcNonFixedFunctionFog( worldPos, g_FogType );
  491. }
  492. #endif
  493. #if( CASCADED_SHADOW_MAPPING )
  494. {
  495. float4 worldPos = float4( o.vWorldPos_csmXform0z.xyz, 1.0f );
  496. o.csmXform0or1_csmXform2.xy = mul( worldPos, g_matWorldToShadowTexMatrices[0] ).xy;
  497. o.csmXform0or1_csmXform2.zw = mul( worldPos, g_matWorldToShadowTexMatrices[1] ).xy;
  498. o.vWorldPos_csmXform0z.w = mul( worldPos, g_matWorldToShadowTexMatrix0_z );
  499. }
  500. #endif
  501. return o;
  502. }