Skip to content

feat: add color-key transparency#160

Open
CyberShadow wants to merge 1 commit intowlrfx:mainfrom
CyberShadow:colorkey
Open

feat: add color-key transparency#160
CyberShadow wants to merge 1 commit intowlrfx:mainfrom
CyberShadow:colorkey

Conversation

@CyberShadow
Copy link

Implemented as more of a color search-and-replace feature.

This allows enabling a transparent background on apps which are not alpha-aware - pick an unlikely color to use as the background, then configure SwayFX to remap it to another color with an alpha value.

Implemented as more of a color search-and-replace feature.

This allows enabling a transparent background on apps which are not alpha-aware
- pick an unlikely color to use as the background, then configure SwayFX to
remap it to another color with an alpha value.
CyberShadow added a commit to CyberShadow/swayfx that referenced this pull request Dec 17, 2025
Implemented as more of a color search-and-replace feature.

This allows enabling a transparent background on apps which are not alpha-aware
- pick an unlikely color to use as the background, then configure SwayFX to
remap it to another color with an alpha value.

Requires wlrfx/scenefx#160.
vec4 c = sample_texture();

// Color-key transparency: replace matching colors
if (colorkey_enabled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use #define/#if and a new shader object for this, so perfomance stays identical when disabled

Copy link
Author

@CyberShadow CyberShadow Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU, because this is a uniform, the if should already be inlined. Are you aware of this causing any impact beyond shader compilation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how accurate this is, but

https://gist.github.com/CyberShadow/d5608b15998194aa75504016b7dd5b75

$ nix-shell --run ./run_benchmark.sh                   
Compiling branchless benchmark...
Compiling branching benchmark...

Running benchmarks...
========================================
OpenGL Version: 4.6 (Core Profile) Mesa 25.1.5
Renderer: AMD Radeon RX 6900 XT (radeonsi, navi21, LLVM 19.1.7, DRM 3.63, 6.15.5)

=== BRANCHLESS SHADER BENCHMARK ===
Resolution: 1920x1080
Iterations: 100000
Total time: 0.729 seconds
Average: 0.0073 ms/frame
FPS: 137188.91

OpenGL Version: 4.6 (Core Profile) Mesa 25.1.5
Renderer: AMD Radeon RX 6900 XT (radeonsi, navi21, LLVM 19.1.7, DRM 3.63, 6.15.5)

=== BRANCHING SHADER BENCHMARK (80% false, 20% true) ===
Resolution: 1920x1080
Iterations: 100000
Total time: 0.729 seconds
Average: 0.0073 ms/frame
FPS: 137139.10

========================================
Benchmark complete!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how accurate this is, but

The issue isn't with high-end hardware, but with power limited "weak" (in comparison) laptop GPUs, especially with all the other things being rendered during the same frame, like poorly damaged toplevels, blur, shadows, etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue isn't with high-end hardware, but with power limited "weak" (in comparison) laptop GPUs

Fair, here are the results on my 8-year-old laptop on the integrated GPU:

Compiling branchless benchmark...
Compiling branching benchmark...

Running benchmarks...
========================================
OpenGL Version: 4.6 (Core Profile) Mesa 25.2.4
Renderer: Mesa Intel(R) UHD Graphics 620 (KBL GT2)

=== BRANCHLESS SHADER BENCHMARK ===
Resolution: 1920x1080
Iterations: 10000
Total time: 4.240 seconds
Average: 0.4240 ms/frame
FPS: 2358.35

OpenGL Version: 4.6 (Core Profile) Mesa 25.2.4
Renderer: Mesa Intel(R) UHD Graphics 620 (KBL GT2)

=== BRANCHING SHADER BENCHMARK (80% false, 20% true) ===
Resolution: 1920x1080
Iterations: 10000
Total time: 4.227 seconds
Average: 0.4227 ms/frame
FPS: 2365.82

========================================
Benchmark complete!

especially with all the other things being rendered during the same frame, like poorly damaged toplevels, blur, shadows, etc.

If you insist, I'll apply the patch if that's what you want. Or do you want me to test any specific combination?

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

Successfully merging this pull request may close these issues.

3 participants