Progress on moving the background rendering fully to the GPU #222
Replies: 1 comment
-
vec4 main(vec2 fragCoord) {
vec3 col = mix(iPrimary, iAccent, sin(iTime));
return vec4(col, 1.0);
} thought I'd include a simple example of a shader written in SkSL if you're curious, this one lerps between the current primary and accent colors using the sine of the time, the variables prefixed with
You can normalise this to a uv with |
Beta Was this translation helpful? Give feedback.
-
I've had some free time recently so I re-investigated the possibility of moving the background renderer fully onto the GPU to eliminate a source of performance drag.
Initially I got it running with OpenGL but it was exceptionally awkward to work with, so I moved onto Skia's rendering pipeline and got it running with not too much work. Currently the major downside is the Skia shader language SkSL which is quite limited in it's current form, thanks to Avalonia running SkiaSharp which itself runs a fairly old version of Skia at this point. This limitation mainly manifests itself in missing functions like
mod
,step
andsmoothstep
(among others). It does make translating GLSL shaders a bit of a headache but it's feasible.I've included 4 default shaders written in sksl - including the empty one which is simply called "flat" for people who don't want a flashy background. I'm not a shader wizard nor am I particularly artistically inclined so I (fairly heavily) adapted some ShaderToy shaders.
Here is a video of it running with the 4 shaders on a loop - I've turned the animation speed up so it's more visible for this demo:
https://dl.dropboxusercontent.com/scl/fi/okmadh8foq0bb53oo33z7/SukiUI.Demo_2024-06-19_10-03-58.webm?rlkey=62tolbunxnhzswtf8k333vz83&dl=0
I haven't been able to benchmark it but it's running at the native framerate of the application very, very smoothly with no noticeable performance impact.
The only thing I'm struggling with at the moment is rewriting the API for the background so it's a little nicer to work with. I'd ideally like to include it in
SukiTheme
but that class is already getting exceptionally heavy and giving it even more responsibility seems like a mistake. An alternative would be aSukiBackground
static class which would act as the singleton in charge of everything. I hate singletons generally but it seems like the cleanest way to approach this global & local state problem.Thought I'd give a quick pros/cons list for this feature overall:
Pros:
Cons:
I've completed the majority of the work needed to get everything running and really the only thing is getting the go-ahead to get this properly implemented and to what extent I should change the API around backgrounds.
Beta Was this translation helpful? Give feedback.
All reactions