[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: introduce `antialiasing` uniform variable in `SDFAARoundedTexture.frag`
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Fri Jan 2 11:30:53 UTC 2026
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
66c75983 by Fatih Uzunoglu at 2026-01-02T12:16:49+01:00
qt: introduce `antialiasing` uniform variable in `SDFAARoundedTexture.frag`
In addition to the preprocessor definition, now there is an uniform variable
to dictate whether antialiasing should be active or not.
Research suggests that conditions based on uniform variables are optimized
well. Consumers may still remove the `ANTIALIASING` preprocessor define to
generate a shader that does not have the capability of applying AA. For
maintenance purposes, generating the shader without AA capability is left
for discussion until the build system supports generating shaders with
preprocessor defines.
Having a shader with no AA capability may get rid of few if statements,
though that would likely not impact the performance in any meaningful
way (see the note above). But at the same time, it would increase the
size, and possibly make antialiasing switch more laggy (though this
would not mean much, since antialiasing switch is not meant to be
animated, at least so far) due to shader switch even though shaders
may be cached, it can not be as fast as adjusting the uniform buffer.
It should be noted that we are already checking conditions based on
the uniform block in both `CROP_SUPPORT` and `BORDER_SUPPORT`
variations.
- - - - -
d1635a46 by Fatih Uzunoglu at 2026-01-02T12:16:49+01:00
qml: remove obsolete note regarding `antialiasing` in `ImageExt`
- - - - -
3 changed files:
- modules/gui/qt/shaders/SDFAARoundedTexture.frag
- modules/gui/qt/shaders/SDFAARoundedTexture_cropsupport_bordersupport.frag
- modules/gui/qt/widgets/qml/ImageExt.qml
Changes:
=====================================
modules/gui/qt/shaders/SDFAARoundedTexture.frag
=====================================
@@ -44,6 +44,9 @@ layout(std140, binding = 0) uniform buf {
float qt_Opacity;
vec4 qt_SubRect_source;
vec2 size;
+#ifdef ANTIALIASING
+ int antialiasing; // WARNING: intentionally not a boolean
+#endif
#ifdef CROP_SUPPORT
vec2 cropRate;
#endif
@@ -142,30 +145,40 @@ void main()
float borderStep = step(-borderRange, dist);
vec4 border = borderStep * borderColor;
#ifdef ANTIALIASING
- // Inner AA (Outer AA is handled below, regardless of the border):
- // This is additive, solid and AA part do not intersect:
- border += (smoothstep(-borderRange - fwidth(dist) * 1.5, -borderRange, dist)) * (1.0 - borderStep) * borderColor;
+ if (antialiasing != 0)
+ {
+ // Inner AA (Outer AA is handled below, regardless of the border):
+ // This is additive, solid and AA part do not intersect:
+ border += (smoothstep(-borderRange - fwidth(dist) * 1.5, -borderRange, dist)) * (1.0 - borderStep) * borderColor;
+ }
#endif
// Source over blending (S + D * (1 - S.a)):
texel = border + texel * (1.0 - border.a);
}
#endif
+ float factor;
#ifdef ANTIALIASING
+ if (antialiasing != 0)
+ {
#ifndef CUSTOM_SOFTEDGE
- float softEdgeMax = fwidth(dist) * 0.75;
- float softEdgeMin = -softEdgeMax;
+ float softEdgeMax = fwidth(dist) * 0.75;
+ float softEdgeMin = -softEdgeMax;
#endif
- // Breathing room (shrink):
- dist += softEdgeMax;
+ // Breathing room (shrink):
+ dist += softEdgeMax;
- // Soften the outline, as recommended by the Valve paper, using smoothstep:
- // "Improved Alpha-Tested Magnification for Vector Textures and Special Effects"
- // NOTE: The whole texel is multiplied, because of premultiplied alpha.
- float factor = smoothstep(softEdgeMin, softEdgeMax, dist);
-#else
- float factor = step(0.0, dist);
+ // Soften the outline, as recommended by the Valve paper, using smoothstep:
+ // "Improved Alpha-Tested Magnification for Vector Textures and Special Effects"
+ // NOTE: The whole texel is multiplied, because of premultiplied alpha.
+ factor = smoothstep(softEdgeMin, softEdgeMax, dist);
+ }
+ else
#endif
+ {
+ factor = step(0.0, dist);
+ }
+
texel *= 1.0 - factor;
fragColor = texel * qt_Opacity;
=====================================
modules/gui/qt/shaders/SDFAARoundedTexture_cropsupport_bordersupport.frag
=====================================
@@ -57,6 +57,9 @@ layout(std140, binding = 0) uniform buf {
float qt_Opacity;
vec4 qt_SubRect_source;
vec2 size;
+#ifdef ANTIALIASING
+ int antialiasing; // WARNING: intentionally not a boolean
+#endif
#ifdef CROP_SUPPORT
vec2 cropRate;
#endif
@@ -155,30 +158,40 @@ void main()
float borderStep = step(-borderRange, dist);
vec4 border = borderStep * borderColor;
#ifdef ANTIALIASING
- // Inner AA (Outer AA is handled below, regardless of the border):
- // This is additive, solid and AA part do not intersect:
- border += (smoothstep(-borderRange - fwidth(dist) * 1.5, -borderRange, dist)) * (1.0 - borderStep) * borderColor;
+ if (antialiasing != 0)
+ {
+ // Inner AA (Outer AA is handled below, regardless of the border):
+ // This is additive, solid and AA part do not intersect:
+ border += (smoothstep(-borderRange - fwidth(dist) * 1.5, -borderRange, dist)) * (1.0 - borderStep) * borderColor;
+ }
#endif
// Source over blending (S + D * (1 - S.a)):
texel = border + texel * (1.0 - border.a);
}
#endif
+ float factor;
#ifdef ANTIALIASING
+ if (antialiasing != 0)
+ {
#ifndef CUSTOM_SOFTEDGE
- float softEdgeMax = fwidth(dist) * 0.75;
- float softEdgeMin = -softEdgeMax;
+ float softEdgeMax = fwidth(dist) * 0.75;
+ float softEdgeMin = -softEdgeMax;
#endif
- // Breathing room (shrink):
- dist += softEdgeMax;
+ // Breathing room (shrink):
+ dist += softEdgeMax;
- // Soften the outline, as recommended by the Valve paper, using smoothstep:
- // "Improved Alpha-Tested Magnification for Vector Textures and Special Effects"
- // NOTE: The whole texel is multiplied, because of premultiplied alpha.
- float factor = smoothstep(softEdgeMin, softEdgeMax, dist);
-#else
- float factor = step(0.0, dist);
+ // Soften the outline, as recommended by the Valve paper, using smoothstep:
+ // "Improved Alpha-Tested Magnification for Vector Textures and Special Effects"
+ // NOTE: The whole texel is multiplied, because of premultiplied alpha.
+ factor = smoothstep(softEdgeMin, softEdgeMax, dist);
+ }
+ else
#endif
+ {
+ factor = step(0.0, dist);
+ }
+
texel *= 1.0 - factor;
fragColor = texel * qt_Opacity;
=====================================
modules/gui/qt/widgets/qml/ImageExt.qml
=====================================
@@ -39,13 +39,6 @@ Item {
implicitWidth: shaderEffect.readyForVisibility ? shaderEffect.implicitWidth : image.implicitWidth
implicitHeight: shaderEffect.readyForVisibility ? shaderEffect.implicitHeight : image.implicitHeight
- // WARNING: We can not override QQuickItem's antialiasing
- // property as readonly because Qt 6.6 marks it
- // as `FINAL`...
- // FIXME: The shader can be generated without
- // the define that enables antialiasing.
- // It should be done when the build system
- // starts supporting shader defines.
antialiasing: true
asynchronous: true
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/455de7d18bf4ab0424e6802892256a567f856c01...d1635a46da90de5dd3171f6c50cb653f5304ce11
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/455de7d18bf4ab0424e6802892256a567f856c01...d1635a46da90de5dd3171f6c50cb653f5304ce11
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list