Artoriuz / ArtCNN

Super-Resolution Convolutional Neural Networks as GLSL shaders for mpv
MIT License
109 stars 2 forks source link

why this glsl shader isn't working on hdr content? #17

Closed geextahslex closed 3 months ago

geextahslex commented 3 months ago

Hi. Could you help me out with this shader? I'm struggling with it since months... ^^ TLDR: Do you know why this works on SDR but isn't on HDR? The original shader worked on both and only 3 lines of code have changed... I marked them at the end

more info: This is a vibrance shader that has 2 conditions. The first one is the srgb threshold float Thresh = 200.0/255.0; the 2nd one is the saturation of the pixel delta = smoothstep(0.8, 0.9, colorSat); What I found out is that if the first number is higher than the 2nd one delta = smoothstep(0.3, 0.2, colorSat);, then you can see some changes but this isn't working as expected. This saturation condition is somehow broken.

By "isn't working" I mean that it visually doesn't change anything. The shader is working in the pipeline but there is no visible effect.

Thank you :)

//!PARAM vibr
//!DESC Saturates/deSaturates
//!TYPE float
//!MINIMUM -1
-0.5

//!HOOK MAIN
//!BIND HOOKED
//!DESC Vibrance

#define CoefLuma vec4(0.2126, 0.7152, 0.0722, 0) //sRGB, HDTV
float Thresh = 200.0/255.0;
float w = 10.0/255.0;

vec4 hook() {
    vec4 c0 = HOOKED_texOff(0);
    float lum = (c0.r + c0.g + c0.b)/3.0;

    float colorSat = max(max(c0.r, c0.g), c0.b) - min(min(c0.r, c0.g), c0.b); 
    vec3 sat = mix(vec3(dot(c0, CoefLuma)), c0.rgb, 1+vibr - colorSat*abs(vibr));
    float delta = smoothstep(Thresh-w, Thresh+w, lum);
1   sat = mix(sat, c0.rgb, delta);
2   delta = smoothstep(0.8, 0.9, colorSat);
3   c0.rgb = mix(c0.rgb, sat, delta);
    return c0;
}

The original shader, works on SDR and HDR

//!PARAM vibr
//!DESC Saturates/deSaturates
//!TYPE float
//!MINIMUM -1
-0.5

//!HOOK MAIN
//!BIND HOOKED
//!DESC Vibrance

#define CoefLuma vec4(0.2126, 0.7152, 0.0722, 0) //sRGB, HDTV
float Thresh = 200.0/255.0;
float w = 10.0/255.0;

vec4 hook() {
vec4 c0 = HOOKED_texOff(0);
float lum = (c0.r + c0.g + c0.b)/3.0; 

float colorSat = max(max(c0.r, c0.g), c0.b) -min(min(c0.r, c0.g), c0.b); // >=0, 5 arithmetic
vec3 sat = mix(vec3(dot(c0, CoefLuma)), c0.rgb, 1+vibr -colorSat*abs(vibr));
float delta = smoothstep( Thresh-w, Thresh+w, lum);
c0.rgb = mix( sat, c0.rgb, delta);
return c0;
}