Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. /*
  2. Coded by Prod80
  3. Ported to ReShade 3.x by Insomnia
  4. Version 1.4
  5. */
  6.  
  7. #include "ReShade.fxh"
  8.  
  9. uniform int iUsehslfilter <
  10. ui_type = "combo";
  11. ui_label = "Use HSL Filter";
  12. ui_items = "No\0Yes\0";
  13. > = 0;
  14.  
  15. uniform float3 ccFilterLuma <
  16. ui_type = "color";
  17. ui_min = 0.0; ui_max = 1.0;
  18. ui_label = "Luma Coefficient";
  19. ui_tooltip = "Only for advanced users";
  20. > = float3(0.2125, 0.7154, 0.0721);
  21.  
  22. uniform int hueMid <
  23. ui_type = "drag";
  24. ui_min = 0.0; ui_max = 360.0;
  25. ui_label = "Hue Mid";
  26. ui_tooltip = "Hue (rotation around the color wheel) of the color which you want to keep";
  27. > = 0;
  28. uniform float hueRange <
  29. ui_type = "drag";
  30. ui_min = 0.0; ui_max = 0.9;
  31. ui_label = "Hue Range";
  32. ui_tooltip = "Range of different hue's around the hueMid that will also kept";
  33. > = 0.2;
  34. uniform float satLimit <
  35. ui_type = "drag";
  36. ui_min = 0.1; ui_max = 1.0;
  37. ui_label = "Saturation Limit";
  38. ui_tooltip = "Saturation control, better keep it higher than 0 for strong colors in contrast to the gray stuff around";
  39. > = 1.0;
  40. uniform float fxcolorMix <
  41. ui_type = "drag";
  42. ui_min = 0.0; ui_max = 1.0;
  43. ui_label = "Color Mix";
  44. ui_tooltip = "Interpolation between the original and the effect, 0 means full original image, 1 means full grey-color image";
  45. > = 1.0;
  46.  
  47.  
  48. //#define Use_COLORSAT 0 //[0:1] //-This will use original color saturation as an added limiter to the strength of the effect
  49.  
  50.  
  51.  
  52. //#define LumCoeff float3(0.212656, 0.715158, 0.072186)
  53. float smootherstep(float edge0, float edge1, float x)
  54. {
  55. x = clamp((x - edge0)/(edge1 - edge0), 0.0, 1.0);
  56. return x*x*x*(x*(x*6 - 15) + 10);
  57. }
  58.  
  59. float3 Hue(in float3 RGB)
  60. {
  61. // Based on work by Sam Hocevar and Emil Persson
  62. float Epsilon = 1e-10;
  63. float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0/3.0) : float4(RGB.gb, 0.0, -1.0/3.0);
  64. float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx);
  65. float C = Q.x - min(Q.w, Q.y);
  66. float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
  67. return float3(H, C, Q.x);
  68. }
  69.  
  70. float3 HUEToRGB(in float H)
  71. {
  72. float R = abs(H * 6 - 3) - 1;
  73. float G = 2 - abs(H * 6 - 2);
  74. float B = 2 - abs(H * 6 - 4);
  75. return saturate(float3(R,G,B));
  76. }
  77.  
  78. static const float Epsilon = 1e-10;
  79.  
  80. float3 RGBToHCV(in float3 RGB)
  81. {
  82. // Based on work by Sam Hocevar and Emil Persson
  83. float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0/3.0) : float4(RGB.gb, 0.0, -1.0/3.0);
  84. float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx);
  85. float C = Q.x - min(Q.w, Q.y);
  86. float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
  87. return float3(H, C, Q.x);
  88. }
  89.  
  90. float3 RGBToHSL(in float3 RGB)
  91. {
  92. float3 HCV = RGBToHCV(RGB);
  93. float L = HCV.z - HCV.y * 0.5;
  94. float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
  95. return float3(HCV.x, S, L);
  96. }
  97.  
  98. float3 HSLToRGB(in float3 HSL)
  99. {
  100. float3 RGB = HUEToRGB(HSL.x);
  101. float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
  102. return (RGB - 0.5) * C + HSL.z;
  103. }
  104.  
  105. float3 HUEFXPass(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
  106. {
  107. float3 color = tex2D(ReShade::BackBuffer, texcoord).rgb;
  108.  
  109. float4 r0; float2 r1; float2 r2;
  110. r0.xyz = saturate( color.xyz );
  111. r0.w=dot(r0.xyz, ccFilterLuma.xyz/dot(ccFilterLuma.xyz, 1));
  112. r1.x = RGBToHSL( r0.xyz ).x;
  113.  
  114. float hueMids = hueMid * (1.0/360.0);
  115. r2.xy=float2(hueMids-hueRange, hueMids+hueRange);
  116.  
  117. if(r2.y>1 && r1.x<r2.y-1)
  118. r1.x+=1;
  119. if(r2.x<0 && r1.x>r2.x+1)
  120. r1.x-=1;
  121. if(r1.x<hueMids)
  122. r0.xyz=lerp(r0.w, r0.xyz, smootherstep(r2.x, hueMids, r1.x)*satLimit);
  123. if(r1.x>=hueMids)
  124. r0.xyz=lerp(r0.w, r0.xyz, (1-smootherstep(hueMids, r2.y, r1.x))*satLimit);
  125.  
  126. color.xyz=lerp(color.xyz, r0.xyz, fxcolorMix);
  127.  
  128.  
  129. if(iUsehslfilter == 1)
  130. {
  131. color.xyz=RGBToHSL(saturate(color.xyz));
  132. color.x=color.x+color.x-smootherstep(1, color.x+r0.x,1);
  133. color.y=color.y+((1-color.y)*(r0.y*color.y));
  134. color.z=color.z+((1-color.z)*(r0.z*color.z));
  135. color.z=color.z+((1-color.z)*(r0.w*(1-color.z)));
  136. color.xyz=HSLToRGB(saturate(color.xyz));
  137. }
  138.  
  139. return color;
  140.  
  141. }
  142.  
  143. technique HueFX
  144. {
  145. pass
  146. {
  147. VertexShader = PostProcessVS;
  148. PixelShader = HUEFXPass;
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement