Thanks to this answer, it is possible to make the shadow of a beamer's block fade to the background color instead of white.
As pointed out by the following MWE, the problem is, the solution provided doesn't work after \begin{document}, which is annoying if one wants to change the background color in the middle of the document.
Hence the question: how to change after preamble the color a beamer's block shadow fades to?
\documentclass{beamer}
\usetheme{Madrid}
\newcommand{\test}[1][yellow]{%
\setbeamercolor{background canvas}{bg=#1}
\makeatletter
\pgfdeclareverticalshading[black,bg]{bmb@shadow}{200cm}{%
color(0bp)=(#1); color(4bp)=(black!50!bg); color(8bp)=(black!50!bg)}
\pgfdeclareradialshading[black,bg]{bmb@shadowball}{\pgfpointorigin}{%
color(0bp)=(black!50!bg); color(4bp)=(#1)}
\pgfdeclareradialshading[black,bg]{bmb@shadowballlarge}{\pgfpointorigin}{%
color(0bp)=(black!50!bg); color(4bp)=(black!50!bg); color(8bp)=(#1)}
%
\makeatother
}
\test
\begin{document}
\begin{frame}
\begin{block}{Foo}
Bar
\end{block}
\end{frame}
%
\test[cyan]
%
\begin{frame}
\begin{block}{Foo}
Bar
\end{block}
\end{frame}
\end{document}


libertinepackage), an extra rectangle is drawn (and slightly visible) between the box and its shadow. – Denis Bitouzé Mar 20 '18 at 17:06