12. (16 points) Let $a, b \in [0,1]$. Find
$$
S=\frac{a}{1+b}+\frac{b}{1+a}+(1-a)(1-b)
$$

the maximum and minimum values.
12. Since $S=\frac{a}{1+b}+\frac{b}{1+a}+(1-a)(1-b)$ $=\frac{1+a+b+a^{2} b^{2}}{(1+a)(1+b)}=1-\frac{a b(1-a b)}{(1+a)(1+b)} \leqslant 1$,
thus, when $a b=0$ or $a b=1$, the equality holds.
Therefore, the maximum value of $S$ is 1.
Let $T=\frac{a b(1-a b)}{(1+a)(1+b)}, x=\sqrt{a b}$. Then
$$
\begin{array}{l}
T=\frac{a b(1-a b)}{1+a+b+a b} \leqslant \frac{a b(1-a b)}{1+2 \sqrt{a b}+a b} \\
=\frac{x^{2}\left(1-x^{2}\right)}{(1+x)^{2}}=\frac{x^{2}(1-x)}{1+x} .
\end{array}
$$

We need to prove: $\frac{x^{2}(1-x)}{1+x} \leqslant \frac{5 \sqrt{5}-11}{2}$.
Equation (1) $\Leftrightarrow\left(x-\frac{\sqrt{5}-1}{2}\right)^{2}(x+\sqrt{5}-2) \geqslant 0$,
so, $T \leqslant \frac{5 \sqrt{5}-11}{2}$. Therefore, $S \geqslant \frac{13-5 \sqrt{5}}{2}$.
When $a=b=\frac{\sqrt{5}-1}{2}$, the equality holds.
Therefore, the minimum value of $S$ is $\frac{13-5 \sqrt{5}}{2}$.