# How to change after preamble the color a beamer's block shadow fades to?

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}

\newcommand{\test}[1][yellow]{%
\setbeamercolor{background canvas}{bg=#1}
\makeatletter
color(0bp)=(#1); color(4bp)=(black!50!bg); color(8bp)=(black!50!bg)}
color(0bp)=(black!50!bg); color(4bp)=(#1)}
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}

\documentclass{beamer}

\setbeamercolor{background canvas}{bg=yellow}

\begin{document}

\begin{frame}
\begin{block}{Foo}
Bar
\end{block}
\end{frame}

\setbeamercolor{background canvas}{bg=cyan}

\begin{frame}
\begin{block}{Foo}
Bar
\end{block}
\end{frame}
\end{document}