Vapoursynth RGBAdjust (GLSL): Difference between revisions

From wiki.selur.net
Jump to navigation Jump to search
Vapoursynth RGBAdjust (GLSL) in Hybrid (via create-page on MediaWiki MCP Server)
 
Update to current Hybrid behaviour; code as <pre> (via update-page on MediaWiki MCP Server)
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
<div style="float:right; margin:0 0 1em 1em;">__TOC__</div>
<div style="float:right; margin:0 0 1em 1em;">__TOC__</div>
'''RGBAdjust (GLSL)''' changes the red, green and blue channels separately on the GPU — bias, scaling and gamma per channel — with a GLSL shader run by libplacebo (vs-placebo). It is similar to [[Vapoursynth RGBAdjust|RGBAdjust]], but the order of the steps and the direction of gamma differ.
'''RGBAdjust (GLSL)''' changes the red, green and blue channels separately on the GPU — scaling, bias and gamma per channel — with a GLSL shader run by libplacebo (vs-placebo). It is the GPU counterpart of [[Vapoursynth RGBAdjust|RGBAdjust]] and uses the same order of steps and the same gamma direction.


''Filtering → Vapoursynth → Color → Grading''
''Filtering → Vapoursynth → Color → Grading''
Line 8: Line 8:
== What it does ==
== What it does ==
For each channel the shader computes, in this order:
For each channel the shader computes, in this order:
# multiply by ''Scaling'',
# add ''Bias'' (on the 8-bit scale, divided by 255),
# add ''Bias'' (on the 8-bit scale, divided by 255),
# multiply by ''Scaling'',
# clamp to the valid range,
# raise to the power ''Gamma''.
# apply ''Gamma'' (the value is raised to the power 1/Gamma) and clamp again.
With the defaults (1 / 0 / 1) the picture is unchanged. Because the bias is added before scaling, it is scaled too. Gamma values above 1 '''darken''' and below 1 brighten — the opposite of [[Vapoursynth RGBAdjust|RGBAdjust]] and AviSynth. The shader does not clamp, so a negative bias combined with a gamma other than 1 can produce artifacts.
With the defaults (1 / 0 / 1) the picture is unchanged. Gamma values above 1 brighten and below 1 darken, as in [[Vapoursynth RGBAdjust|RGBAdjust]] and AviSynth.


== Requirements ==
== Requirements ==
Line 23: Line 24:
| Scaling (R/G/B) || RedScale, GreenScale, BlueScale || 0 – 100 || 1.00 || Multiplies the channel.
| Scaling (R/G/B) || RedScale, GreenScale, BlueScale || 0 – 100 || 1.00 || Multiplies the channel.
|-
|-
| Bias (R/G/B) || RedBias, GreenBias, BlueBias || -255 – 255 || 0.00 || Offset added before scaling, on the 8-bit scale.
| Bias (R/G/B) || RedBias, GreenBias, BlueBias || -255 – 255 || 0.00 || Offset added after scaling, on the 8-bit scale.
|-
|-
| Gamma (R/G/B) || RedGamma, GreenGamma, BlueGamma || 0 – 100 || 1.00 || Exponent; > 1 darkens, < 1 brightens.
| Gamma (R/G/B) || RedGamma, GreenGamma, BlueGamma || 0.01 – 100 || 1.00 || Gamma per channel; > 1 brightens, < 1 darkens.
|}
|}


== Example ==
== Example ==
A slightly warmer picture (red × 1.05, blue × 0.95) on a 10-bit YUV 4:2:0 source:
A slightly warmer picture (red × 1.05, blue × 0.95) on a 10-bit YUV 4:2:0 source:
<syntaxhighlight lang="python">
<pre>
# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLRGBAdjust
# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLRGBAdjust
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
Line 45: Line 46:
glsl = glsl.replace('#define GreenGamma 1.0', '#define GreenGamma 1')
glsl = glsl.replace('#define GreenGamma 1.0', '#define GreenGamma 1')
glsl = glsl.replace('#define BlueGamma 1.0', '#define BlueGamma 1')
glsl = glsl.replace('#define BlueGamma 1.0', '#define BlueGamma 1')
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 ''RGBAdjust.glsl'' from its GLSL folder, writes all nine values into its <code>#define</code> lines and runs it with <code>placebo.Shader</code>. The frame size stays the same.
* Hybrid loads the shader ''RGBAdjust.glsl'' from its GLSL folder, writes all nine values into its <code>#define</code> lines 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 59: Line 61:
== Background ==
== Background ==
=== The shader ===
=== The shader ===
''RGBAdjust.glsl'' is a full RGB adjustment shader for mpv, modeled after AviSynth's RGBAdjust (v0.1). Per channel it does <code>c += Bias/255</code>, <code>c *= Scale</code>, <code>c = pow(c, Gamma)</code>.
''RGBAdjust.glsl'' (v0.2) is an RGB adjustment shader for mpv in the same order as AviSynth's RGBAdjust. Per channel it computes <code>c = clamp(c * Scale + Bias/255, 0, 1)</code> and then <code>c = clamp(pow(c, 1/Gamma), 0, 1)</code>.


