Vapoursynth AntiRing (GLSL)

From wiki.selur.net
Jump to navigation Jump to search

AntiRing (GLSL) runs mpv's antiring shader through vs-placebo. The shader limits the overshoot that a scaling kernel creates next to sharp edges.

Filtering → Vapoursynth → DeRing

AntiRing (GLSL) controls in Hybrid
AntiRing (GLSL) controls in Hybrid

What it does

During scaling, each output pixel is clamped to the minimum and maximum of eight neighbors (four axial, four diagonal) taken from the picture before scaling, and then mixed with the unclamped pixel by Strength. A second pass does the same for chroma after chroma upscaling.

The shader only acts on overshoot created by scaling. Hybrid therefore runs it while scaling to twice the width and height and scales the result back to the input size with Spline36, so Strength and Radius have a visible effect. It is not a deringer for ringing that is already in the source; for that use AntiRing, HQDering, MDering or CDEF.

Requirements

  • vs-placebo (libplacebo) and a GPU with Vulkan support.
  • The GLSL shader folder in Hybrid's VapourSynth plugins; without it all GLSL filters are hidden.

Settings

Control Parameter Range / values Hybrid default Meaning
Strength strength 0.01 – 100 1 Mix between the original and the clamped pixel: 1 = full clamp, below 1 = partial. Above 1 the clamp is overshot (overcorrection).
Radius radius 0.01 – 100 0.5 Distance of the neighbor samples (in pixels of the picture before scaling) that define the minimum/maximum window.

Example

Default settings on a 10-bit YUV 4:2:0 source (640x356):

# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLAntiRing
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# applying anti-ringing using glsl filter
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/antiring.glsl") as glslf:
  glsl = glslf.read()
glsl = glsl.replace('const float strength = 1.0;', 'const float strength = 1;')
glsl = glsl.replace('const float radius = 0.5;', 'const float radius = 0.5;')
clip = core.resize.Spline36(core.placebo.Shader(clip, shader_s=glsl, width=clip.width*2, height=clip.height*2, matrix=1), width=clip.width, height=clip.height)

How Hybrid calls it

  • The clip is converted to YUV 4:4:4 16 bit, the only format the shader filter accepts.
  • Hybrid writes Strength and Radius into the shader text (both passes), runs the shader at twice the input width and height and scales the result back to the input size with Spline36. The color matrix of the clip is passed to vs-placebo.
  • Both values are always written; they have no unit and are not scaled.
  • vs-placebo works in an RGB pipeline and converts back to YUV; this round trip alone can clip values outside the limited range.
  • AntiRing (GLSL) also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

Shader and vs-placebo

The shader comes from an mpv configuration (wopian/mpv-config, antiring.hook). Its luma pass hooks the stage after the scaling kernel, the chroma pass the stage after chroma upscaling; the shader notes that the chroma pass ignores chroma offsets and so adds a little error. vs-placebo only runs a shader stage when that stage is actually rendered, which is why the shader needs a scaling call to have an effect. vs-placebo's own resampler also has a built-in antiring option.

Sources