Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Hardware & Software > Software players

Reply
 
Thread Tools Search this Thread Display Modes
Old 13th May 2015, 18:00   #1  |  Link
bacondither
Registered User
 
Join Date: Oct 2013
Location: Sweden
Posts: 128
Adaptive sharpen - Image sharpening shader

It is an image enhancement shader written in HLSL that can be used by MPC-HC or MPDN and other software that can use pixel shaders. Github page

Version 2018-04-14
BSD 2-clause license

Download

Code:
Changelog:
2018-04-14 - Misc tweaks.

2017-12-30 - Cosmetic changes and minor improvements.

2017-11-01 - Small improvement for anti-ringing.
           - Tweaks and minor changes.

2017-04-11 - Use compression instead of clipping for nmax_scale & nmin_scale.
           - Tweaked saturation compensation.

2017-01-22 - Replaced the algorithm for saturation compensation.

2016-12-07 - Changed how saturation is compensated for when brightness is altered.
           - Misc tweaks.

2016-09-24 - Updated edge-detection weights, slightly better for high-frequency content.
           - Minor tweaks.

2016-07-10 - Replaced lerp used for overshoot compression with a weighted power mean, reduces some ringing.
           - Corrected minor error in the custom smoothstep function.
           - Slightly improved weighting for nmax & nmin.
           - Tweaked some parameters.

2016-01-12 - Faster sorting algorithm.

2016-01-07 - Fixed compiler warning X3571 and handle a possible divide by zero.

2015-12-09 - Use a concave sharpening kernel for higher center edge values.
           - For summation of pixels in the laplace kernel use a sRGB gamma approximation.

2015-11-17 - Improved low threshold for sharpening.
           - Linear light used for summation in the laplace kernel.
           - Fixed tanh overflow.

2015-09-23 - Limit low values for the "middle ring" of laplace weights.
           - Misc changes.

2015-08-19 - 2-pass algorithm.
           - Better overshoot control.
           - Reduced saturation loss on pixels made brighter.

2015-06-25 - Unrolls the sorting loop when compiled with ps 4.0+ (much better performance for ps 4.0+).
           - Added fix for MPDN (alpha channel is always set to one).
           - Style fixes.

2015-05-15 - No real change from the last version, just changed some stupid variable names and comments.

2015-04-05 - First release.

Installation instructions

The shader is tuned and designed for post resize.
Requires gamma light as input and a pixel shader of version 3 or higher.

Settings are stored in the second pass file.
curve_height is the main control for the sharpening strength.

The correct shader order are:
Pass one
Pass two

If the shader passes are added in the wrong order or the alpha channel is truncated, it will return a green screen.


It does what?

The shader tries to sharpen somewhat blurry edges the most, it avoids to sharpen near-flat areas and very sharp edges.
The outer weights of the laplace matrix is variable to mitigate ringing on relative sharp edges and to provide more sharpening on wider and blurrier edges.

The final stage is a soft limiter that confines overshoots based on local near min/max values.
Light overshoots are limited more due to it's worse appearance compared to dark undershoots in most cases.


Old Versions

Depreciated old one pass version:
Download - OLD - 2015-05-25

Last edited by bacondither; 16th April 2018 at 16:15.
bacondither is offline   Reply With Quote
Old 14th May 2015, 07:52   #2  |  Link
toniash
Registered User
 
Join Date: Oct 2010
Posts: 131
Quote:
Originally Posted by bacondither View Post
It is an image enhancement shader written in HLSL that can be used by MPC-HC or MPDN and other software that can use pixel shaders. It's tuned and designed for post resize and wants gamma light as input.

I will probably rewrite this post soon and add more information!
Meanwhile i hope it works for you

BSD 2-clause license

Requires pixel shader version 3.0

Version 2015-04-05

Download
Very good!

What is gamma light?

Last edited by toniash; 14th May 2015 at 12:05.
toniash is offline   Reply With Quote
Old 14th May 2015, 13:06   #3  |  Link
Zachs
Suptitle, MediaPlayer.NET
 
Join Date: Nov 2001
Posts: 1,721
Think of Gamma light is the default mode in a render chain. So long as you don't add the ConvertToLinearLight.hlsl file which converts gamma light to linear light, you'll be in gamma light mode.
Zachs is offline   Reply With Quote
Old 18th May 2015, 05:44   #4  |  Link
KhR0N1K
Registered User
 
