Skip to content

Commit

Permalink
focus quality ... 1/2
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarza9788 committed Oct 26, 2024
1 parent 91422d0 commit b7434c0
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 36 deletions.
7 changes: 4 additions & 3 deletions resources/shaders/focus.frag
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ float easeInOutSine(float x) {
}

// A simple blur function
vec4 blur(vec2 uv, float radius) {
vec4 blur(vec2 uv, float radius, float samples) {
vec4 color = vec4(0.0);

const float tau = 6.28318530718;
const float directions = 15.0;
const float samples = 5.0;
// const float samples = quality;

for (float d = 0.0; d < tau; d += tau / directions) {
for (float s = 0.0; s < 1.0; s += 1.0 / samples) {
Expand All @@ -62,6 +62,7 @@ vec4 blur(vec2 uv, float radius) {

// The width of the fading effect is loaded from the settings.
uniform float uBlurAmount;
uniform float uBlurQuality;

void main() {

Expand All @@ -74,7 +75,7 @@ void main() {
float blurAmount = mix(uBlurAmount, 0.0, easedProgressBlur);

// Apply blur
vec4 texColor = blur( iTexCoord.st, blurAmount);
vec4 texColor = blur( iTexCoord.st, blurAmount, uBlurQuality);

// Control alpha using easedProgressAlpha
float alpha = easedProgressAlpha;
Expand Down
34 changes: 34 additions & 0 deletions resources/ui/adw/focus.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
<property name="page-increment">10</property>
</object>

<object class="GtkAdjustment" id="focus-blur-quality">
<property name="upper">20</property>
<property name="lower">1</property>
<property name="step-increment">1</property>
<property name="page-increment">5</property>
</object>

<object class="AdwExpanderRow" id="focus-prefs">

<child>
Expand Down Expand Up @@ -75,6 +82,33 @@ SPDX-License-Identifier: GPL-3.0-or-later
</object>
</child>

<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Blur Quality</property>
<child>
<object class="GtkScale">
<property name="valign">center</property>
<property name="draw-value">1</property>
<property name="digits">2</property>
<property name="value-pos">left</property>
<property name="width-request">300</property>
<property name="adjustment">focus-blur-quality</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-focus-blur-quality">
<property name="icon-name">edit-clear-symbolic</property>
<property name="valign">center</property>
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
<style>
<class name="flat" />
</style>
</object>
</child>

</object>
</child>

</object>

</interface>
66 changes: 35 additions & 31 deletions resources/ui/adw/prefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -214,39 +214,43 @@ SPDX-License-Identifier: GPL-3.0-or-later
</child>
</object>

<object class="AdwPreferencesPage" id="general-prefs">
<child>
<object class="AdwPreferencesGroup" id="effects-group">
<property name="margin-top">20</property>
<property name="margin-bottom">20</property>
<property name="margin-start">20</property>
<property name="margin-end">20</property>
<property name="title" translatable="yes">Effect Selection</property>
<property name="description" translatable="yes">If multiple are selected, one is chosen randomly.</property>

<child type="header-suffix">
<object class="GtkBox">
<property name="valign">center</property>
<style>
<class name="linked" />
</style>
<object class="AdwPreferencesPage" id="general-prefs">
<child>
<object class="AdwPreferencesGroup" id="effects-group">
<property name="margin-top">20</property>
<property name="margin-bottom">20</property>
<property name="margin-start">20</property>
<property name="margin-end">20</property>
<property name="title" translatable="yes">Effect Selection</property>
<property name="description" translatable="yes">If multiple are selected, one is chosen randomly.</property>

<child>
<object class="GtkButton" id="choose-all-effects-button">
<property name="label" translatable="yes">All</property>
</object>
</child>

<child>
<object class="GtkButton" id="choose-no-effects-button">
<property name="label" translatable="yes">None</property>
</object>
</child>
<!-- Add buttons for selecting all or no effects -->
<child type="header-suffix">
<object class="GtkBox">
<property name="valign">center</property>
<style>
<class name="linked" />
</style>

<child>
<object class="GtkButton" id="choose-all-effects-button">
<property name="label" translatable="yes">All</property>
</object>
</child>

<child>
<object class="GtkButton" id="choose-no-effects-button">
<property name="label" translatable="yes">None</property>
</object>
</child>

</object>
</child>

</object>
</child>
</object>

</object>
</child>
</object>
</child>
</object>

</interface>
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,13 @@ SPDX-License-Identifier: CC0-1.0
<key name="focus-blur-ammout" type="i">
<default>50</default>
<summary>Focus Blur Ammout</summary>
<description>The Blue Amount before Focusing.</description>
<description>The Blur Amount before Focusing.</description>
</key>

<key name="focus-blur-quality" type="i">
<default>5</default>
<summary>Focus Blur Quality</summary>
<description>The Quality of the Blur (Setting this too high may increase GPU load and affect performance)</description>
</key>

</schema>
Expand Down
8 changes: 7 additions & 1 deletion src/effects/Focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ export default class Effect {
this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => {
// Store uniform locations of newly created shaders.
shader._uBlurAmount = shader.get_uniform_location("uBlurAmount");
shader._uBlurQuality = shader.get_uniform_location("uBlurQuality");

// Write all uniform values at the start of each animation.
shader.connect("begin-animation", (shader, settings) => {
shader.set_uniform_float(shader._uBlurAmount, 1, [
settings.get_int("focus-blur-ammout"),
]);

shader.set_uniform_float(shader._uBlurQuality, 1, [
settings.get_int("focus-blur-quality"),
]);
});
});
}
Expand All @@ -69,7 +74,7 @@ export default class Effect {
// This will be shown in the sidebar of the preferences dialog as well as in the
// drop-down menus where the user can choose the effect.
static getLabel() {
return _("Focus Effect");
return _("Focus");
}

// -------------------------------------------------------------------- API for prefs.js
Expand All @@ -81,6 +86,7 @@ export default class Effect {
// on how to bind other types of UI elements.
dialog.bindAdjustment('focus-animation-time');
dialog.bindAdjustment('focus-blur-ammout');
dialog.bindAdjustment('focus-blur-quality');
}

// ---------------------------------------------------------------- API for extension.js
Expand Down

0 comments on commit b7434c0

Please sign in to comment.