Advertisement
ShoterXX

Blur.fx

Nov 19th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1.  
  2. namespace ShoterXX
  3. {
  4.  
  5. static const uint2 vertexID = uint2(2,1);
  6.  
  7. #define fetchAt(COORDS) tex2Dlod(ReShade::BackBuffer, float4(COORDS, 0, 0))
  8.  
  9. #define CreateLQTextureLOD(NAME, x, y, lod)\
  10. \
  11. texture2D NAME##Tex\
  12. {\
  13. Width = ##x;\
  14. Height = ##y;\
  15. Format = RGBA8;\
  16. MipLevels = lod;\
  17. };\
  18. \
  19. sampler2D NAME\
  20. {\
  21. Texture = NAME##Tex;\
  22. };
  23.  
  24. #define DoBlurPassOdd(i) \
  25. pass \
  26. { \
  27. VertexShader = ShoterXX::VS_PI_BLUR##i; \
  28. PixelShader = ShoterXX::PS_PI_BlurPush##i; \
  29. RenderTarget = ShoterXX::PI_Blur2Tex; \
  30. }
  31.  
  32. #define DoBlurPassEven(i) \
  33. pass \
  34. { \
  35. VertexShader = ShoterXX::VS_PI_BLUR##i; \
  36. PixelShader = ShoterXX::PS_PI_BlurPull##i; \
  37. RenderTarget = ShoterXX::PI_BlurTex; \
  38. }
  39.  
  40. #define CreateBlurVertex(i)\
  41. \
  42. void VS_PI_BLUR##i(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 xy : TEXCOORD, out float4x4 fetchMatrix : TEXCOORD1)\
  43. {\
  44. xy = (id == vertexID) ? 2.0 : 0.0;\
  45. position = float4(xy * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1);\
  46. \
  47. float2 pixOffset = ReShade::PixelSize * (i*i + 0.5) * ppB.y;\
  48. \
  49. pixOffset.y *= ((ppB.x + i) % 2) ? -1 : 1;\
  50. \
  51. fetchMatrix._11_12_13_14 = float4(xy, 0, 0);\
  52. fetchMatrix._21_22_23_24 = float4(xy + float2( 0.00000000000, 1.0) * pixOffset, 0, 2);\
  53. fetchMatrix._31_32_33_34 = float4(xy + float2( 0.86602540378, 0.5) * pixOffset, 0, 2);\
  54. fetchMatrix._41_42_43_44 = float4(xy + float2(-0.86602540378, 0.5) * pixOffset, 0, 2);\
  55. }
  56.  
  57. #define CreateBlurPassOdd(i)\
  58. \
  59. CreateBlurVertex(i)\
  60. \
  61. void PS_PI_BlurPush##i(in float4 vpos : SV_Position, in float2 xy : TEXCOORD, in float4x4 fetchMatrix : TEXCOORD1, out float4 put : SV_Target0)\
  62. {\
  63. DoBlur(i, PI_Blur, xy, put, fetchMatrix);\
  64. }
  65.  
  66. #define CreateBlurPassEven(i)\
  67. \
  68. CreateBlurVertex(i)\
  69. \
  70. void PS_PI_BlurPull##i(in float4 vpos : SV_Position, in float2 xy : TEXCOORD, in float4x4 fetchMatrix : TEXCOORD1, out float4 put : SV_Target0)\
  71. {\
  72. DoBlur(i, PI_Blur2, xy, put, fetchMatrix);\
  73. }
  74.  
  75.  
  76.  
  77. CreateLQTextureLOD(PI_Blur , BUFFER_WIDTH/1.999, BUFFER_HEIGHT/2.002, 3);
  78. CreateLQTextureLOD(PI_Blur2, BUFFER_WIDTH/2.001, BUFFER_HEIGHT/1.998, 3);
  79.  
  80.  
  81.  
  82. uniform float2 ppB < source = "pingpong"; min = 0; max = 1; step = 100; >;
  83.  
  84. void DoBlur(in int i, in sampler2D tex, in float2 xy, out float4 put, in float4x4 fetchMatrix)
  85. {
  86. int j;
  87.  
  88. [unroll]
  89. for(j = 0; j<4; j++)
  90. fetchMatrix[j] = tex2Dlod(tex, fetchMatrix[j]);
  91.  
  92. fetchMatrix._14 = 1 - dot(fetchMatrix._24_34_44 = saturate(1 - abs((put.w = fetchMatrix._14) - fetchMatrix._24_34_44) * 64)/3, 1);
  93.  
  94. [unroll]
  95. for(j = 0; j<4; j++)
  96. fetchMatrix[j].rgb = pow(fetchMatrix[j].rgb, 8) * fetchMatrix[j].a;
  97.  
  98. put.rgb = pow((fetchMatrix._11_12_13 + fetchMatrix._21_22_23) + (fetchMatrix._31_32_33 + fetchMatrix._41_42_43), rcp(8));
  99. }
  100.  
  101. void DoBlurNP(in int i, in sampler2D tex, in float2 xy, out float4 put, in float4x4 fetchMatrix)
  102. {
  103. int j;
  104.  
  105. [unroll]
  106. for(j = 0; j<4; j++)
  107. fetchMatrix[j] = tex2Dlod(tex, fetchMatrix[j]);
  108.  
  109. fetchMatrix._14 = 1 - dot(fetchMatrix._24_34_44 = saturate(1 - abs((put.w = fetchMatrix._14) - fetchMatrix._24_34_44) * 64)/3, 1);
  110.  
  111. [unroll]
  112. for(j = 0; j<4; j++)
  113. fetchMatrix[j].rgb = pow(fetchMatrix[j].rgb, 8) * fetchMatrix[j].a;
  114.  
  115. put.rgb = (fetchMatrix._11_12_13 + fetchMatrix._21_22_23) + (fetchMatrix._31_32_33 + fetchMatrix._41_42_43);
  116. }
  117.  
  118. void PS_PI_BlurGet(in float4 vpos : SV_Position, in float2 xy : TEXCOORD, in float4x4 fetchMatrix : TEXCOORD1, out float4 put : SV_Target0)
  119. {
  120. float4 curP;
  121.  
  122. DoBlurNP(6, PI_Blur, xy, curP, fetchMatrix);
  123.  
  124. float2 pixOffset = xy + ReShade::PixelSize * 0.5;
  125.  
  126. put = fetchAt(pixOffset);
  127.  
  128. put = pow(curP * 0.750 + put * put * 0.250, rcp(8));
  129.  
  130. put.a = ReShade::GetLinearizedDepth(pixOffset);
  131. }
  132.  
  133. CreateBlurPassOdd(0)
  134. CreateBlurPassEven(1)
  135. CreateBlurPassOdd(2)
  136. CreateBlurPassEven(3)
  137. CreateBlurPassOdd(4)
  138. CreateBlurPassEven(5)
  139. CreateBlurPassOdd(6)
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement