Schneegans / Burn-My-Windows

🔥 Disintegrate your windows with style.
GNU General Public License v3.0
2.65k stars 76 forks source link

Some effects have black rectangle around/behind them #272

Closed daudix closed 1 year ago

daudix commented 1 year ago

Describe the Bug

Some effects have a black rectangle around the effect, it looks like it's missing alpha, does not happen for maximized windows, happens in both Wayland and Xorg

Effects affected:

This does not happen in virtual machine (GNOME Boxes) with disabled 3D acceleration

I don't have NVIDIA or any other dedicated GPU

Seems to be similar to #199

Kooha-2023-01-07-15-45-15.webm

Steps to reproduce the behavior:

  1. Apply Fire effect for opening/closing windows
  2. Open/Close some windows
  3. See weird black rectangle around window

Some logs (opening/closing nautilus)

systemd-hostnamed.service: Deactivated successfully.
SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=systemd-hostnamed comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
BPF prog-id=0 op=UNLOAD
BPF prog-id=0 op=UNLOAD
BPF prog-id=0 op=UNLOAD
JS ERROR: TypeError: workspace is undefined
_getSpacing@resource:///org/gnome/shell/ui/workspacesView.js:213:13
vfunc_allocate@resource:///org/gnome/shell/ui/workspacesView.js:339:18
vfunc_allocate@resource:///org/gnome/shell/ui/overviewControls.js:214:33
_updateWorkspacesViews@resource:///org/gnome/shell/ui/workspacesView.js:1026:38
prepareToEnterOverview@resource:///org/gnome/shell/ui/workspacesView.js:993:14
prepareToEnterOverview@resource:///org/gnome/shell/ui/overviewControls.js:720:33
gestureBegin@resource:///org/gnome/shell/ui/overviewControls.js:782:14
_gestureBegin@resource:///org/gnome/shell/ui/overview.js:358:33
_beginGesture@resource:///org/gnome/shell/ui/swipeTracker.js:603:14
_handleEvent@resource:///org/gnome/shell/ui/swipeTracker.js:170:26

Started app-gnome-org.gnome.design.IconLibrary-33044.scope - Application launched by gnome-shell.
Started app-flatpak-org.gnome.design.IconLibrary-33044.scope.
meta_window_set_stack_position_no_sync: assertion 'window->stack_position >= 0' failed
app-flatpak-org.gnome.design.IconLibrary-33044.scope: Consumed 5.292s CPU time.
Started dbus-:1.2-org.gnome.Nautilus@19.service.
Started dbus-:1.2-org.gnome.DiskUtility@19.service.
BPF prog-id=112 op=LOAD
BPF prog-id=113 op=LOAD
BPF prog-id=114 op=LOAD
Starting systemd-hostnamed.service - Hostname Service...
meta_window_set_stack_position_no_sync: assertion 'window->stack_position >= 0' failed
SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=systemd-hostnamed comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Started systemd-hostnamed.service - Hostname Service.

System

Hardware

Schneegans commented 1 year ago

Hey there! Thanks for the report, it seems to be indeed the same issue as #199. As I cannot reproduce this on my end, we would have to try to fix this on your end. Do you feel confident editing some GLSL shaders? Then I could give you a step-by-step guide on how to proceed :smile:

daudix commented 1 year ago

I can try )

daudix commented 1 year ago

Alright, I have looked at the shaders and I can do nothing with them, sadly

The only simple way you can reproduce this on your end is a VM with 3D acceleration, GNOME Boxes and Fedora work nice together and it have 3D acceleration option

Schneegans commented 1 year ago

I cannot reproduce this. It neither happens in a virtual machine (with and without hardware acceleration) nor in the continuous integration jobs which test all the effects on various Fedora versions on every commit. Hence, I would guess that it is quite closely related to the involved hardware...

But maybe we can test this on your end anyways. I'll send you some instructions later today!

daudix commented 1 year ago

Thanks!

Schneegans commented 1 year ago

Alright, will add some debugging output to the shaders and see if we can deduce something. Here are the required steps (if you need a more detailed explanation at some point, feel free to ask!):

  1. Clone the Burn-My-Windows repository. To do this, open a terminal, change to a directory where you want the source code of the extension and execute these commands:

    git clone https://github.com/Schneegans/Burn-My-Windows.git
    cd Burn-My-Windows
  2. Now you will have to install the extension. This command compiles the locales, schemas and resources, creates a zip file of the extension and finally installs it with the gnome-extensions tool:

    make install
  3. Now logout / login to fully reload the new version of the extension.
  4. Confirm that everything works by opening the settings dialog of the extension. It should show that you are running Burn-My-Windows 24 (previously it was 23). There should also be a new "Glitch" effect :wink:.
  5. Now open the file <Burn-My-Windows directory>/resources/shaders/common.glsl with a text editor.
  6. Replace this line with this code:

    bool isnan(float val) {
      return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;
    }
    
    bvec4 isnan(vec4 val) {
      return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
    }
    
    void setOutputColor(vec4 outColor) {
    
      // Return red if any RGBA component is NaN.
      if (any(isnan(outColor))) {
        cogl_color_out = vec4(1.0, 0.0, 0.0, 1.0);
        return;
      }
    
      // Return yellow if any RGBA component greater than 1.0.
      if (any(greaterThan(outColor, vec4(1.0)))) {
        cogl_color_out = vec4(1.0, 1.0, 0.0, 1.0);
        return;
      }
    
      // Return green if all RGBA components are zero.
      if (all(equal(outColor, vec4(0.0)))) {
        cogl_color_out = vec4(0.0, 1.0, 0.0, 1.0);
        return;
      }
    
      // Return blue if alpha component is zero.
      if (outColor.a == 0.0) {
        cogl_color_out = vec4(0.0, 0.0, 1.0, 1.0);
        return;
      }
    
      cogl_color_out = outColor;
    }
  7. Execute again:
    make install
  8. Then restart GNOME Shell with Alt + F2, r + Enter if you are on X11 or logout / login if you are on Wayland.
  9. If you now preview the effects, there should be funky colors going on. Please tell me the color of the areas which were previously black. Are they still black? Or do they have a different color now?

If you want to revert the changes, simply execute this commands for now:

cd <Burn-My-Windows directory>
git checkout resources/shaders/common.glsl
make install

And finally restart GNOME Shell with Alt + F2, r + Enter if you are on X11 or logout / login if you are on Wayland.

I hope that we can figure this out... thanks for your support!

daudix commented 1 year ago

Thank you for detailed guide, I really appreciate it!

Yep, colors have changed, black rectangle is now blue in most effects ("Incinerate" have additional yellow color)

Kooha-2023-01-08-15-56-10.webm

Schneegans commented 1 year ago

Interesting :smile:.

Could you please replace the original line with this code:

void setOutputColor(vec4 outColor) {
  if (outColor.a == 0.0) {
    cogl_color_out = mix(outColor, vec4(0.0, 0.0, 1.0, 1.0), 0.99);
    return;
  }

  cogl_color_out = outColor;
}

Is it still blue? Remember to always do a make install followed by a Alt + F2, r + Enter (or logout / login if you are on Wayland) after each change.

If this is still blue, you could also try this variant:

void setOutputColor(vec4 outColor) {
  outColor.a = max(outColor.a, 0.00001);
  cogl_color_out = outColor;
}

What happens now?

daudix commented 1 year ago

Using first snippet effects that had black rectangle have black rectangle, and effects such as hexagons have blue background

Using second snippet effects that had black rectangle have black rectangle, and other effects look like normal

Schneegans commented 1 year ago

Ahh, I feared that. It seems that there is some issue in the shader code. In the first version, we have simply overridden the output color with blue. This allowed the GLSL compiler to remove basically all other code as it would not affect the final color. Hence, the buggy part was optimized out. In the second variant, we did not override the color with blue, but mixed it with 99% blue. Hence, the compiler could not remove the rest of the code and now it crashes again, resulting in black color.

Could you please list all effects which exhibit the black issues? Maybe I can spot something which all these effects have in common...

daudix commented 1 year ago

Of course! here is it

Schneegans commented 1 year ago

Thanks! I think that I found something. Could you try to replace the alphaOver function in line 123 with this version (and undo all other changes you did)?

vec4 alphaOver(vec4 under, vec4 over) {
  if (under.a == 0.0 && over.a == 0.0) {
    return vec4(0.0);
  }

  float alpha = mix(under.a, 1.0, over.a);
  return vec4(mix(under.rgb * under.a, over.rgb, over.a) / alpha, alpha);
}

This catches a case which potentially divides by zero. Maybe your hardware does not like this :stuck_out_tongue:

daudix commented 1 year ago

line 123 - 126, right?

Schneegans commented 1 year ago

Yes!

daudix commented 1 year ago

Hooray!

I have checked all effects and they all work properly

Kooha-2023-01-08-21-35-48.webm

Schneegans commented 1 year ago

Awesome! Thanks a lot for your time. This fix will be included in the next version, until then you can keep using the version from git. Once Burn-My-Windows 24 is released, you can simply remove the extension an install it again from extensions.gnome.org! The settings will not be lost.

daudix commented 1 year ago

Thank you so much for rapid response and fix! :heart: