Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLSL Shader problem,.. (is it a bug or am I doing something wrong?) #48

Open
Selur opened this issue Jul 26, 2024 · 3 comments
Open

GLSL Shader problem,.. (is it a bug or am I doing something wrong?) #48

Selur opened this issue Jul 26, 2024 · 3 comments

Comments

@Selur
Copy link

Selur commented Jul 26, 2024

Using:

//!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 16.0
#define output_high 235.0
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);
   
   // Ensure values are within the [0, 1] range before gamma correction
   normalized = clamp(normalized, 0.0, 1.0);
   // 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;
}

through:

# Imports
import vapoursynth as vs
# getting Vapoursynth core
import sys
import os
core = vs.core
# Import scripts folder
scriptPath = 'F:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))
# loading plugins
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
# Import scripts
import validate
# Source: 'G:\TestClips&Co\files\test.avi'
# Current color space: YUV420P8, bit depth: 8, resolution: 640x352, frame rate: 25fps, scanorder: progressive, yuv luminance scale: limited, matrix: 470bg
# Loading G:\TestClips&Co\files\test.avi using LWLibavSource
clip = core.lsmas.LWLibavSource(source="G:/TestClips&Co/files/test.avi", format="YUV420P8", stream_index=0, cache=0, prefer_hw=0)
frame = clip.get_frame(0)
# Setting detected color matrix (470bg).
clip = core.std.SetFrameProps(clip=clip, _Matrix=5)
# setting color transfer (170), if it is not set.
if validate.transferIsInvalid(clip):
  clip = core.std.SetFrameProps(clip=clip, _Transfer=6)
# setting color primaries info (to 470), if it is not set.
if validate.primariesIsInvalid(clip):
  clip = core.std.SetFrameProps(clip=clip, _Primaries=5)
# setting color range to TV (limited) range.
clip = core.std.SetFrameProps(clip=clip, _ColorRange=1)
# making sure frame rate is set to 25fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
# making sure the detected scan type is set (detected: progressive)
clip = core.std.SetFrameProps(clip=clip, _FieldBased=0) # progressive
# adjusting color space from YUV420P8 to YUV444P16 for vsGLSLLevels
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()
clip = core.placebo.Shader(clip=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, range_s="limited", dither_type="error_diffusion")
# set output frame rate to 25fps (progressive)
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
# output
clip.set_output()

I expected the filtered and the unfiltered version to be identical, which they are not.
difference
Is there a bug in vs-placebo? Am I using it wrong? Is there a bug in my shader code?

@quietvoid
Copy link
Collaborator

I don't know? You could always try using the shader in mpv.

@Asd-g
Copy link

Asd-g commented Jan 14, 2025

//!HOOK MAIN means the shader is applied on RGB input and not on YUV (as supposed by the shader code).

@Selur
Copy link
Author

Selur commented Jan 15, 2025

So the shader needs to me rewritten to assume YUV input to work with placebo.Shader or is there a mistake in the shader that it doesn't work with RGB as intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants