Vapoursynth Gamma (GLSL): Difference between revisions

From wiki.selur.net
Jump to navigation Jump to search
Default 1, minimum 0.01 (via update-page on MediaWiki MCP Server)
Example with gamma 1.2 (via update-page on MediaWiki MCP Server)
Line 21: Line 21:


== Example ==
== Example ==
Default settings on a 10-bit YUV 4:2:0 source:
Slightly brighter mid tones (''Gamma'' 1.2) on a 10-bit YUV 4:2:0 source:
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLGamma
# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLGamma

Revision as of 17:22, 14 November 2026

Gamma (GLSL) changes the gamma of the video with a small GLSL shader that libplacebo (vs-placebo) runs on the GPU.

Filtering → Vapoursynth → Color → Levels

Gamma (GLSL) controls in Hybrid
Gamma (GLSL) controls in Hybrid

What it does

Each color channel is raised to the power 1/Gamma. Values above 1 brighten the mid tones, values below 1 darken them; pure black and pure white stay where they are. The result is clamped to the valid range.

Requirements

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

Settings

Control Shader parameter Range Hybrid default Meaning
Gamma GammaFactor 0.01 – 100 1.00 1 = no change, > 1 brightens, < 1 darkens.

Example

Slightly brighter mid tones (Gamma 1.2) on a 10-bit YUV 4:2:0 source:

# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLGamma
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# adjusting gamma using GLSL Gamma
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/gamma.glsl") as glslf:
  glsl = glslf.read()
glsl = glsl.replace('#define GammaFactor 2.0', '#define GammaFactor 2')
clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height)
# 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 loads the shader gamma.glsl from its GLSL folder, writes the value into its GammaFactor line and runs it with placebo.Shader. The frame size stays the same.
  • The shader runs in libplacebo's RGB pipeline, so the curve acts on the R, G and B values; the result comes back as YUV444P16.
  • The filter is only offered when Hybrid's GLSL shader folder is present.
  • Gamma (GLSL) also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

The shader

gamma.glsl is a lightweight gamma correction shader for mpv/libplacebo. It computes clamp(pow(rgb, 1/GammaFactor), 0, 1) and passes alpha through unchanged.

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. width and height set the output size.

VapourSynth

The VapourSynth documentation has no page for this shader filter. The closest core function is std.Levels with its gamma parameter, see Levels.

AviSynth

AviSynth has no separate gamma filter; the gamma argument of Levels does the same (higher values brighten). See Avisynth Levels.

Sources