Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3DLUT shader as an temporary solution for Color Management for hyprland #38

Open
MCPO-Spartan-117 opened this issue May 31, 2024 · 6 comments

Comments

@MCPO-Spartan-117
Copy link

MCPO-Spartan-117 commented May 31, 2024

I'm surprised no one has made a 3DLUT shader using a PNG like Reshade, libretro or some art applications like i think blender as a compromise until Color Management actually reaches wayland/hyprland/AMDGPU, this of course has the downside of being on all monitors until hyprland's shader API gets more developed but a option is better than none.

  • This'll probably be better in some ways as i believe the AMDGPU Display Core driver will be limited to 9^3 or 17^3 ICCs, far from the biggest which is 65^3(in DisplayCAL, though this is probably overkill by a huge margin),

    • These ICCs don't have any color correction just gamma correction(at least the "2DLUTs" made by Displaycal/Argyllcms), You can make 3DLUTs that have the color correction in a ICC format but argyll-dispwin(argyllcms tool to apply ICCs to X11) won't apply them because they are missing a vgt tag so this'll be a benefit over X11 too.
  • You could make an arbitrary PNG in a 3DLUT format to apply whatever colors you want if you wanted to for some reason.

Currently this is the only thing holding me back from using wayland/hyprland and it'd be nice to at least see some solution for it, even if i have to do it myself but i'd need some pointers as i know nothing of GLSL, if this requires some C or other backend code or how i'd integrate it into hyprshade(if needed).

@gnusenpai
Copy link

I believe Hyprland is supposed to support per-output shaders (see hyprwm/Hyprland#2485), but I couldn't get it to work, maybe it's a bug.

@loqusion
Copy link
Owner

loqusion commented Jun 1, 2024

So to clarify, what is a 3DLUT shader? Does this blog post describe what you're looking to implement? What is the appeal of this over, say, writing shaders by hand? Is this a feature that makes "color management shaders" (for lack of a better term) easier?

@MCPO-Spartan-117
Copy link
Author

MCPO-Spartan-117 commented Jun 1, 2024

Yes, that blog post sums PNG 3DLUTs up.

It allows using a standard format for color/gamma correction (or color modification if you'd like), things like Reshade, LibRetro, Blender and apparently Gimp can use PNGs, Gimp can also use ICCs, Displaycal/Argyllcms can make PNG and other 3DLUT formats such as

2024-06-01_02-50

PNGs are typically used, but these other formats could be used if they're easier, though maybe harder to modify.

Writing a shader by hand for the purpose of accurate color/gamma correction for your display would be tricky without data that a colorimeter/spectrometer provides, espically when displays can be like this

https://www.youtube.com/watch?v=QGIsvXa4zGg&t=11m12s
mpv-shot0022
Or
https://www.youtube.com/watch?v=ItPCOFR5xuU&t=13m35s
mpv-shot0006
They're probably worse examples

And if you do have one it'd be much easier to make a 3DLUT than to manually make a shader with that data, especially if you making one with a HDR gamma curve.

@MCPO-Spartan-117
Copy link
Author

@babul09
Copy link

babul09 commented Sep 21, 2024

Just a novice user here with a shitty laptop screen. I have an icc calibration file for my laptop but i am no expert in creating a shader. I tried to implement a basic fragment shader with the help of chatgpt, but it dosent work properly, although it did shift the white point of my screen. Here is the shader chatgpt cooked based on the icc dump data i provided it.

`#version 100

precision mediump float;

uniform sampler2D tex;

// Color transformation matrix
const mat3 colorMatrix = mat3(
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0
);

// Gamma correction value (from rTRC, gTRC, bTRC)
const float gamma = 2.1953125;

vec3 applyColorMatrix(vec3 color) {
return colorMatrix * color;
}

vec3 applyGammaCorrection(vec3 color) {
return pow(color, vec3(gamma));
}

void main() {
// Generate texture coordinates from fragment position
vec2 texCoord = gl_FragCoord.xy / vec2(1920.0, 1080.0); // Adjust these values to your screen resolution

vec4 texColor = texture2D(tex, texCoord);
vec3 correctedColor = applyColorMatrix(texColor.rgb);
correctedColor = applyGammaCorrection(correctedColor);
gl_FragColor = vec4(correctedColor, texColor.a);

}`

@MCPO-Spartan-117
Copy link
Author

@babul09
@gnusenpai Now supports 1DLUTs.
hyprwm/Hyprland#4377 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants