VideoHelp Forum
+ Reply to Thread
Results 1 to 8 of 8
Thread
  1. Member
    Join Date
    Mar 2024
    Location
    germany
    Search Comp PM
    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; 
    }
    Quote Quote  
  2. 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;
    }
    Quote Quote  
  3. Member
    Join Date
    Mar 2024
    Location
    germany
    Search Comp PM
    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.
    Quote Quote  
  4. Any error messages?
    Quote Quote  
  5. Member
    Join Date
    Mar 2024
    Location
    germany
    Search Comp PM
    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"
    Image
    [Attachment 78736 - Click to enlarge]

    This is the normal image without any shaders or when I run the shader with your tweaks
    Image
    [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
    Image
    [Attachment 78738 - Click to enlarge]
    Last edited by geextah_2; 30th Apr 2024 at 11:23.
    Quote Quote  
  6. Member
    Join Date
    Mar 2024
    Location
    germany
    Search Comp PM
    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.
    Quote Quote  
  7. Sorry, I had lost this thread.

    Give me a day or two to look into the HDR issue.
    Quote Quote  
  8. Member
    Join Date
    Mar 2024
    Location
    germany
    Search Comp PM
    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;
    }
    Here you can see the comparison

    Hard edge
    Image
    [Attachment 78852 - Click to enlarge]


    Smooth
    Image
    [Attachment 78853 - Click to enlarge]
    Last edited by geextah_2; 5th May 2024 at 07:20.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!