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

KDE HDR makes the effects very dark #432

Closed
Kevadroz opened this issue Mar 9, 2024 · 16 comments
Closed

KDE HDR makes the effects very dark #432

Kevadroz opened this issue Mar 9, 2024 · 16 comments
Labels
bug Something isn't working contributions welcome Most likely, I will not work on this in the next couple of weeks KDE The bug is specific to KDE

Comments

@Kevadroz
Copy link

Kevadroz commented Mar 9, 2024

Describe the Bug

When HDR is enabled in Plasma 6 the effects are very very dark

Steps to reproduce the behavior:

  1. Use one of the effects
  2. Enable HDR on KDE display options
  3. open/colse a window

System

Please complete the following information:

  • Linux distribution: Arch Linux
  • Burn-My-Windows version: Hexagon from KDE Store at date 2024-02-29
  • KWin / Plasma Version: 6.0.1
@Kevadroz Kevadroz added the bug Something isn't working label Mar 9, 2024
@Schneegans
Copy link
Owner

Hi there! Thanks for the report. However, I have no way to test this on my end. Also, I tried reaching out to the KWin developers on Matrix but didn't get any reply. So I am not sure how to proceed here. I'll try to ask them again.

Since this HDR support is pretty new and still kind of experimental, it's hard to find any documentation about it. Maybe if more people start using Plasma 6 and HDR, more will experience this issue and at some point someone will show up who has the knowledge to fix it 🤔

@Schneegans Schneegans added contributions welcome Most likely, I will not work on this in the next couple of weeks KDE The bug is specific to KDE labels Mar 15, 2024
@jasonslay
Copy link

I have a framework 13 laptop (AMD) with this issue. What's interesting is that it doesn't support HDR. I'm on Arch/KDE as well and I only see this when using Wayland. When using X11 the effects look normal. Maybe this isn't purely an HDR bug?

@jasonslay
Copy link

I have a framework 13 laptop (AMD) with this issue. What's interesting is that it doesn't support HDR. I'm on Arch/KDE as well and I only see this when using Wayland. When using X11 the effects look normal. Maybe this isn't purely an HDR bug?

Disabling the color profile applied to the monitor allows the effects to work as expected. I applied the color profile following these directions so others might also have this issue.

@mmcnutt
Copy link

mmcnutt commented Jun 16, 2024

further to this bug, it is also triggered with any colour profile, not just HDR. You can trigger it by reading the profile out of your monitor in Plasma 6.1 - so with 6.1 you wont need HDR hardware to fault find this

@Zamundaaa
Copy link

If you want to make the effect support HDR, you can

  • #include "colormanagement.glsl" in your shader, which adds a whole bunch of uniforms and functions for color management
  • use sourceEncodingToNitsInDestinationColorspace(color) to convert from the source color to nits on the output
  • assume the source encoding is sRGB (non-sRGB input will be opt in for js effects, once that's supported. If the window uses HDR, KWin will map it to sRGB automatically before the shader gets it), and use sourceEncodingToNitsInDestinationColorspace(color) also for sRGB colors you're using in the shader
  • play with the brightness values if you want, you could for example make use of brightness levels up to maxDestinationLuminance for fire or things like that
  • use nitsToDestinationEncoding(color) to convert to the value KWin's framebuffer expects at the end of the shader

I also hope to make KWin automatically patch shaders from javascript effects to support color management, but that's going to take at least until Plasma 6.3.

@Schneegans
Copy link
Owner

@Zamundaaa thanks for this information! I'll see if I find an HDR screen somewhere and then I'll try to implement this.

@Zamundaaa
Copy link

You don't need an HDR screen, setting an ICC profile (in 6.1, not anymore in 6.2) makes the difference very obvious too.

@Schneegans
Copy link
Owner

I see. Can you give some insights about transparency handling? I think KWin gives source color and expects framebuffer color with premultiplied alpha. As I have to work with straight alpha (for GNOME compatibility), I have to do

vec4 fragColor = texture2D(sampler, coords);
if (fragColor.a > 0.0) {
  fragColor.rgb /= fragColor.a;
}

in the beginning and finally

fragColor = vec4(fragColor.rgb * fragColor.a, fragColor.a);

I guess sourceEncodingToNitsInDestinationColorspace has to be before the initial conversion and nitsToDestinationEncoding after the final conversion? But what shall I do to straight-alpha sRGB values I use in between? All combinations I tried so far resulted in wrong colors. Even without an ICC profile set, the colors are wrong (looks like an issue with the alpha compositing to me).

It's supposed to like this:
Screenshot_20241003_070613

But looks rather like this:
Screenshot_20241003_070800

@Schneegans
Copy link
Owner

@Zamundaaa do you have any information on this?

@Zamundaaa
Copy link

Zamundaaa commented Oct 12, 2024

I guess sourceEncodingToNitsInDestinationColorspace has to be before the initial conversion and nitsToDestinationEncoding after the final conversion?

Yes.

But what shall I do to straight-alpha sRGB values I use in between?

You also need to apply sourceEncodingToNitsInDestinationColorspace to them, so that they're in linear (nits) instead of sRGB encoding. Depending on your expectations with blending you might also need to use a non-linear blending function to combine them with values from the framebuffer.

As you can assume the source encoding to be sRGB, you could also apply your shader code first, and then only at the end do sourceEncodingToNitsInDestinationColorspace + nitsToDestinationEncoding on the final (sRGB) values instead.

@Schneegans
Copy link
Owner

@Zamundaaa Thanks! Doing both conversions at the end of the shader seems to be the best solution for now. Once GNOME supports HDR as well, I can maybe make all the shaders work in linear space. But supporting both at the same time seems hard.

Since when are these methods available? Can I include colormanagement.glsl also in Plasma 5? Or is there some GLSL preprocessor directive I could use to prevent including and using these methods in Plasma 5?

Thank you!

@Zamundaaa
Copy link

Since when are these methods available?

Plasma 6.0.

Or is there some GLSL preprocessor directive I could use to prevent including and using these methods in Plasma 5?

Not right now, but if that would help, we could add a #define that you can check for in the next bugfix release

@Schneegans
Copy link
Owner

Well, I guess it would be useful to know the KWin version in the shader sometimes. However in this case I presume that the code will sooner or later start to diverge from the Plasma 5 version anyways. So I can also start now creating two package versions, one for Plasma 5 and one for Plasma 6.

@Schneegans
Copy link
Owner

So, I added this to the latest main branch. Does anybody want to test this? Simply clone the repository and run the kwin/build.sh script. Like this:

git clone https://github.com/Schneegans/Burn-My-Windows.git
cd Burn-My-Windows
kwin/build.sh

Then the effects will be in the kwin/ directory.

@mmcnutt
Copy link

mmcnutt commented Oct 29, 2024

A quick test - these look mostly better - TV Glitch is being strange tho - sometimes it renders all white and sometimes black (transparent windows still render that blurred pane, but I understand that is a different issue).

A secondary plasma 6 issue is that the colour selection cant be used its just a grey box that does nothing - I think the widget might have changed for plasma6?

image

@Schneegans
Copy link
Owner

Ok, thanks for the feedback! I guess that these are different problems. For the color button to work, you need to install a package called KF6-kwidgetaddons-devel or similar, depending on your distribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contributions welcome Most likely, I will not work on this in the next couple of weeks KDE The bug is specific to KDE
Projects
None yet
Development

No branches or pull requests

5 participants