blur1_ps.fx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //texture PrevFrameImage;
  2. //sampler2D sampler_main = sampler_state { Texture = <PrevFrameImage>; };
  3. //float4 _c0; // source texsize (.xy), and inverse (.zw)
  4. //float4 _c1; // w1..w4
  5. //float4 _c2; // d1..d4
  6. //float4 _c3; // scale, bias, w_div
  7. void PS( float2 uv : TEXCOORD,
  8. out float4 ret : COLOR0 )
  9. {
  10. // LONG HORIZ. PASS 1:
  11. //const float w[8] = { 4.0, 3.8, 3.5, 2.9, 1.9, 1.2, 0.7, 0.3 }; <- user can specify these
  12. //const float w1 = w[0] + w[1];
  13. //const float w2 = w[2] + w[3];
  14. //const float w3 = w[4] + w[5];
  15. //const float w4 = w[6] + w[7];
  16. //const float d1 = 0 + 2*w[1]/w1;
  17. //const float d2 = 2 + 2*w[3]/w2;
  18. //const float d3 = 4 + 2*w[5]/w3;
  19. //const float d4 = 6 + 2*w[7]/w4;
  20. //const float w_div = 0.5/(w1+w2+w3+w4);
  21. #define srctexsize _c0
  22. #define w1 _c1.x
  23. #define w2 _c1.y
  24. #define w3 _c1.z
  25. #define w4 _c1.w
  26. #define d1 _c2.x
  27. #define d2 _c2.y
  28. #define d3 _c2.z
  29. #define d4 _c2.w
  30. #define fscale _c3.x
  31. #define fbias _c3.y
  32. #define w_div _c3.z
  33. // note: if you just take one sample at exactly uv.xy, you get an avg of 4 pixels.
  34. //float2 uv2 = uv.xy;// + srctexsize.zw*float2(0.5,0.5);
  35. float2 uv2 = uv.xy + srctexsize.zw*float2(1,1); // + moves blur UP, LEFT by 1-pixel increments
  36. float3 blur =
  37. ( tex2D( sampler_main, uv2 + float2( d1*srctexsize.z,0) ).xyz
  38. + tex2D( sampler_main, uv2 + float2(-d1*srctexsize.z,0) ).xyz)*w1 +
  39. ( tex2D( sampler_main, uv2 + float2( d2*srctexsize.z,0) ).xyz
  40. + tex2D( sampler_main, uv2 + float2(-d2*srctexsize.z,0) ).xyz)*w2 +
  41. ( tex2D( sampler_main, uv2 + float2( d3*srctexsize.z,0) ).xyz
  42. + tex2D( sampler_main, uv2 + float2(-d3*srctexsize.z,0) ).xyz)*w3 +
  43. ( tex2D( sampler_main, uv2 + float2( d4*srctexsize.z,0) ).xyz
  44. + tex2D( sampler_main, uv2 + float2(-d4*srctexsize.z,0) ).xyz)*w4
  45. ;
  46. blur.xyz *= w_div;
  47. blur.xyz = blur.xyz*fscale + fbias;
  48. ret.xyz = blur;
  49. ret.w = 1;
  50. //ret.xyzw = tex2D(sampler_main, uv + 0*srctexsize.zw);
  51. }