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.

208 lines
6.6 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. #define CSM_MODE_VERY_LOW_OR_LOW (0)
  3. #define CSM_MODE_MEDIUM (1)
  4. #define CSM_MODE_HIGH (2)
  5. #define CSM_MODE_ATI_FETCH4 (3)
  6. #if defined( SHADER_MODEL_PS_2_B ) && !defined( _GAMECONSOLE ) && !defined( _CONSOLE )
  7. // Register and interpolator usage, per shader
  8. #if defined( CSM_LIGHTMAPPEDGENERIC )
  9. // use 7 registers which we have, just. No interpolators free at all
  10. const float4 g_matWorldToShadowTexMatrices0z : register( c22 );
  11. const float4 g_matWorldToShadowTexMatrices1x : register( c23 );
  12. const float4 g_matWorldToShadowTexMatrices1y : register( c24 );
  13. const float4 g_matWorldToShadowTexMatrices2x : register( c25 );
  14. const float4 g_matWorldToShadowTexMatrices2y : register( c26 );
  15. const float4 g_vCamPosition : register( c27 );
  16. const float4 g_vCSMTexParams : register( c6 );
  17. #if ( PAINTREFRACT != 0 )
  18. #error PAINTREFRACT assumed to be 0 as register slots being used for csm's
  19. #endif
  20. #elif defined( CSM_VERTEXLIT_AND_UNLIT_GENERIC )
  21. const float4 g_vCamPosition : register( c8 );
  22. const float4 g_vCSMTexParams : register( c9 );
  23. #if ( OUTLINE != 0 )
  24. #error OUTLINE assumed to be 0 as register slots being used for csm's
  25. #endif
  26. #if ( SEAMLESS_BASE != 0 ) || ( SEAMLESS_DETAIL != 0 )
  27. #error SEAMLESS_BASE or SEAMLESS_DETAIL assumed to be 0 as register slots being used for csm's
  28. #endif
  29. // the following interpolators are used
  30. // baseTexCoord_csmXform1.zw : TEXCOORD0 - holds CSMTransformLightToTexture_1.xy
  31. // detailTexCoord_csmXform2.zw : TEXCOORD1 - holds CSMTransformLightToTexture_2.xy
  32. // worldSpaceNormal_csmXform0.w : TEXCOORD4 - holds CSMTransformLightToTexture_0.z
  33. #elif defined( CSM_VERTEXLIT_AND_UNLIT_GENERIC_BUMP )
  34. const float4 g_vCamPosition : register( c17 );
  35. const float4 g_vCSMTexParams : register( c18 );
  36. // the following interpolators are used
  37. // baseTexCoord2_light0e01_or_csmXform0or1.zw : TEXCOORD0 - holds CSMTransformLightToTexture_0or1.xy
  38. // lightAtten_csmXform2.zw : TEXCOORD2 - holds CSMTransformLightToTexture_2.xy
  39. // vWorldNormal_light2e1_or_csmXform0.w : TEXCOORD3 - holds CSMTransformLightToTexture_0.z
  40. #elif defined( CSM_PHONG )
  41. const float4 g_vCamPosition : register( c24 );
  42. const float4 g_vCSMTexParams : register( c25 );
  43. // the following interpolators are used
  44. // flTeamIdFade_csmXform0z_csmXform0or1xy.zw : TEXCOORD7 - holds CSMTransformLightToTexture_0or1.xy
  45. // lightAtten_csmXform2.zw : TEXCOORD1 - holds CSMTransformLightToTexture_2.xy
  46. // flTeamIdFade_csmXform0z_csmXform0or1xy.y : TEXCOORD3 - holds CSMTransformLightToTexture_0.z
  47. #elif defined( CSM_CHARACTER )
  48. const float4 g_vCamPosition : register( c26 );
  49. const float4 g_vCSMTexParams : register( c27 );
  50. // the following interpolators are used
  51. // csmXform0z_csmXform0or1xy.yz : TEXCOORD7 - holds CSMTransformLightToTexture_0or1.xy
  52. // vTexCoord0_csmXform2.zw : TEXCOORD0 - holds CSMTransformLightToTexture_2.xy
  53. // csmXform0z_csmXform0or1xy.x : TEXCOORD7 - holds CSMTransformLightToTexture_0.z
  54. #else
  55. #error No support for this shader and csm's when using ps_2_b on pc
  56. #endif
  57. // note this is a different param mapping from non ps_2_b csmtexparams
  58. #define g_flSunShadowingZLerpFactorBase g_vCSMTexParams.x
  59. #define g_flSunShadowingZLerpFactorRange g_vCSMTexParams.y
  60. #define g_flInvCascadeResolution g_vCSMTexParams.z
  61. #else
  62. const float4 g_vCSMLightColor : register( c64 );
  63. const float4 g_vCSMLightDir : register( c65 );
  64. const float4 g_vCSMTexParams : register( c66 );
  65. const float4 g_vCSMTexParams2 : register( c67 );
  66. const float4 g_vCSMTexParams3 : register( c68 );
  67. const float4x4 g_matWorldToShadowTexMatrices[4] : register( c69 );
  68. const float4 g_vCascadeAtlasUVOffsets[4] : register( c85 );
  69. const float4 g_vCamPosition : register( c89 );
  70. #define g_flSunShadowingInvShadowTextureWidth g_vCSMTexParams.x
  71. #define g_flSunShadowingInvShadowTextureHeight g_vCSMTexParams.y
  72. #define g_flSunShadowingHalfInvShadowTextureWidth g_vCSMTexParams.z
  73. #define g_flSunShadowingHalfInvShadowTextureHeight g_vCSMTexParams.w
  74. #define g_flSunShadowingShadowTextureWidth g_vCSMTexParams2.x
  75. #define g_flSunShadowingShadowTextureHeight g_vCSMTexParams2.y
  76. #define g_flSunShadowingSplitLerpFactorBase g_vCSMTexParams2.z
  77. #define g_flSunShadowingSplitLerpFactorInvRange g_vCSMTexParams2.w
  78. #define g_flSunShadowingZLerpFactorBase g_vCSMTexParams3.x
  79. #define g_flSunShadowingZLerpFactorRange g_vCSMTexParams3.y
  80. #endif
  81. float3 CSMVisualizePosition( float3 vPositionWs )
  82. {
  83. float3 cColor = float3( 0, 0, 1 );
  84. int ix = vPositionWs.x / 8.0f;
  85. int iy = vPositionWs.y / 8.0f;
  86. if ( frac( iy / 2.0f ) )
  87. {
  88. if ( frac( ix / 2.0f ) )
  89. {
  90. cColor = float3( 1.0f, 0.0f, 0.0f );
  91. }
  92. else
  93. {
  94. cColor = float3( 0.0f, 1.0f, 0.0f );
  95. }
  96. }
  97. else
  98. {
  99. if ( frac( ix / 2.0f ) )
  100. {
  101. cColor = float3( 0.0f, 1.0f, 0.0f );
  102. }
  103. else
  104. {
  105. cColor = float3( 1.0f, 0.0f, 0.0f );
  106. }
  107. }
  108. return cColor;
  109. }
  110. float3 CSMVisualizeSplit( float3 vPositionWs )
  111. {
  112. #if defined( SHADER_MODEL_PS_2_B )
  113. return float3( 1, 0, 0 );
  114. #else
  115. float4 vPosition4Ws = float4( vPositionWs.xyz, 1.0f );
  116. float3 vPositionToSampleLs = float3( 0.0f, 0.0f, 0.0f );
  117. int nCascadeIndex = 0;
  118. vPositionToSampleLs.xy = mul( vPosition4Ws.xyzw, g_matWorldToShadowTexMatrices[0] ).xy;
  119. #if ( CASCADE_SIZE > 1 )
  120. if ( dot( saturate( vPositionToSampleLs.xy ) - vPositionToSampleLs.xy, float2( 1, 1 ) ) != 0.0f )
  121. {
  122. nCascadeIndex = 1;
  123. vPositionToSampleLs.xy = mul( vPosition4Ws.xyzw, g_matWorldToShadowTexMatrices[1] ).xy;
  124. #if ( CASCADE_SIZE > 2 )
  125. if ( dot( saturate( vPositionToSampleLs.xy ) - vPositionToSampleLs.xy, float2( 1, 1 ) ) != 0.0f )
  126. {
  127. nCascadeIndex = 2;
  128. vPositionToSampleLs.xy = mul( vPosition4Ws.xyzw, g_matWorldToShadowTexMatrices[2] ).xy;
  129. #if ( CASCADE_SIZE > 3 )
  130. if ( dot( saturate( vPositionToSampleLs.xy ) - vPositionToSampleLs.xy, float2( 1, 1 ) ) != 0.0f )
  131. {
  132. nCascadeIndex = 3;
  133. vPositionToSampleLs.xy = mul( vPosition4Ws.xyzw, g_matWorldToShadowTexMatrices[3] ).xy;
  134. }
  135. #endif
  136. }
  137. #endif
  138. }
  139. #endif
  140. float3 cColor = float3( 1, 0, 1 );
  141. if ( dot( saturate( vPositionToSampleLs.xy ) - vPositionToSampleLs.xy, float2( 1, 1 ) ) == 0.0f )
  142. {
  143. if ( nCascadeIndex == 0 )
  144. cColor = float3( 0, 1, 0 );
  145. else if ( nCascadeIndex == 1 )
  146. cColor = float3( 0, 0, 1 );
  147. else if ( nCascadeIndex == 2 )
  148. cColor = float3( 0, 1, 1 );
  149. else
  150. cColor = float3( 1, 0, 0 );
  151. }
  152. return cColor;
  153. #endif
  154. }
  155. #if defined( _GAMECONSOLE ) || defined(_CONSOLE)
  156. #include "csm_common_gameconsole_fxc.h"
  157. #elif defined( SHADER_MODEL_PS_2_B )
  158. #include "csm_common_pc_ps2b_fxc.h"
  159. #else
  160. #include "csm_common_pc_fxc.h"
  161. #endif