Vapoursynth Thin (GLSL-A4K)

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

Thin (GLSL-A4K) thins the outlines of anime and cartoons on the GPU with the Anime4K Thin shader.

Filtering → Vapoursynth → Line

Thin (GLSL-A4K) controls in Hybrid
Thin (GLSL-A4K) controls in Hybrid

What it does

The shader computes an edge gradient of the luma (Sobel plus Gaussian) and warps the picture towards the edges, which makes lines narrower. The warp can run several times. Three variants trade quality for GPU time.

Requirements

  • vs-placebo (libplacebo) and a GPU with Vulkan support.
  • The GLSL shader folder in Hybrid's VapourSynth plugins; without it the filter is locked.

Settings

Control Parameter Range / values Hybrid default Meaning
Strength STRENGTH 0.01 – 100 0.6 Warp strength per iteration; higher gives thinner lines, past a point they visibly bend. Scaled with the picture height relative to 1080p.
Iterations ITERATIONS 1 – 100 1 Number of warp passes; lower Strength with more iterations is cleaner but slower.
Speed – VeryFast, Fast, HQ VeryFast Shader variant: VeryFast and Fast compute the gradient at reduced resolution, HQ at full resolution with the largest kernel.

Example

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

# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLThinLine
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# Line thinning using GLSL Anime4K-Thin
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/Anime4K_Thin_VeryFast.glsl") as glslf:
  glsl = glslf.read()
glsl = glsl.replace('#define STRENGTH 0.6', '#define STRENGTH 0.6')
glsl = glsl.replace('#define ITERATIONS 1', '#define ITERATIONS 1')
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; the output stays in that format and size.
  • Hybrid loads the shader file of the chosen Speed, writes Strength and Iterations into the shader text and runs it with the input width and height and the clip's color matrix.
  • Both values are always written. They are not scaled to the bit depth.
  • Thin (GLSL-A4K) also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

Anime4K

Anime4K by bloc97 is an open-source (MIT) collection of real-time shaders for anime, written mainly for mpv; Hybrid uses the v3.2 Thin shaders. The project lists Thin as an experimental shader, based on the idea that thinner lines look sharper. Related shaders: Darken (GLSL-A4K) and Deblur (GLSL-A4K).

Sources