A user was having some performance issues with their project, specifically related to their tilt shift blur effect
This was for vanilla shaders (not Craft) so I decided to try making a more optimised version. The original effect used a single pass with a kernel size of 12, which required at least 144 (12^2) texture samples per pixel
The new effect uses two separate passes (kernel size x 2 samples), with a pre-computed kernel passed in as a uniform array. You can see the difference by changing the kernel size parameter and sigma parameter. Another optimisation is the use of branching (not always bad) so that blurring only occurs in the top and bottom regions. The blur regions are also smoothly blended by adjusting the effective texel size when applying the blur
Because of the way that modern GPUs work, a wavefront/warp (groups of threads working on neighboring pixels) will have coherent branching when all of the threads have the same condition locally (https://www.peterstefek.me/shader-branch.html). So most of the pixels not in the bottom or top will only do one sample per pass instead (a few pixels on the boundary will do a little more work)
Anyway, enjoy!