SHARE
TWEET

Lumasharpen

a guest Aug 25th, 2016 2,302 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Author: CeeJay.dk
  2. // Title: LumaSharpen
  3. // Pack: SweetFX
  4. // Desc:
  5. // Sharpens the image
  6. // This is simplified version of the LumaSharpen found in SweetFX
  7.  
  8. //Settings :
  9. static const float sharp_strength = 0.60; //Sharpening strength
  10. static const float sharp_clamp    = 0.035; //Clamp the max sharpening to prevent halo artifacts
  11.  
  12. //Code :
  13. texture lastpass;
  14.  
  15. sampler s0 = sampler_state { texture=<lastpass>; minfilter = linear; magfilter = linear; mipfilter = linear; addressu=clamp; addressv = clamp; };
  16.  
  17. vector rcpres;
  18.  
  19. float4 LumaSharpen(in float2 Tex : TEXCOORD) : COLOR0
  20. {
  21.         float4 inColor = tex2D(s0, Tex);
  22.  
  23.         float3 blur = tex2D(s0, Tex + float2(0.5 * rcpres.xy)).rgb;
  24.         blur += tex2D(s0, Tex + float2(-0.5 * rcpres.xy)).rgb;
  25.         blur += tex2D(s0, Tex + float2(0.5 * rcpres.x,-0.5 * rcpres.y)).rgb;
  26.         blur += tex2D(s0, Tex + float2(-0.5 * rcpres.x,0.5 * rcpres.y)).rgb;
  27.  
  28.         blur /= 4.0;
  29.  
  30.         float3 sharp = inColor.rgb - blur;
  31.  
  32.         static const float3 CoefLuma = float3(0.2126, 0.7152, 0.0722); //luma conversion values
  33.         float3 sharp_strength_luma = (sharp_strength * CoefLuma);
  34.  
  35.         // -- Adjust strength of the sharpening --
  36.         float sharp_luma = dot(sharp, sharp_strength_luma); //Calculate the luma and adjust the strength
  37.  
  38.         // -- Clamping the maximum amount of sharpening to prevent halo artifacts --
  39.         sharp_luma = clamp(sharp_luma, -sharp_clamp, sharp_clamp);  //
  40.  
  41.         inColor.rgb = inColor.rgb + sharp_luma;
  42.  
  43.         return inColor;
  44. }
  45.  
  46. technique T0 < string MGEinterface="MGE XE 0"; >
  47. {
  48.         pass p0
  49.         {
  50.                 PixelShader = compile ps_3_0 LumaSharpen();
  51.         }
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top