mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
26.85k stars 2.84k forks source link

looking for st2094-10 glsl shader #13442

Closed geextahslex closed 3 months ago

geextahslex commented 5 months ago

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

haasn commented 5 months ago

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

geextahslex commented 5 months ago

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

haasn commented 5 months ago

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

geextahslex commented 5 months ago

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 ^^

haasn commented 5 months ago

cc @natural-harmonia-gropius

natural-harmonia-gropius commented 5 months ago

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;
}
geextahslex commented 5 months ago

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

natural-harmonia-gropius commented 5 months ago

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

I will check artifacts in dark area later. image

geextahslex commented 5 months ago

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 ^^

natural-harmonia-gropius commented 5 months ago

tint

I committed changes, update it.

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

geextahslex commented 5 months ago

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

natural-harmonia-gropius commented 5 months ago

but much darker

try to change this value to 0.01 or 0.005 image

geextahslex commented 5 months ago

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

mckey

geextahslex commented 5 months ago

0.001 also works fine

natural-harmonia-gropius commented 5 months ago

OK, I updated them to 1.0 and 0.001

geextahslex commented 5 months ago

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

natural-harmonia-gropius commented 5 months ago

I think something between them both would work the best

adjust sigma, back to 0.5 or try another value.