bjin / mpv-prescalers

prescalers for mpv, as user shaders
GNU Lesser General Public License v3.0
362 stars 33 forks source link

vibrance shader glsl #61

Closed geextahslex closed 6 months ago

geextahslex commented 6 months ago

Hi I use this shader to desaturate dark colors in mpv. I want to make something similar but with vibrance instead of saturation. Can you help me out with that? Thank you :)

//!PARAM Strength
//!DESC Desat Strength
//!TYPE float
//!MINIMUM 0
//!MAXIMUM 1
1

//!HOOK MAIN
//!BIND HOOKED
//!DESC Desaturation smooth

#define Thresh 35/255.
#define w 10/255.
#define CoefLuma vec4(0.2126, 0.7152, 0.0722, 0) //sRGB, HDTV

/* simple threshold with mpv glsl
Strength*desaturation [0 to1.0], 0: full color, 1: grayscale.
*/

vec4 hook()  {
   vec4 c0 = HOOKED_texOff(0);
   float desaturation = smoothstep(Thresh + w, Thresh - w, dot(c0, CoefLuma));
   // return vec4(desaturation, 1);
   c0.rgb = mix(c0.rgb, vec3(dot(c0, CoefLuma)), Strength*desaturation);

   return c0;
}
Rebelradio1 commented 6 months ago

``//!PARAM Strength //!DESC Desat Strength //!TYPE float //!MINIMUM 0 //!MAXIMUM 1 1

//!HOOK MAIN //!BIND HOOKED //!DESC Desaturation smooth

define Thresh 35./255.

define w 10./255.

define CoefLuma vec4(0.2126, 0.7152, 0.0722, 0) //sRGB, HDTV

extension GL_KHR_memory_scope_semantics: enable

/ desaturate vibrance with smoothstep / vec4 hook() { vec4 c0 = HOOKED_texOff(0); float vibrance = 1.0 - smoothstep(Thresh - w, Thresh + w, dot(c0, CoefLuma));

c0.rgb = mix(vec3(dot(c0, CoefLuma)), c0.rgb, Strength*vibrance);

return c0;

} ``

I did my best on it and it seems to work well when I play my videos. Hope this helps

geextahslex commented 6 months ago

Thanks for your response. I tried it, it seems to effect the whole image and is not respecting the treshold. You can try this one out.

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

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

#define CoefLuma vec4(0.2126, 0.7152, 0.0722, 0) //sRGB, HDTV
float Thresh = 45.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;
}
Rebelradio1 commented 6 months ago

Yep, after more testing, I could not test it long at work yours works better. 😀