8. If $a, b \in \mathbf{R}$, then the minimum value of $f(a, b)=\sqrt{2 a^{2}-8 a+10}+\sqrt{b^{2}-6 b+10}+\sqrt{2 a^{2}-2 a b+b^{2}}$ is $\qquad$
8. $2 \sqrt{5}$.
$f(a, b)=\sqrt{(a-3)^{2}+(a-1)^{2}}+\sqrt{(b-3)^{2}+1}+\sqrt{(a-b)^{2}+a^{2}}$ represents the perimeter of the triangle with vertices $P(3,1), Q(a, a), R(b, 0)$ in the coordinate plane $x O y$. It is also easy to see that the trajectories of points $Q$ and $R$ are the lines $y=x$ and $y=0$, respectively.

As shown in Figure 3, construct the reflections of point $P$ about the lines $y=x$ and $y=0$, denoted as $P_{1}$ and $P_{2}$, respectively. It is easy to find that $P_{1}(1,3), P_{2}(3,-1)$. Connect $P_{1} P_{2}$, intersecting $y=x$ and $y=0$ at points $Q$ and $R$, respectively. Connect $P Q, P R$. We will now prove that the perimeter of $\triangle P Q R$ is minimized in this configuration.

Take any points $Q^{\prime}$ and $R^{\prime}$ on the lines $y=x$ and $y=0$, respectively, and connect $P_{1} Q^{\prime}, P Q^{\prime}, Q^{\prime} R^{\prime}, P R^{\prime}, P_{2} R^{\prime}$. Then, $P Q^{\prime}+P R^{\prime}+Q^{\prime} R^{\prime}=P_{1} Q^{\prime}+Q^{\prime} R^{\prime}+R^{\prime} P_{2} \geqslant P_{1} P_{2}=P_{1} Q+Q R+R P_{2}=P Q+Q R+R P$. Therefore, the minimum value of the perimeter of $\triangle P Q R$ is
$$
\left|P_{1} P_{2}\right|=\sqrt{(1-3)^{2}+(3+1)^{2}}=2 \sqrt{5} \text {. }
$$