Vapoursynth Saturation (GLSL): Difference between revisions

From wiki.selur.net
Jump to navigation Jump to search
Example with factor 1.3 (via update-page on MediaWiki MCP Server)
Update to current Hybrid behaviour; code as <pre> (via update-page on MediaWiki MCP Server)
 
(4 intermediate revisions by the same user not shown)
Line 27: Line 27:
== Example ==
== Example ==
Saturation raised by 30 % (''Factor'' 1.3) on a 10-bit YUV 4:2:0 source:
Saturation raised by 30 % (''Factor'' 1.3) on a 10-bit YUV 4:2:0 source:
<syntaxhighlight lang="python">
<pre>
# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLSaturation
# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLSaturation
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# adjusting saturation using GSLS bSat
# adjusting saturation using GLSL bSat
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/bSat.hook.glsl") as glslf:
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/bSat.hook.glsl") as glslf:
   glsl = glslf.read()
   glsl = glslf.read()
glsl = glsl.replace('#define SatFactor 2.43', '#define SatFactor 2.43')
glsl = glsl.replace('#define SatFactor 2.43', '#define SatFactor 1.3')
clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height)
clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height, matrix=1)
# adjusting output color from YUV444P16 to YUV420P10 for NVEncModel
# adjusting output color from YUV444P16 to YUV420P10 for NVEncModel
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, dither_type="error_diffusion")
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, dither_type="error_diffusion")
</syntaxhighlight>
</pre>


== How Hybrid calls it ==
== How Hybrid calls it ==
* The clip is converted to YUV444P16 first, the only format the filter accepts in Hybrid.
* The clip is converted to YUV444P16 first, the only format the filter accepts in Hybrid.
* Hybrid passes the clip's color matrix to <code>placebo.Shader</code> (<code>matrix=1</code> for BT.601/470bg, 2 for BT.709, 4/5 for BT.2020), so the shader's RGB values match the clip.
* Hybrid loads the shader ''bSat.hook.glsl'' from its GLSL folder, writes the factor into its <code>SatFactor</code> line and runs it with <code>placebo.Shader</code>. The frame size stays the same.
* Hybrid loads the shader ''bSat.hook.glsl'' from its GLSL folder, writes the factor into its <code>SatFactor</code> line and runs it with <code>placebo.Shader</code>. The frame size stays the same.
* The shader works on RGB inside libplacebo's pipeline; the result comes back as YUV444P16.
* The shader works on RGB inside libplacebo's pipeline; the result comes back as YUV444P16.
Line 52: Line 53:
=== vs-placebo (placebo.Shader) ===
=== vs-placebo (placebo.Shader) ===
<code>placebo.Shader</code> runs mpv-syntax GLSL shaders through libplacebo. The shader is passed as a file or, as Hybrid does, as a string. Input is a 16-bit YUV clip, output is always YUV444P16; the conversion to and from RGB uses the ''matrix'', ''trc'' and ''chroma_loc'' settings (default BT.709).
<code>placebo.Shader</code> runs mpv-syntax GLSL shaders through libplacebo. The shader is passed as a file or, as Hybrid does, as a string. Input is a 16-bit YUV clip, output is always YUV444P16; the conversion to and from RGB uses the ''matrix'', ''trc'' and ''chroma_loc'' settings (default BT.709).
=== VapourSynth ===
Not a core filter; the VapourSynth documentation has no page for it.


=== AviSynth ===
=== AviSynth ===
AviSynth has no GLSL filters. The closest core filter is Tweak with its ''sat'' parameter (0–10, 1 = no change), which works in YUV instead of RGB. See [[Avisynth Tweak]].
The closest AviSynth core filter is Tweak with its ''sat'' parameter (0–10, 1 = no change), which works in YUV instead of RGB. See [[Avisynth Tweak]].


== Sources ==
== Sources ==

Latest revision as of 09:50, 16 November 2026

Saturation (GLSL) changes the color saturation with bSat, a small GLSL shader originally written for mpv, run on the GPU by libplacebo (vs-placebo).

Filtering → Vapoursynth → Color → Grading

Saturation (GLSL) controls in Hybrid
Saturation (GLSL) controls in Hybrid

What it does

For every pixel the shader averages R, G and B to a gray value and blends between that gray and the original color by Factor:

  • 0 = grayscale,
  • below 1 = less saturation,
  • 1 = no change,
  • above 1 = more saturation.

Very large factors clip strongly saturated colors.

Requirements

  • vs-placebo (libplacebo) and a GPU that libplacebo can use.
  • Hybrid's GLSL shader folder.

Settings

Control Shader parameter Range Hybrid default Meaning
Factor SatFactor 0 – 100 1.00 Saturation factor; 1 = no change.

Example

Saturation raised by 30 % (Factor 1.3) on a 10-bit YUV 4:2:0 source:

# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLSaturation
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# adjusting saturation using GLSL bSat
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/bSat.hook.glsl") as glslf:
  glsl = glslf.read()
glsl = glsl.replace('#define SatFactor 2.43', '#define SatFactor 1.3')
clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height, matrix=1)
# adjusting output color from YUV444P16 to YUV420P10 for NVEncModel
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, dither_type="error_diffusion")

How Hybrid calls it

  • The clip is converted to YUV444P16 first, the only format the filter accepts in Hybrid.
  • Hybrid passes the clip's color matrix to placebo.Shader (matrix=1 for BT.601/470bg, 2 for BT.709, 4/5 for BT.2020), so the shader's RGB values match the clip.
  • Hybrid loads the shader bSat.hook.glsl from its GLSL folder, writes the factor into its SatFactor line and runs it with placebo.Shader. The frame size stays the same.
  • The shader works on RGB inside libplacebo's pipeline; the result comes back as YUV444P16.
  • The filter is only offered when Hybrid's GLSL shader folder is present.
  • Saturation (GLSL) also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

The shader

bSat (v0.1 by butterw) is a lightweight RGB saturation shader for mpv. It computes gray = (R+G+B)/3 with equal weights (not luma weights) and returns mix(gray, color, SatFactor) without clamping.

vs-placebo (placebo.Shader)

placebo.Shader runs mpv-syntax GLSL shaders through libplacebo. The shader is passed as a file or, as Hybrid does, as a string. Input is a 16-bit YUV clip, output is always YUV444P16; the conversion to and from RGB uses the matrix, trc and chroma_loc settings (default BT.709).

AviSynth

The closest AviSynth core filter is Tweak with its sat parameter (0–10, 1 = no change), which works in YUV instead of RGB. See Avisynth Tweak.

Sources