mpv icon indicating copy to clipboard operation
mpv copied to clipboard

looking for st2094-10 glsl shader

Open geextahslex opened this issue 1 year ago • 17 comments

does someone have or know where to find the st2094-10 shader as glsl? I know that it is already implemented in mpv.

Thank you for any help

geextahslex avatar Feb 08 '24 15:02 geextahslex

st2094-10 in mpv is not a shader, it's C code:

https://code.videolan.org/videolan/libplacebo/-/blob/master/src/tone_mapping.c?ref_type=heads#L418

haasn avatar Feb 08 '24 17:02 haasn

would it be possible to convert it into a glsl shader?

geextahslex avatar Feb 09 '24 14:02 geextahslex

Of course, it's just code. What do you need it for?

haasn avatar Feb 09 '24 14:02 haasn

I need it for https://github.com/natural-harmonia-gropius/hdr-toys, his pipeline is build (works best) with shaders. There are shaders for: reinhard, bt2446c, bt2390 etc. but obviously st2094-10 is missing, and it's my favourite one ^^

geextahslex avatar Feb 09 '24 14:02 geextahslex

cc @natural-harmonia-gropius

haasn avatar Feb 09 '24 20:02 haasn

would it be possible to convert it into a glsl shader? Of course, it's just code.

Thank you.

@geextahslex the shader is here, but no st2094_pick_knee(), you need to modify x2 and y2 manually.

//!PARAM L_hdr
//!TYPE float
//!MINIMUM 0
//!MAXIMUM 10000
1000.0

//!PARAM L_sdr
//!TYPE float
//!MINIMUM 0
//!MAXIMUM 1000
203.0

//!PARAM CONTRAST_sdr
//!TYPE float
//!MINIMUM 0
//!MAXIMUM 1000000
1000.0

//!HOOK OUTPUT
//!BIND HOOKED
//!DESC tone mapping (st 2094-10)

const vec3 RGB_to_Y = vec3(0.2627002120112671, 0.6779980715188708, 0.05930171646986196);

float curve(float x) {
    float x1 = 0.0;
    float x2 = 0.7;
    float x3 = L_hdr / L_sdr;

    float y1 = 1.0 / CONTRAST_sdr;
    float y2 = 0.18;
    float y3 = 1.0;

    float a = 1.0 / (x3 * y3 * (x1 - x2) + x2 * y2 * (x3 - x1) + x1 * y1 * (x2 - x3));

    mat3 cmat = mat3(
        x2 * x3 * (y2 - y3), x1 * x3 * (y3 - y1), x1 * x2 * (y1 - y2),
        x3 * y3 - x2 * y2  , x1 * y1 - x3 * y3  , x2 * y2 - x1 * y1  ,
        x3 - x2            , x1 - x3            , x2 - x1
    );

    vec3 coeffs = vec3(y1, y2, y3) * cmat * a;

    float c1 = coeffs.r;
    float c2 = coeffs.g;
    float c3 = coeffs.b;

    return (c1 + c2 * x) / (1.0 + c3 * x);
}

vec3 tone_mapping_y(vec3 RGB) {
    float y = dot(RGB, RGB_to_Y);
    return RGB * curve(y) / y;
}

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

    color.rgb = tone_mapping_y(color.rgb);

    return color;
}

Thank you, I played around with the settings. But there are oversaturated shadows, like in the screenshots blue tint and there is artifacting on the letterbox. (both L_sdr=150) reinhard (black_point_compensation /bottosson) reinhard myk

2094 (y2=0.40) ((no black_point_compensation /bottosson) reinhard 2094

I like the luminance but the color feels of reinhard hgghhggh

2094 fgfgfgfg

reinhard reini

this should be black but its green ^^ 2094 2094fff

geextahslex avatar Feb 11 '24 13:02 geextahslex

Try the updated one st2094-10, this set x2 and y2 automatically.

I will check artifacts in dark area later. image

I looked into it Ahsoka improved, I think the red seats should desaturate even more to get closer to reinhard. There is a green tint in the blacks 2094 new3

You can see the green tint here, I boosted gamma by 50 to make it more visible. Reinhard also turns green eventually but its not noticable without any gamma boost. 2094 new3 green

Here the blue tint stayed the same, it should be blue but less (see reinhard screenshot) 2094 new

And the artifacting on the letterbox is fixed Overall nice improvements Hopefully it can be later added to the portfolio ^^

geextahslex avatar Feb 12 '24 00:02 geextahslex

tint

I committed changes, update it.

https://www.desmos.com/calculator/vjruzaxez0 curve here, you could draw reinhard with bpc your self for comparison.

Okay so I don't know why, the picture gets much darker now.

sigma0.5 here its the same picture as before but much darker sigma 1 0 x fff

sigma1.0 fixed the green tint in the shadow in the seat sigma 1 0 x ddd

sigma1.0 it feels the same as before, but it is darker now sigma 1 0 x

geextahslex avatar Feb 12 '24 11:02 geextahslex

but much darker

try to change this value to 0.01 or 0.005 image

Okay it's brighter now, still a notch darker than yesterday but the seats look better now, color like reinhard :)

mckey

geextahslex avatar Feb 12 '24 12:02 geextahslex

0.001 also works fine

geextahslex avatar Feb 12 '24 12:02 geextahslex

OK, I updated them to 1.0 and 0.001

okay I feel like it's desaturated too much, the lights are no longer red

reinhard reino 00

2094 2094 latest

here you can see it's almost greyscale 2094 2094 latest x

reinhard is maybe too saturated, I think something between them both would work the best reinhard reinii

geextahslex avatar Feb 12 '24 12:02 geextahslex

I think something between them both would work the best

adjust sigma, back to 0.5 or try another value.