Join Date: May 2015
Posts: 16
thanks

awesome work man was waiting for something like this for a long time. it looks amazing. i was testing the FineSharp and LumaSharpen through madVR but i like the way this one looks a lot better.

thanks
KhR0N1K is offline   Reply With Quote
Old 18th May 2015, 10:04   #5  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
Testing in MPDN, the image immediately becomes much darker. Is this expected? For some reason, the same thing happens with FineSharp.

Intel 4600, win8.1.
foxyshadis is offline   Reply With Quote
Old 18th May 2015, 10:14   #6  |  Link
huhn
Registered User
 
Join Date: Oct 2012
Posts: 7,903
Quote:
Originally Posted by foxyshadis View Post
Testing in MPDN, the image immediately becomes much darker. Is this expected? For some reason, the same thing happens with FineSharp.

Intel 4600, win8.1.
works fine for me. even if work used as a pre resize shader.
huhn is offline   Reply With Quote
Old 18th May 2015, 10:16   #7  |  Link
KhR0N1K
Registered User
 
Join Date: May 2015
Posts: 16
Quote:
Originally Posted by foxyshadis View Post
Testing in MPDN, the image immediately becomes much darker. Is this expected? For some reason, the same thing happens with FineSharp.

Intel 4600, win8.1.
i noticed this happening when saving screens to compare using MPC-BE. but seemed fine when viewing in the player itself or using PrtScrn instead of Save Image. could be a completely different issue though.

Last edited by KhR0N1K; 18th May 2015 at 10:18.
KhR0N1K is offline   Reply With Quote
Old 20th May 2015, 12:50   #8  |  Link
RainyDog
Registered User
 
Join Date: May 2009
Posts: 184
Thanks for this bacondither. Tried it last night and liked what I saw.

I'd been using Lumasharpen pre and post resize with reduced clamp as I could never get it to my liking when used in post only. But I found Adaptive Sharpen to be much more effective post only so it might be just what I've been looking for.

Seemed much too aggressive when used as a pre resize sharpener though, but I suppose you mention that it has been tuned for post resize.
RainyDog is offline   Reply With Quote
Old 11th June 2015, 03:47   #9  |  Link
bacondither
Registered User
 
Join Date: Oct 2013
Location: Sweden
Posts: 128
Quote:
Originally Posted by toniash View Post
Very good!
Quote:
Originally Posted by KhR0N1K View Post
awesome work man was waiting for something like this for a long time. it looks amazing. i was testing the FineSharp and LumaSharpen through madVR but i like the way this one looks a lot better.

thanks
Quote:
Originally Posted by RainyDog View Post
Thanks for this bacondither. Tried it last night and liked what I saw.

I'd been using Lumasharpen pre and post resize with reduced clamp as I could never get it to my liking when used in post only. But I found Adaptive Sharpen to be much more effective post only so it might be just what I've been looking for.

Seemed much too aggressive when used as a pre resize sharpener though, but I suppose you mention that it has been tuned for post resize.
Thanks

Quote:
Originally Posted by foxyshadis View Post
Testing in MPDN, the image immediately becomes much darker. Is this expected? For some reason, the same thing happens with FineSharp.

Intel 4600, win8.1.
For me it works fine in MPDN.

Last edited by bacondither; 16th June 2015 at 07:37.
bacondither is offline   Reply With Quote
Old 16th June 2015, 02:56   #10  |  Link
Olivier C.
Registered User
 
Join Date: Jan 2014
Location: France
Posts: 76
Hi,

Is there an equivalent of Masktools for GPU ?
Something like mt_merge (merge two layers according to a mask) for example ?

The actual formula is y = ((256 - m) * x1 + m * x2 + 128) / 256 ) where, for a given pixel :
y is the result (merge)
m is the mask value (from 0 to 255)
x1 is the first layer to merge
x2 is the second layer to merge

I am trying to port some avisynth scripts to shaders (GPU) but i am not an expert of .hlsl

Thanks
Olivier
Olivier C. is offline   Reply With Quote
Old 16th June 2015, 03:42   #11  |  Link
vivan
/人 ◕ ‿‿ ◕ 人\
 
