Using libplacebo in Vapoursynth, I thought I try to create an alternative to Levels() and ended up with:
using:Code://!HOOK MAIN //!BIND HOOKED //!DESC Levels // Define levels adjustment parameters #define input_low 16.0 #define input_high 235.0 #define gamma 1.0 #define output_low 0.0 #define output_high 255.0 /* A comprehensive Levels adjustment shader for mpv Similar to AviSynth Levels filter v0.1 */ vec4 hook() { vec4 color = HOOKED_texOff(0); // Normalize input parameters to [0, 1] range float input_low_norm = input_low / 255.0; float input_high_norm = input_high / 255.0; float output_low_norm = output_low / 255.0; float output_high_norm = output_high / 255.0; // Apply input low/high levels color.rgb = (color.rgb - input_low_norm) / (input_high_norm - input_low_norm); color.rgb = clamp(color.rgb, 0.0, 1.0); // Apply gamma correction using 1/gamma color.rgb = pow(color.rgb, vec3(1.0 / gamma)); // Apply output low/high levels color.rgb = color.rgb * (output_high_norm - output_low_norm) + output_low_norm; return color; }
which properly changes the defines to:Code:clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, range_s="limited") 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 16') glsl = glsl.replace('#define output_high 255.0', '#define output_high 235') glsl = glsl.replace('#define gamma 1.0', '#define gamma 1') clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
I expected the in- and output to be identical, but there seems to be a mistake, since the lower values all get clamped.Code:#define input_low 16 #define input_high 235 #define gamma 1 #define output_low 16 #define output_high 235
Does anyone see the mistake I made?
I suspect I made a logical mistake in the scaling of the input parameters,..
Cu Selur
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays!
+ Reply to Thread
Results 1 to 2 of 2
Thread
-
Last edited by Selur; 13th Jul 2024 at 02:01.
users currently on my ignore list: deadrats, Stears555 -
Suspecting that the issue to early clamping, I used:
Code:vec4 hook() { vec4 color = HOOKED_texOff(0); // Normalize input and output parameters to [0, 1] range float input_low_norm = input_low / 255.0; float input_high_norm = input_high / 255.0; float output_low_norm = output_low / 255.0; float output_high_norm = output_high / 255.0; // Apply input low/high levels vec3 normalized = (color.rgb - input_low_norm) / (input_high_norm - input_low_norm); // Apply gamma correction using 1/gamma vec3 gamma_corrected = pow(normalized, vec3(1.0 / gamma)); // Apply output low/high levels vec3 adjusted_output = gamma_corrected * (output_high_norm - output_low_norm) + output_low_norm; // Ensure values are within the [0, 1] range color.rgb = clamp(adjusted_output, 0.0, 1.0); return color; }
=> that looks different, but still wrong.
Cu Selurusers currently on my ignore list: deadrats, Stears555
Similar Threads
-
PotPlayer shader : Smart Vibrance
By Baudelare in forum Software PlayingReplies: 3Last Post: 16th May 2024, 19:44 -
add a saturation condition to a glsl shader
By geextah_2 in forum Software PlayingReplies: 7Last Post: 5th May 2024, 04:59 -
Pixel-shaders for video playback (.hlsl, .glsl)
By butterw in forum Software PlayingReplies: 41Last Post: 2nd Apr 2024, 15:21 -
HLSL SBS 3D shader filter
By Космик in forum Software PlayingReplies: 30Last Post: 3rd Oct 2020, 17:41 -
How to use 'mpv -vf=pp' ?
By Selur in forum Newbie / General discussionsReplies: 1Last Post: 1st Mar 2020, 09:08