=== vs-placebo (placebo.Shader) ===
=== vs-placebo (placebo.Shader) ===
Line 65: Line 67:


=== VapourSynth ===
=== VapourSynth ===
Not a core filter; the VapourSynth documentation has no page for it. For the CPU version see [[Vapoursynth RGBAdjust|RGBAdjust]].
For the CPU version see [[Vapoursynth RGBAdjust|RGBAdjust]].


=== AviSynth (RGBAdjust) ===
=== AviSynth (RGBAdjust) ===
AviSynth's RGBAdjust applies gain first, then bias, then gamma (with > 1 brightening) and clips the result; it adds ''analyze'', ''dither'' and per-frame values. See [[Avisynth RGBAdjust]].
AviSynth's RGBAdjust applies gain first, then bias, then gamma (with > 1 brightening) and clips the result, like the shader; it adds ''analyze'', ''dither'' and per-frame values. See [[Avisynth RGBAdjust]].


== Sources ==
== Sources ==
* [https://github.com/sgt0/vs-placebo vs-placebo README]
* [https://github.com/sgt0/vs-placebo vs-placebo README]
* [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/adjust.html AviSynth+ documentation: RGBAdjust]
* [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/adjust.html AviSynth+ documentation: RGBAdjust]
* The shader ''RGBAdjust.glsl'' shipped with Hybrid
* [https://github.com/Selur/hybrid-glsl-filters hybrid-glsl-filters] (the shader ''RGBAdjust.glsl'')
* Hybrid's tooltips
* Hybrid's tooltips


[[Category:Vapoursynth Filters]]
[[Category:Vapoursynth Filters]]

Latest revision as of 09:50, 16 November 2026

RGBAdjust (GLSL) changes the red, green and blue channels separately on the GPU — scaling, bias and gamma per channel — with a GLSL shader run by libplacebo (vs-placebo). It is the GPU counterpart of RGBAdjust and uses the same order of steps and the same gamma direction.

Filtering → Vapoursynth → Color → Grading

RGBAdjust (GLSL) controls in Hybrid
RGBAdjust (GLSL) controls in Hybrid

What it does

For each channel the shader computes, in this order:

  1. multiply by Scaling,
  2. add Bias (on the 8-bit scale, divided by 255),
  3. clamp to the valid range,
  4. apply Gamma (the value is raised to the power 1/Gamma) and clamp again.

With the defaults (1 / 0 / 1) the picture is unchanged. Gamma values above 1 brighten and below 1 darken, as in RGBAdjust and AviSynth.

Requirements

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

Settings

Control Shader parameter Range Hybrid default Meaning
Scaling (R/G/B) RedScale, GreenScale, BlueScale 0 – 100 1.00 Multiplies the channel.
Bias (R/G/B) RedBias, GreenBias, BlueBias -255 – 255 0.00 Offset added after scaling, on the 8-bit scale.
Gamma (R/G/B) RedGamma, GreenGamma, BlueGamma 0.01 – 100 1.00 Gamma per channel; > 1 brightens, < 1 darkens.

Example

A slightly warmer picture (red × 1.05, blue × 0.95) on a 10-bit YUV 4:2:0 source:

# adjusting color space from YUV420P10 to YUV444P16 for vsGLSLRGBAdjust
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# adjusting colors using GLSL RGBAdjust
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/RGBAdjust.glsl") as glslf:
  glsl = glslf.read()
glsl = glsl.replace('#define RedScale 1.0', '#define RedScale 1.05')
glsl = glsl.replace('#define GreenScale 1.0', '#define GreenScale 1')
glsl = glsl.replace('#define BlueScale 1.0', '#define BlueScale 0.95')
glsl = glsl.replace('#define RedBias 0.0', '#define RedBias 0')
glsl = glsl.replace('#define GreenBias 0.0', '#define GreenBias 0')
glsl = glsl.replace('#define BlueBias 0.0', '#define BlueBias 0')
glsl = glsl.replace('#define RedGamma 1.0', '#define RedGamma 1')
glsl = glsl.replace('#define GreenGamma 1.0', '#define GreenGamma 1')
glsl = glsl.replace('#define BlueGamma 1.0', '#define BlueGamma 1')
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 RGBAdjust.glsl from its GLSL folder, writes all nine values into its #define lines 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.
  • RGBAdjust (GLSL) also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

The shader

RGBAdjust.glsl (v0.2) is an RGB adjustment shader for mpv in the same order as AviSynth's RGBAdjust. Per channel it computes c = clamp(c * Scale + Bias/255, 0, 1) and then c = clamp(pow(c, 1/Gamma), 0, 1).

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.

VapourSynth

For the CPU version see RGBAdjust.

AviSynth (RGBAdjust)

AviSynth's RGBAdjust applies gain first, then bias, then gamma (with > 1 brightening) and clips the result, like the shader; it adds analyze, dither and per-frame values. See Avisynth RGBAdjust.

Sources