Vapoursynth Levels (GLSL): Difference between revisions
Vapoursynth Levels (GLSL) in Hybrid (via create-page on MediaWiki MCP Server) |
Contents box on the right, new section order (via update-page on MediaWiki MCP Server) |
||
| Line 1: | Line 1: | ||
<div style="float:right; margin:0 0 1em 1em;">__TOC__</div> | |||
'''Levels (GLSL)''' remaps brightness levels on the GPU: values in an input range are stretched or squeezed to an output range, with a gamma curve in between. It does the same job as [[Vapoursynth Levels|Levels]], but runs as a small GLSL shader through libplacebo (vs-placebo). | '''Levels (GLSL)''' remaps brightness levels on the GPU: values in an input range are stretched or squeezed to an output range, with a gamma curve in between. It does the same job as [[Vapoursynth Levels|Levels]], but runs as a small GLSL shader through libplacebo (vs-placebo). | ||
| Line 9: | Line 10: | ||
With Hybrid's defaults (''In'' 16/235, ''Out'' 0/255) the filter expands limited (TV) range to full (PC) range. | With Hybrid's defaults (''In'' 16/235, ''Out'' 0/255) the filter expands limited (TV) range to full (PC) range. | ||
== Requirements == | |||
* vs-placebo (libplacebo) and a GPU that libplacebo can use. | |||
* Hybrid's GLSL shader folder. | |||
== Settings == | == Settings == | ||
| Line 22: | Line 27: | ||
All values are on the 8-bit scale, independent of the clip's bit depth; the shader divides them by 255 internally. | All values are on the 8-bit scale, independent of the clip's bit depth; the shader divides them by 255 internally. | ||
== Example == | == Example == | ||
| Line 47: | Line 45: | ||
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> | </syntaxhighlight> | ||
== How Hybrid calls it == | |||
* The clip is converted to YUV444P16 first, the only format the filter accepts in Hybrid. | |||
* Hybrid loads the shader ''Levels.glsl'' from its GLSL folder, writes the five values into its <code>#define</code> lines and runs it with <code>placebo.Shader</code>. The frame size stays the same. | |||
* The shader runs in libplacebo's RGB pipeline, so all three color channels are adjusted the same way (unlike [[Vapoursynth Levels|Levels]] with ''Planes'' set to luma only). | |||
* The filter is only offered when Hybrid's GLSL shader folder is present. | |||
* Levels (GLSL) also offers the [[Vapoursynth common filter options|common options]] (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick). | |||
== Background == | == Background == | ||
| Line 60: | Line 65: | ||
=== AviSynth (Levels) === | === AviSynth (Levels) === | ||
AviSynth's Levels uses the same transfer function, ((x − input_low) / (input_high − input_low))^(1/gamma) scaled to the output range, and adds ''coring'' and ''dither'' options. See [[Avisynth Levels]]. | AviSynth's Levels uses the same transfer function, ((x − input_low) / (input_high − input_low))^(1/gamma) scaled to the output range, and adds ''coring'' and ''dither'' options. See [[Avisynth Levels]]. | ||
== Sources == | == Sources == | ||
Revision as of 15:57, 14 November 2026
Levels (GLSL) remaps brightness levels on the GPU: values in an input range are stretched or squeezed to an output range, with a gamma curve in between. It does the same job as Levels, but runs as a small GLSL shader through libplacebo (vs-placebo).
Filtering → Vapoursynth → Color → Levels

What it does
Values between In min and In max are mapped to the range between Out min and Out max; values outside the input range are clipped. Gamma bends the curve in between: values above 1 brighten the mid tones, values below 1 darken them.
With Hybrid's defaults (In 16/235, Out 0/255) the filter expands limited (TV) range to full (PC) 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 |
|---|---|---|---|---|
| In (min/max) | input_low / input_high | 0–255 | 16 / 235 | Input range that is assumed. |
| Out (min/max) | output_low / output_high | 0–255 | 0 / 255 | Range the input range is mapped to. |
| Gamma | gamma | 0–100 | 1.00 | 1 = no change, > 1 brightens, < 1 darkens, 0 = black. |
All values are on the 8-bit scale, independent of the clip's bit depth; the shader divides them by 255 internally.
Example
Default settings on a 10-bit YUV 4:2:0 source:
# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLLevels
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# adjusting level susing GLSL Levels
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/Levels.glsl") as glslf:
glsl = glslf.read()
glsl = glsl.replace('#define input_low 16.0', '#define input_low 16')
glsl = glsl.replace('#define input_high 235.0', '#define input_high 235')
glsl = glsl.replace('#define output_low 0.0', '#define output_low 0')
glsl = glsl.replace('#define output_high 255.0', '#define output_high 255')
glsl = glsl.replace('#define gamma 1.0', '#define gamma 1')
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 Levels.glsl from its GLSL folder, writes the five values into its
#definelines and runs it withplacebo.Shader. The frame size stays the same. - The shader runs in libplacebo's RGB pipeline, so all three color channels are adjusted the same way (unlike Levels with Planes set to luma only).
- The filter is only offered when Hybrid's GLSL shader folder is present.
- Levels (GLSL) also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).
Background
The shader
Levels.glsl is an mpv-style user shader. It normalizes the five values to 0–1, subtracts input_low, divides by the input range, clamps to 0–1, applies pow(x, 1/gamma), scales to the output range and clamps again.
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, so 4:2:0 chroma is upscaled. width and height set the output size.
VapourSynth
The VapourSynth documentation has no page for this shader filter; the CPU counterpart is std.Levels, see Levels.
AviSynth (Levels)
AviSynth's Levels uses the same transfer function, ((x − input_low) / (input_high − input_low))^(1/gamma) scaled to the output range, and adds coring and dither options. See Avisynth Levels.
Sources
- vs-placebo README
- VapourSynth documentation: std.Levels (CPU counterpart)
- AviSynth+ documentation: Levels
- The shader Levels.glsl shipped with Hybrid
- Hybrid's tooltips