loqusion / hyprshade

Hyprland shader configuration tool
MIT License
280 stars 7 forks source link

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

Open MCPO-Spartan-117 opened 4 months ago

MCPO-Spartan-117 commented 4 months ago

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.

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 commented 4 months ago

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

loqusion commented 4 months ago

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 commented 4 months ago

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 commented 1 month ago

https://github.com/hyprwm/Hyprland/issues/4377#issuecomment-2309964751

babul09 commented 2 weeks ago

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);

}`