Skip to content

qt: use Evan Wallace's fast rounded rectangle shadow instead of pre-generated texture sampling

My limited research resulted that this is considered a better approach than any texture based approach (whether GPU or CPU generated).

Regarding non-texture based solutions, it has the advantage over Qt 6.9's RectangularShadow or Qt 5's RectangularGlow that this uses proper approximation of gaussian blur instead of relying on smoothstep(), which I assume is good for glow effect but not for shadows.

More information available at https://madebyevan.com/shaders/fast-rounded-rectangle-shadows, I have also found a benchmark here https://tchayen.com/thousands-styled-rectangles-in-120fps-on-gpu.

Draft because I'm still thinking if there is a way to eliminate clipping without requiring to provide a certain size. It is not very nice to calculate the bounding box of the effect. At the same time, I also do not want to make the shader cover the whole window (this would also break batching, as there are many of them, they would all overlap). I currently used vec2 compensatedOffset = vec2(blurRadius, blurRadius) * 2.0, but it seems it is not enough (noticeable with strong shadows, not so much with the values we are using currently). It seems that Qt uses 2.5 (https://codebrowser.dev/qt6/qtbase/src/widgets/effects/qpixmapfilter.cpp.html#radiusScale), but I'm worried that 2.5 may be too much that would cause normal (not hovered or selected state) shadows to overlap inter-delegate (in fact, 2.0 already causes overlapping with the secondary normal shadows in grid view, but we can't really do much here. Perhaps the delegate spacing should be increased, or blur radius be decreased). I'm open to suggestions.

When feasible (shadows not overlapped), this should be continued to be batched just as other ShaderEffect that are alike, thanks to https://github.com/qt/qtdeclarative/commit/ee616b3905106a3eedef9ee964ab283ef45c7dbc, https://github.com/qt/qtdeclarative/commit/38cab579a0c5398b7621221fd8609bc43cf1f3c5.

This also has the additional advantage of not occupying the limited size atlas texture with shadow textures, and the image cache with shadow images.

Request review @chub.

Merge request reports

Loading