Vapoursynth Luma Sharpen (GLSL)

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

Luma Sharpen (GLSL) is an unsharp-mask style sharpener that runs as a GPU shader through vs-placebo. It is a port of LumaSharpen by CeeJay.dk (SweetFX).

Filtering → Vapoursynth → Sharpen

Luma Sharpen (GLSL) controls in Hybrid
Luma Sharpen (GLSL) controls in Hybrid

What it does

Each luma pixel is blurred with a few neighbors, the difference to the original is scaled by Strength, limited by Clamp and added back. Only luma is touched, which avoids color artifacts; the clamp keeps halos small. The shader compares itself to the Unsharp Mask of image editors.

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 sharp_strength 0.0001 – 10 0.3 Sharpening strength; the shader suggests 0.1 – 3.
Clamp sharp_clamp 0.0001 – 10 0.035 Largest change a pixel may receive (normalized 0 – 1 luma); above 1 it no longer limits anything.
Pattern pattern Fast, Normal, Wider, Pyramid shaped, 9 tap 9 fetch gaussian, 9 tap 9 fetch high pass Normal Sample pattern of the blur (see below).
Offset bias offset_bias 0 – 6 1.0 Scales the radius of the sample pattern.

Example

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

# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLLumaSharpen
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# Sharpening using GLSL LumaSharpen
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/LumaSharpenHook.glsl") as glslf:
  glsl = glslf.read()
glsl = glsl.replace('#define sharp_strength 0.30', '#define sharp_strength 0.3000')
glsl = glsl.replace('#define sharp_clamp    0.035', '#define sharp_clamp    0.0350')
glsl = glsl.replace('#define pattern 2', '#define pattern 2')
glsl = glsl.replace('#define offset_bias 1.0', '#define offset_bias 1.0000')
clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height, matrix=1)

How Hybrid calls it

  • The clip is converted to YUV 4:4:4 16 bit, the only format the shader filter accepts.
  • Hybrid writes the four settings into the shader text and runs it with the input width and height; the color matrix of the clip is passed to vs-placebo.
  • All values are always written; they work on normalized values and are not scaled to the bit depth.
  • Luma Sharpen (GLSL) also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

Patterns

  • Fast: 7-tap gaussian with 2 texture fetches; strength is raised by 1.5.
  • Normal: 9-tap gaussian with 4 fetches.
  • Wider: experimental 17-tap pattern; strength × 0.51.
  • Pyramid shaped: pyramid high pass; strength × 0.666.
  • 9 tap 9 fetch gaussian / high pass: slower variants with 9 fetches; strength × 0.75 and × 8/9.

The output of the shader is clamped to the valid range.

Sources