8. Given $\alpha, \beta, \gamma \in(0, \pi)$, and $\alpha+\beta+2 \gamma=\pi$, then the maximum value of $\cos \alpha+\cos \beta+\sin 2 \gamma$ is $\qquad$
$$
\begin{array}{l}
\cos \alpha+\cos \beta+\sin 2 \gamma=\cos \alpha+\cos \beta+\sin (\alpha+\beta) \leqslant 2 \cos \frac{\alpha+\beta}{2}+\sin (\alpha+\beta) \\
\xlongequal{t=\frac{\alpha+\beta}{2}} 2 \cos t+\sin 2 t, \text{ let } f(t)=2 \cos t+\sin 2 t, f^{\prime}(t)=-2 \sin t+2 \cos 2 t \\
=-4 \sin ^{2} t-2 \sin t+2=-2(2 \sin t-1)(\sin t+1), \text{ thus } f(t)_{\max }=f\left(\frac{\pi}{6}\right)=\frac{3 \sqrt{3}}{2},
\end{array}
$$

Equality holds when $\alpha=\beta=\frac{\pi}{6}$. Therefore, the maximum value of $\cos \alpha+\cos \beta+\sin 2 \gamma$ is $\frac{3 \sqrt{3}}{2}$.