libretro / glsl-shaders

This repo is for glsl shaders converted by hand from libretro's common-shaders repo, since some don't play nicely with the cg2glsl script.
911 stars 223 forks source link

how to limit this shader effect to 0-40srgb? #454

Closed geextahslex closed 3 months ago

geextahslex commented 3 months ago

Hi, could someone be so nice and help me to put a srgb treshold (smoothstep) into this shader? This is a S-Curve (sigmoid) contrast shader. I would like to apply the effect only in the sRGB 0-40/80(smoothstep) range

#define Thresh 15/255.
#define w 10/255.
#define CoefLuma vec4(0.2126, 0.7152, 0.0722, 0) //sRGB, HDTV
smoothstep(Thresh + w, Thresh - w)

S-Curve

//!HOOK OUTPUT
//!BIND HOOKED
//!DESC sCurve (sigmoid)

#define S 0.25 

vec4 hook(){
    vec4 c0 = HOOKED_texOff(0);

    c0.rgb = mix(c0.rgb, 1/( 1.0 + exp(-14*c0.rgb +7) ), S);
    return c0; 
}

Thank you :)

hizzlekizzle commented 3 months ago

I pitched this to our shader-programming channel in discord and this was guest.r's take: image So, go ahead and calculate both with and without the effect, then mix between with the smoothstepped mix-factor.

geextahslex commented 3 months ago

Thanks for your answer. I know the "theory" but I need proper code that works ^^' I also use discord, maybe I could join the conversation

hizzlekizzle commented 3 months ago

sure, come on down :)

https://discord.com/invite/VZ2b7wghxR #programming-shaders

geextahslex commented 3 months ago

Thank you :) I'm not sure in which category my question would make sense? ^^' Official Software channels->help?

geextahslex commented 3 months ago

Solved:

//!HOOK LUMA
//!BIND HOOKED
//!DESC sCurve (sigmoid)

#define EFFECT_END             vec3(40.0) // stop applying the effect here
#define EFFECT_END_RAMP_SIZE   vec3(10.0) // smooth out the edge of the effect

#define S vec3(0.15)

vec4 hook()  {
    vec4 orig = HOOKED_tex(HOOKED_pos);
    vec3 effect = mix(orig.rgb, 1/( 1.0 + exp(-14*orig.rgb +7) ), S); //your desidered effect.

    //effect = vec3(0.0); 

    vec3 mmix = smoothstep(EFFECT_END - EFFECT_END_RAMP_SIZE*0.5, 
                           EFFECT_END + EFFECT_END_RAMP_SIZE*0.5, 
                           orig.rgb * 255.0);

    vec3 out_color = mix(effect, orig.rgb, mmix);

    return vec4(out_color, orig.a);

}