-
-
Notifications
You must be signed in to change notification settings - Fork 79
Add CRT effect shader and animation while shutting down #2770
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
Draft
SubhadeepJasu
wants to merge
1
commit into
elementary:main
Choose a base branch
from
SubhadeepJasu:fades
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright 2026 elementary, Inc. <https://elementary.io> | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| uniform sampler2D tex; | ||
| uniform float OCCLUSION; // 0.0 when the TV is fully on, 1.0 when it's fully off | ||
| uniform float HEIGHT; // Screen height in pixels | ||
|
|
||
| float cubicBezier(float x, float a, float b, float c, float d) { | ||
| float _x = 1.0 - x; | ||
| return a * _x * _x * _x + | ||
| b * 3.0 * _x * _x * x + | ||
| c * 3.0 * _x * x * x + | ||
| d * x * x * x; | ||
| } | ||
|
|
||
| vec4 tvEffect(vec2 uv, float scale, float occlusion) { | ||
| float y_scaled = 0.5 + (uv.y - 0.5) / (scale * scale); | ||
| float x_scaled = uv.x; | ||
|
|
||
| // Wait for scale to get small enough before shrinking the bright line to a dot | ||
| if (scale < 0.1) { | ||
| float scale_fract = scale / 0.1; | ||
| x_scaled = 0.5 + (uv.x - 0.5) / (scale_fract * scale_fract); | ||
| } | ||
|
|
||
| // Outside of the scaled area should be black | ||
| if (scale >= 0.0 && y_scaled >= 0.0 && y_scaled <= 1.0 && x_scaled >= 0.0 && x_scaled <= 1.0) { | ||
| vec4 color = texture2D(tex, vec2(x_scaled, y_scaled)); | ||
| // Make it brighter as the window gets smaller | ||
| return color + occlusion * color + occlusion * 0.75; | ||
| } else { | ||
| return vec4(0.0, 0.0, 0.0, 1.0); | ||
| } | ||
| } | ||
|
|
||
| void main() { | ||
| // Ease out the occlusion | ||
| float occlusion = cubicBezier(OCCLUSION, 0.0, 0.98, 0.75, 1.0); | ||
| float scale = 1.0 - occlusion; | ||
| vec2 uv = cogl_tex_coord0_in.xy; | ||
|
|
||
| // Apply a 5x5 Gaussian blur, with support of 0.5 and sigma 1.0 | ||
| float kernel[5]; | ||
| kernel[0] = 0.0614; | ||
| kernel[1] = 0.2448; | ||
| kernel[2] = 0.3877; | ||
| kernel[3] = 0.2448; | ||
| kernel[4] = 0.0614; | ||
|
|
||
| float blurSize = occlusion * 5.0 / HEIGHT; | ||
|
|
||
| vec4 color = vec4(0.0); | ||
| for (int i = 0; i < 5; i++) { | ||
| for (int j = 0; j < 5; j++) { | ||
| vec2 offset = vec2(float(i - 2), float(j - 2)) * blurSize; | ||
| color += tvEffect(uv + offset, scale, occlusion) * kernel[i] * kernel[j]; | ||
| } | ||
| } | ||
|
|
||
| cogl_color_out = color; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright 2026 elementary, Inc. <https://elementary.io> | ||
| * SPDX-License-Identifier: LGPL-3.0-or-later | ||
| */ | ||
|
|
||
| public class Gala.TVEffect : Clutter.ShaderEffect { | ||
| private float _occlusion = 0.0f; | ||
| public float occlusion { get { | ||
| return _occlusion; | ||
| } set { | ||
| _occlusion = value; | ||
| set_uniform_value ("OCCLUSION", value); | ||
| queue_repaint (); | ||
| }} | ||
|
|
||
| private float _height = 512.0f; | ||
| public float height { get { | ||
| return _height; | ||
| } set { | ||
| _height = value; | ||
| set_uniform_value ("HEIGHT", value); | ||
| queue_repaint (); | ||
| }} | ||
|
|
||
| public TVEffect (float occlusion = 0.0f) { | ||
| Object ( | ||
| #if HAS_MUTTER48 | ||
| shader_type: Cogl.ShaderType.FRAGMENT, | ||
| #else | ||
| shader_type: Clutter.ShaderType.FRAGMENT_SHADER, | ||
| #endif | ||
| occlusion: occlusion | ||
| ); | ||
|
|
||
| try { | ||
| var bytes = GLib.resources_lookup_data ( | ||
| "/io/elementary/desktop/gala/shaders/tv-effect.frag", | ||
| GLib.ResourceLookupFlags.NONE | ||
| ); | ||
| set_shader_source ((string) bytes.get_data ()); | ||
| } catch (Error e) { | ||
| warning ("Failed to load TV effect shader: %s", e.message); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * SPDX-FileCopyrightText: 2020, 2025, 2026 elementary, Inc. (https://elementary.io) | ||
| */ | ||
|
|
||
| public class Gala.ShutdownCurtain : Clutter.Actor { | ||
| private unowned Clutter.Stage stage; | ||
| public uint animation_duration { get; set construct; default = 300; } | ||
|
|
||
| public ShutdownCurtain (Meta.Context context) { | ||
| int screen_width, screen_height; | ||
| context.get_display ().get_size (out screen_width, out screen_height); | ||
| width = screen_width; | ||
| height = screen_height; | ||
| stage = (Clutter.Stage) context.get_display ().get_stage (); | ||
| } | ||
|
|
||
| public void animate () { | ||
| var animation_thread = new Thread<void> ("tv-effect-animation", start); | ||
| animation_thread.join (); | ||
| } | ||
|
|
||
| private void start () { | ||
| int time = 0; | ||
| var tv_effect = new TVEffect (); | ||
| tv_effect.occlusion = 0; | ||
| tv_effect.height = height; | ||
| stage.add_effect_with_name ( | ||
| "tv-effect", | ||
| tv_effect | ||
| ); | ||
|
|
||
| while (time < animation_duration) { | ||
| tv_effect.occlusion = (animation_duration - time) / (float) animation_duration; | ||
|
|
||
| time += 16; | ||
| Thread.usleep (16000); | ||
| } | ||
|
|
||
| stage.remove_effect_by_name ("tv-effect"); | ||
| Thread.usleep (2000); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK at this point Mutter has already completely shutdown. So we don't have a stage nor a frame clock nor anything anymore