Join Date: May 2011
Location: Russia
Posts: 643
It should work just like that, except everything is done in floating point ([0..1] range).
So
Code:
(1.0 - m) * x1 + m * x2 + 0.5
or it's equal
Code:
lerp (x1, x2, m) + 0.5
vivan is offline   Reply With Quote
Old 16th June 2015, 18:44   #12  |  Link
madshi
Registered Developer
 
Join Date: Sep 2006
Posts: 9,140
Some caution, though: I think AviSynth scripts usually run in YCbCr, so Y has a range from 16-235. In contrast to that, usually custom pixel shaders are executed in PC levels. So AviSynth 16 should map to floating point 0.0, and AviSynth 235 should map to floating point 1.0. Won't matter for some AviSynth scripts, but it will probably affect some.
madshi is offline   Reply With Quote
Old 16th June 2015, 19:00   #13  |  Link
Olivier C.
Registered User
 
Join Date: Jan 2014
Location: France
Posts: 76
Quote:
Originally Posted by vivan View Post
It should work just like that, except everything is done in floating point ([0..1] range).
So
Code:
(1.0 - m) * x1 + m * x2 + 0.5
or it's equal
Code:
lerp (x1, x2, m) + 0.5
Thanks vivan
Olivier C. is offline   Reply With Quote
Old 16th June 2015, 19:01   #14  |  Link
Olivier C.
Registered User
 
Join Date: Jan 2014
Location: France
Posts: 76
Quote:
Originally Posted by madshi View Post
Some caution, though: I think AviSynth scripts usually run in YCbCr, so Y has a range from 16-235. In contrast to that, usually custom pixel shaders are executed in PC levels. So AviSynth 16 should map to floating point 0.0, and AviSynth 235 should map to floating point 1.0. Won't matter for some AviSynth scripts, but it will probably affect some.
Good point Mathias, thanks !
Olivier C. is offline   Reply With Quote
Old 28th June 2015, 22:46   #15  |  Link
madshi
Registered Developer
 
Join Date: Sep 2006
Posts: 9,140
FYI, I've implemented this in the latest madVR build now, so users can directly play with it, instead of having to setup custom pixel shaders. Thanks for making this available under BSD license!
madshi is offline   Reply With Quote
Old 7th July 2015, 02:28   #16  |  Link
KhR0N1K
Registered User
 
Join Date: May 2015
Posts: 16
this may sound like a dumb question but do i have to have the options "don't use linear light for dithering" and "don't use linear light for smooth motion frame blending" in the madVR options under the "trade quality for performance" tab?

or do these not interfere with the gamma light for the Adaptive Sharpen shader?

also the same question for the "scale in linear light" options for upscaling and downscaling in madVR?
KhR0N1K is offline   Reply With Quote
Old 7th July 2015, 07:46   #17  |  Link
madshi
Registered Developer
 
Join Date: Sep 2006
Posts: 9,140
These options are totally unrelated to Adaptive Sharpen. The trade quality options should better be unchecked, unless you need them to be checked for performance reasons. For upscaling linear light is not recommended. For downscaling it's a matter of taste.
madshi is offline   Reply With Quote
Old 7th July 2015, 18:43   #18  |  Link
KhR0N1K
Registered User
 
Join Date: May 2015
Posts: 16
Quote:
Originally Posted by madshi View Post
These options are totally unrelated to Adaptive Sharpen. The trade quality options should better be unchecked, unless you need them to be checked for performance reasons. For upscaling linear light is not recommended. For downscaling it's a matter of taste.
ok will do madshi. thanks a lot for the response. i will do what you said and leave them unchecked. and keep the scaling ones off as well.
KhR0N1K is offline   Reply With Quote
Old 11th July 2015, 02:44   #19  |  Link
foozoor
Registered User
 
foozoor's Avatar
 
Join Date: Feb 2012
Posts: 116
Could you make an opengl (glsl) version ?
It would be great for mpv-player users.
foozoor is offline   Reply With Quote
Old 16th July 2015, 16:28   #20  |  Link
bacondither
Registered User
 
Join Date: Oct 2013
Location: Sweden
Posts: 128
Quote:
Originally Posted by foozoor View Post
Could you make an opengl (glsl) version ?
It would be great for mpv-player users.
I'm working on improving it now, perhaps in the future i will write a glsl version of it.
bacondither is offline   Reply With Quote
Reply

Tags
adaptive sharpen, shader, sharpening

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:33.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.