Hi, I have this vibrance shader, It has an srgb threshold which can be adjusted. But the shader affects all saturation levels/%. I would like to leave colors that have a saturation under 80% unaffected, and target the above 90% saturation pixels, with a smooth transition between them (80-90%). So the first condition is the srgb threshold and the 2nd condition would be the pixel saturation. From my understanding this shader already checks saturation levels but I don't know how this works. Any help would be appreciated![]()
side note: I don't understand shaders, I just want to make this one adjustment.
Code://!PARAM vibr //!DESC Saturates/deSaturates //!TYPE float //!MINIMUM -1 -0.3 //!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; }
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays!
+ Reply to Thread
Results 1 to 8 of 8
Thread
-
-
Start with something like this and go from there:
//!PARAM vibr
//!DESC Saturates/deSaturates
//!TYPE float
//!MINIMUM -1
-0.3
//!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);
// Calculate saturation of the pixel's color
float colorSat = max(max(c0.r, c0.g), c0.b) - min(min(c0.r, c0.g), c0.b);
// Check if saturation is above 90%
if (colorSat > 0.9) {
// Calculate luminance
float lum = dot(c0.rgb, CoefLuma.rgb);
// Calculate smoothstep value for transition between 80-90% saturation
float smoothstepValue = smoothstep(0.8, 0.9, colorSat);
// Calculate the adjusted saturation
vec3 adjustedSaturation = mix(vec3(dot(c0.rgb, CoefLuma.rgb)), c0.rgb, 1.0 + vibr - colorSat * abs(vibr));
// Apply the effect with smooth transition
c0.rgb = mix(c0.rgb, adjustedSaturation, smoothstepValue);
}
else if (colorSat < 0.8) {
// Leave colors with saturation under 80% unaffected
return c0;
}
// Calculate luminance
float lum = (c0.r + c0.g + c0.b) / 3.0;
float delta = smoothstep(Thresh - w, Thresh + w, lum);
c0.rgb = mix(vec3(dot(c0.rgb, CoefLuma.rgb)), c0.rgb, 1.0 + vibr - colorSat * abs(vibr));
c0.rgb = mix(c0.rgb, c0.rgb, delta);
return c0;
} -
Thank you for your answer. I tried this out and there is no effect visible. The shader is running but I guess something is not working properly.
-
No, I use this in mpv, it is not capable of showing any error messages. But if there would be a code error, the shader wouldn't load at all. The shader is loaded and runs in the pipeline but there is no visible change/effect to the image.
Here are some screenshots so you have a visual representation of what we are talking about
This is how the shader worked before your tweaks, it targets the set srgb threshold "float Thresh = 45.0/255.0"
[Attachment 78736 - Click to enlarge]
This is the normal image without any shaders or when I run the shader with your tweaks
[Attachment 78737 - Click to enlarge]
Here you can see the saturation of the suit, it's at 98%, so it shuld be affected by the shader
[Attachment 78738 - Click to enlarge]Last edited by geextah_2; 30th Apr 2024 at 11:23.
-
Sorry, it works. I tested it with an HDR file instead of SDR, my bad. Do you know why it isn't working on HDR? The original shader worked on both.
Last edited by geextah_2; 2nd May 2024 at 06:04.
-
Sorry, I had lost this thread.
Give me a day or two to look into the HDR issue. -
No problem. That would be awesome, thank you
This is an improved version, with less hard edges, better smoothstep
Code://!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); sat = mix(sat, c0.rgb, delta); delta = smoothstep(0.8, 0.9, colorSat); c0.rgb = mix(c0.rgb, sat, delta); return c0; }
Hard edge
[Attachment 78852 - Click to enlarge]
Smooth
[Attachment 78853 - Click to enlarge]Last edited by geextah_2; 5th May 2024 at 07:20.
Similar Threads
-
Pixel-shaders for video playback (.hlsl, .glsl)
By butterw in forum Software PlayingReplies: 41Last Post: 2nd Apr 2024, 15:21 -
ffmpeg IF .bat condition on channel count and language
By geextah_2 in forum Video ConversionReplies: 3Last Post: 18th Mar 2024, 06:04 -
Vapoursynth CPU saturation
By meimeiriver in forum EditingReplies: 4Last Post: 27th Jan 2022, 22:51 -
HLSL SBS 3D shader filter
By Космик in forum Software PlayingReplies: 30Last Post: 3rd Oct 2020, 17:41