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.

368 lines
10 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "DUALSEQUENCE" "0..1"
  3. // STATIC: "SEQUENCE_BLEND_MODE" "0..2"
  4. // STATIC: "ADDBASETEXTURE2" "0..1"
  5. // STATIC: "MAXLUMFRAMEBLEND1" "0..1"
  6. // STATIC: "MAXLUMFRAMEBLEND2" "0..1"
  7. // STATIC: "EXTRACTGREENALPHA" "0..1"
  8. // STATIC: "COLORRAMP" "0..1"
  9. // STATIC: "ANIMBLEND" "0..1"
  10. // STATIC: "ADDSELF" "0..1"
  11. // STATIC: "MOD2X" "0..1"
  12. // STATIC: "DEPTHBLEND" "0..1" [CONSOLE]
  13. // STATIC: "DEPTHBLEND" "0..1" [PC]
  14. // STATIC: "INVERSEDEPTHBLEND" "0..1" [CONSOLE]
  15. // STATIC: "INVERSEDEPTHBLEND" "0..0" [PC]
  16. // STATIC: "SHADER_SRGB_READ" "0..1" [XBOX]
  17. // STATIC: "SHADER_SRGB_READ" "0..0" [PC]
  18. // STATIC: "SHADER_SRGB_READ" "0..0" [SONYPS3]
  19. // STATIC: "COLOR_LERP_PS" "0..1"
  20. // STATIC: "PACKED_INTERPOLATOR" "0..1"
  21. // STATIC: "DISTANCEALPHA" "0..1"
  22. // STATIC: "SOFTEDGES" "0..1"
  23. // STATIC: "OUTLINE" "0..1"
  24. // STATIC: "MULOUTPUTBYALPHA" "0..1"
  25. // SKIP: ( $DISTANCEALPHA == 0 ) && ( $SOFTEDGES || $OUTLINE )
  26. // SKIP: $DISTANCEALPHA && $DUALSEQUENCE
  27. // SKIP: $DISTANCEALPHA && ( $MAXLUMFRAMEBLEND2 || $MAXLUMFRAMEBLEND1 )
  28. // SKIP: ( $DUALSEQUENCE == 0 ) && ( $SEQUENCE_BLEND_MODE != 0 )
  29. // SKIP: $INVERSEDEPTHBLEND && !$DEPTHBLEND [CONSOLE]
  30. // These are mutually exclusive because PACKED_INTERPOLATOR only fetches a single texture tile
  31. // SKIP: $PACKED_INTERPOLATOR && ( $ANIMBLEND || $MAXLUMFRAMEBLEND1 || $EXTRACTGREENALPHA || $DUALSEQUENCE )
  32. #define COMBINE_MODE_AVERAGE 0
  33. #define COMBINE_MODE_USE_FIRST_AS_ALPHA_MASK_ON_SECOND 1
  34. #define COMBINE_MODE_USE_FIRST_OVER_SECOND 2
  35. #define HDRTYPE HDR_TYPE_NONE
  36. #include "common_ps_fxc.h"
  37. HALF4 g_Parameters : register( c0 );
  38. #define fAdditiveBlendWeight g_Parameters.x
  39. #define fOverbrightFactor g_Parameters.y
  40. #define fAdditiveSelfBlendWeight g_Parameters.z
  41. #define fIntensity g_Parameters.w
  42. float g_flMod2xIdentity : register( c1 );
  43. float4 g_DepthFeatheringConstants : register( c2 );
  44. float4 g_FogParams : register( c3 );
  45. float3 g_EyePos : register( c4 );
  46. HALF3 g_vColor0 : register( c5 );
  47. HALF3 g_vColor1 : register( c6 );
  48. // VS_OUTPUT in a common file.
  49. #define PIXELSHADER
  50. #include "common_spritecard_fxc.h"
  51. sampler BaseTextureSampler : register( s0 );
  52. sampler ColorRampSampler : register( s1 );
  53. sampler DepthSampler : register( s2 );
  54. #if DISTANCEALPHA == 0
  55. #define EDGESOFTNESS_START 0.5h
  56. #define EDGESOFTNESS_END 0.425h
  57. #define OUTLINECOLOR HALF4( 0, 1, 0, 1 )
  58. #define OUTLINESTART0 0.2h
  59. #define OUTLINESTART1 0.3h
  60. #define OUTLINEEND0 0.49h
  61. #define OUTLINEEND1 0.6h
  62. #else
  63. HALF4 g_vecOutlineColor : register( c7 );
  64. #define OUTLINECOLOR (HALF4)( g_vecOutlineColor * i.vecOutlineTint )
  65. HALF4 g_vecOutlineControl : register( c8 );
  66. #define OUTLINESTART0 ( g_vecOutlineControl.x )
  67. #define OUTLINESTART1 ( g_vecOutlineControl.y )
  68. #define OUTLINEEND0 ( g_vecOutlineControl.z )
  69. #define OUTLINEEND1 ( g_vecOutlineControl.w )
  70. HALF4 g_vecEdgeControl : register( c9 );
  71. #define EDGESOFTNESS_START ( g_vecEdgeControl.x )
  72. #define EDGESOFTNESS_END ( g_vecEdgeControl.y )
  73. #endif
  74. HALF DepthFeatheringFullDepth( sampler DepthSampler, const float4 vProjPos, float4 vDepthBlendConstants )
  75. {
  76. # if ( !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) ) //minimum requirement of ps2b
  77. {
  78. float2 vProjPosDivW = vProjPos.xy / vProjPos.w;
  79. float2 vScreenPos = vProjPosDivW * g_vDepthFeatherViewportMad.xy + g_vDepthFeatherViewportMad.zw;
  80. float flFeatheredAlpha;
  81. // Sample the scene's depth at the current fragment.
  82. float flSceneProjZ = tex2D( DepthSampler, vScreenPos ).r;
  83. float4 vSceneProjPos = float4( vProjPosDivW.x, vProjPosDivW.y, flSceneProjZ, 1.0f );
  84. float flSceneViewZ = dot( vSceneProjPos, g_vDepthFeatherProjToViewZW[0] );
  85. float flSceneViewW = dot( vSceneProjPos, g_vDepthFeatherProjToViewZW[1] );
  86. flSceneViewZ /= flSceneViewW;
  87. // fragment's viewspace Z from its projection space coord. computed in VS
  88. float flSurfViewZ = vProjPos.z;
  89. flFeatheredAlpha = flSurfViewZ - flSceneViewZ;
  90. flFeatheredAlpha = saturate( saturate( vDepthBlendConstants.z * flFeatheredAlpha ) + vDepthBlendConstants.w );
  91. return flFeatheredAlpha;
  92. }
  93. # else
  94. {
  95. return 1.0;
  96. }
  97. # endif
  98. }
  99. float4_color_return_type main( PS_INPUT i ) : COLOR
  100. {
  101. // Sample frames from textures
  102. HALF4 baseTex0 = h4tex2Dsrgb( BaseTextureSampler, i.texCoord0_1.xy );
  103. HALF4 baseTex1;
  104. HALF4 result = baseTex0;
  105. HALF4 vVertexColor;
  106. #if ( PACKED_INTERPOLATOR )
  107. {
  108. vVertexColor.rgba = i.texCoord0_1.zzzw;
  109. }
  110. #else
  111. {
  112. vVertexColor.rgba = i.argbcolor.rgba;
  113. baseTex1 = h4tex2Dsrgb( BaseTextureSampler, i.texCoord0_1.wz );
  114. }
  115. #endif
  116. #if ( COLOR_LERP_PS )
  117. {
  118. vVertexColor.rgb = lerp( g_vColor0.rgb, g_vColor1.rgb, saturate( vVertexColor.r ) );
  119. }
  120. #endif
  121. // Blend by default (may override with bMaxLumFrameBlend1 or bExtractGreenAlpha)
  122. #if ( ANIMBLEND )
  123. result = lerp( result, baseTex1, (HALF)i.blendfactor0.x );
  124. #endif
  125. #if ( MAXLUMFRAMEBLEND1 )
  126. {
  127. // Blend between animation frames based upon max luminance
  128. HALF lum0 = dot( HALF3(.3, .59, .11), baseTex0.rgb * (1.0h-(HALF)i.blendfactor0.x));
  129. HALF lum1 = dot( HALF3(.3, .59, .11), baseTex1.rgb * (HALF)i.blendfactor0.x);
  130. if ( lum0 > lum1 )
  131. result = baseTex0;
  132. else
  133. result = baseTex1;
  134. }
  135. #elif( EXTRACTGREENALPHA )
  136. {
  137. // Weight Green/Alphas from the two frames for a scalar result
  138. result = dot( baseTex0, (HALF4)i.blendfactor0 ) + dot( baseTex1, (HALF4)i.blendfactor1 );
  139. }
  140. #endif
  141. if ( DISTANCEALPHA )
  142. {
  143. HALF flOrigAlpha = result.a;
  144. if ( SOFTEDGES )
  145. {
  146. result.a = smoothstep( EDGESOFTNESS_END, EDGESOFTNESS_START, result.a );
  147. }
  148. else
  149. {
  150. if ( result.a < 0.5h )
  151. result = 0;
  152. }
  153. if ( OUTLINE )
  154. {
  155. result.rgb *= vVertexColor.rgb; // multiply by vertex color before glow.
  156. if ( ( flOrigAlpha >= OUTLINESTART0 ) && ( flOrigAlpha <= OUTLINEEND1 ) )
  157. {
  158. float oFactor = 1.0f;
  159. if ( flOrigAlpha <= OUTLINESTART1 )
  160. {
  161. oFactor = smoothstep( OUTLINESTART0, OUTLINESTART1, flOrigAlpha );
  162. }
  163. else
  164. {
  165. oFactor = smoothstep( OUTLINEEND1, OUTLINEEND0, flOrigAlpha );
  166. }
  167. result = lerp( result, OUTLINECOLOR, oFactor );
  168. }
  169. }
  170. }
  171. #if ( DUALSEQUENCE )
  172. {
  173. baseTex0 = h4tex2Dsrgb( BaseTextureSampler, i.vSeq2TexCoord0_1.xy );
  174. baseTex1 = h4tex2Dsrgb( BaseTextureSampler, i.vSeq2TexCoord0_1.wz );
  175. // Blend by default (may override with bMaxLumFrameBlend2)
  176. HALF4 rgb2 = lerp( baseTex0, baseTex1, (HALF)i.blendfactor0.z );
  177. #if ( MAXLUMFRAMEBLEND2 )
  178. {
  179. // blend between animation frames based upon max luminance
  180. HALF tlum0 = dot( HALF3(.3, .59, .11), baseTex0.rgb * (1.0h-(HALF)i.blendfactor0.x));
  181. HALF tlum1 = dot( HALF3(.3, .59, .11), baseTex1.rgb * (HALF)i.blendfactor0.x);
  182. if ( tlum0 > tlum1 )
  183. rgb2 = baseTex0;
  184. else
  185. rgb2 = baseTex1;
  186. }
  187. #endif
  188. #if ( SEQUENCE_BLEND_MODE == COMBINE_MODE_AVERAGE )
  189. {
  190. result = 0.5h * ( result + rgb2 );
  191. }
  192. #elif ( SEQUENCE_BLEND_MODE == COMBINE_MODE_USE_FIRST_AS_ALPHA_MASK_ON_SECOND )
  193. {
  194. result.rgb = rgb2.rgb;
  195. }
  196. #elif ( SEQUENCE_BLEND_MODE == COMBINE_MODE_USE_FIRST_OVER_SECOND )
  197. {
  198. result.rgb = lerp( result.rgb, rgb2.rgb, rgb2.a );
  199. }
  200. #endif
  201. }
  202. #endif
  203. // Optional color ramp
  204. #if ( COLORRAMP )
  205. {
  206. result.rgb = h3tex2Dsrgb( ColorRampSampler, float2( result.r, result.g ) ).rgb;
  207. }
  208. #endif
  209. // Overbright
  210. result.rgb *= fOverbrightFactor;
  211. //Soft Particles FTW
  212. #if (DEPTHBLEND == 1)
  213. HALF fDepthBlend = DepthFeatheringFullDepth( DepthSampler, i.vProjPos, g_DepthFeatheringConstants );
  214. #if (INVERSEDEPTHBLEND == 1)
  215. fDepthBlend = 1.0h - fDepthBlend;
  216. #endif
  217. vVertexColor.a *= fDepthBlend;
  218. #endif
  219. // Premultiply the alpha for a ONE:INVALPHA blend
  220. #if ( ADDBASETEXTURE2 )
  221. {
  222. result.a *= vVertexColor.a;
  223. // In this case, we don't really want to pre-multiply by alpha
  224. #if ( !COLORRAMP )
  225. {
  226. result.rgb *= result.a;
  227. }
  228. #endif
  229. #if ( EXTRACTGREENALPHA )
  230. {
  231. result.rgb += fAdditiveBlendWeight * vVertexColor.a * result.rgb;
  232. }
  233. #else
  234. {
  235. result.rgb += fOverbrightFactor * fAdditiveBlendWeight * vVertexColor.a * h3tex2Dsrgb( BaseTextureSampler, i.texCoord2 ).rgb;
  236. }
  237. #endif
  238. result.rgb *= vVertexColor.rgb;
  239. }
  240. #else
  241. {
  242. #if ADDSELF
  243. {
  244. result.a *= vVertexColor.a;
  245. result.rgb *= result.a;
  246. result.rgb += fAdditiveSelfBlendWeight * result.rgb;
  247. result.rgb *= vVertexColor.rgb;
  248. }
  249. #else
  250. {
  251. #if ( MOD2X )
  252. {
  253. result.rgb = lerp( (HALF3)g_flMod2xIdentity, result.rgb, vVertexColor.rgb );
  254. result.a *= vVertexColor.a;
  255. }
  256. #else
  257. {
  258. if ( ! OUTLINE )
  259. {
  260. result *= vVertexColor; // if outlined, we've already done this. don't want to mul glow by particle color.
  261. }
  262. else
  263. {
  264. result.a *= vVertexColor.a;
  265. }
  266. }
  267. #endif
  268. }
  269. #endif
  270. }
  271. #endif
  272. float4_color_return_type vOutput;
  273. #if ( MOD2X )
  274. {
  275. // Blend towards a unity multiply as alpha gets closer to zero
  276. result.rgb = lerp( ( HALF3 )g_flMod2xIdentity, result.rgb, result.a );
  277. // Don't tonemap scale since we are multiplying by what is already in the framebuffer.
  278. vOutput = FinalOutputHalf( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  279. }
  280. #else
  281. {
  282. vOutput = FinalOutputHalf( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR );
  283. #if defined( _X360 ) && defined( CSTRIKE15 )
  284. // TEMPORARY - fix up properly after PAX
  285. // undo the linear to gamma that would have been done in FinalOutput as we have other colour ops to perform
  286. vOutput.rgb = GammaToLinear( vOutput.rgb );
  287. #endif
  288. }
  289. #endif
  290. vOutput = saturate( vOutput );
  291. // Purposely multiplying after saturating.
  292. vOutput.rgb *= fIntensity;
  293. #if ( MULOUTPUTBYALPHA )
  294. {
  295. // Do the final alpha multiply in the shader to avoid alpha blender unit precision problems. (This should only be enabled when we would normally
  296. // do SRC_RGB*SRC_ALPHA+DST_RGB blending.)
  297. vOutput.rgb *= vOutput.a;
  298. vOutput.a = 1.0h;
  299. }
  300. #endif
  301. #if ( MOD2X )
  302. {
  303. }
  304. #else
  305. {
  306. #if defined( _X360 ) && defined( CSTRIKE15 )
  307. // [mariod] - srgb write required in this shader - after FinalOutput due to other ops - Final output will skip since TONEMAP_SCALE is NONE
  308. vOutput.rgb = LinearToGamma( vOutput.rgb );
  309. //vOutput.rgb = SrgbLinearToGamma( vOutput.rgb );
  310. #endif
  311. }
  312. #endif
  313. return vOutput;
  314. }