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.

69 lines
2.0 KiB

  1. //====== Copyright � 1996-2007, Valve Corporation, All rights reserved. ===========================
  2. #ifdef HDRTYPE
  3. #undef HDRTYPE
  4. #endif
  5. #define HDRTYPE HDR_TYPE_NONE
  6. // Includes =======================================================================================
  7. #include "common_ps_fxc.h"
  8. // Texture Samplers ===============================================================================
  9. sampler g_tFullScreenColor : register( s0 );
  10. sampler g_tFullScreenVelocity : register( s1 );
  11. // Shaders Constants and Globals ==================================================================
  12. // Interpolated values ============================================================================
  13. struct PS_INPUT
  14. {
  15. float2 vUv0 : TEXCOORD0;
  16. };
  17. // Main ===========================================================================================
  18. float4 main( PS_INPUT i ) : COLOR
  19. {
  20. float4 vVelocity = tex2D( g_tFullScreenVelocity, i.vUv0.xy );
  21. vVelocity.xy = vVelocity.xy * 256.0f / 255.0f * 2.0f - float2( 1.0f, 1.0f );
  22. #define NUM_SAMPLES 10
  23. #define STEP_SIZE 0.002
  24. #define OLD_METHOD 0
  25. #if OLD_METHOD
  26. float4 cBlurColor = float4( 0, 0, 0, 0 );
  27. for ( int x = 0; x < NUM_SAMPLES; x ++ )
  28. {
  29. // Calculate offset uv
  30. float2 vUvTmp = i.vUv0.xy - ( vVelocity.xy * x * STEP_SIZE );
  31. cBlurColor += (1.0f / NUM_SAMPLES ) * tex2D( g_tFullScreenColor, vUvTmp.xy );
  32. }
  33. return float4( cBlurColor.rgb, 1.0f );
  34. #else
  35. float4 cBaseColor = tex2D( g_tFullScreenColor, i.vUv0.xy );
  36. float4 cBlurColor = float4( 0, 0, 0, 0 );
  37. float flTotalBlurWeight = 0.0f;
  38. // @TODO: unroll loop on X360?
  39. for ( int x = 1; x < NUM_SAMPLES; x ++ )
  40. {
  41. // Calculate offset uv
  42. float2 vUvTmp = i.vUv0.xy + ( vVelocity.xy * x * STEP_SIZE );
  43. float4 vOffsetVelocity = tex2D( g_tFullScreenVelocity, vUvTmp );
  44. flTotalBlurWeight += vOffsetVelocity.b;
  45. cBlurColor += vOffsetVelocity.b * tex2D( g_tFullScreenColor, vUvTmp.xy );
  46. }
  47. float4 cFinalColor = ( cBlurColor + ( NUM_SAMPLES - flTotalBlurWeight ) * cBaseColor ) / NUM_SAMPLES;
  48. return float4( cFinalColor.rgb, 1.0f );
  49. #endif
  50. }