22

As depicted below, Illustrator offers various transparency styles:

enter image description here

It is my understanding that, at this point, pstricks and TikZ are both limited to the normal style listed above. Could the other styles be implemented as well or is there any unexpected limitation somewhere?

3
  • 1
    Look at tex.stackexchange.com/a/162018/14500 . Jun 4, 2014 at 9:30
  • @PaulGaborit That's fairly sad: I up-voted your post some time ago, but completely overlooked it when I posed my question. In a way, I was looking for examples with a picture in the background.
    – pluton
    Jun 6, 2014 at 5:46
  • A specific question about blend modes is better than a vague question about new features. ;-) Jun 6, 2014 at 6:12

2 Answers 2

37

Both pstricks and PGF/TikZ can produce all the required blend modes. However it seems that pstricks.tex in TeXLive 2013 (a) only defines some of the blend modes supported by ghostscript (at least from version 9.14), and (b) has a bug where Ligten should read Lighten.

It is (as far as I can tell) quite simple to amend this, although I should caution I am no pstricks expert. The following shows all the blend modes for both packages and should be compiled with xelatex. It may not work with earlier versions of ghostscript.

\documentclass[border=5]{standalone}
\usepackage{pstricks}
\usepackage{tikz}
\makeatletter

\pst@def{setBlendmode}<
    \ifcase\psk@blendmode
      /Normal \or 
      /Compatible \or
      /Screen \or
      /Multiply \or
      /HardLight \or
      /Darken \or
      /Lighten \or
      /Difference \or
      /ColorDodge \or
      /ColorBurn \or
      /SoftLight \or
      /Hue \or
      /Saturation \or
      /Luminosity \or
      /Overlay \or
      /Exclusion \or
      /Color
    \else
      /Normal 
    \fi
    .setblendmode \psk@shapealpha .setshapealpha >
\makeatother

\pgfkeys{%
  ps blend mode/.style={/ps blend mode/.cd, #1/.try},
  ps blend mode/.cd,
  normal/.code=\psset{blendmode=0},
  compatible/.code=\psset{blendmode=1},
  screen/.code=\psset{blendmode=2},
  multiply/.code=\psset{blendmode=3},
  hard light/.code=\psset{blendmode=4},
  darken/.code=\psset{blendmode=5},
  lighten/.code=\psset{blendmode=6},
  difference/.code=\psset{blendmode=7},
  color dodge/.code=\psset{blendmode=8},
  color burn/.code=\psset{blendmode=9},
  soft light/.code=\psset{blendmode=10},
  hue/.code=\psset{blendmode=11},
  saturation/.code=\psset{blendmode=12},
  luminosity/.code=\psset{blendmode=13},
  overlay/.code=\psset{blendmode=14},
  exclusion/.code=\psset{blendmode=15},
  color/.code=\psset{blendmode=16}
}

\def\psshowblend#1{%
\psset{unit=0.5cm,fillstyle=shape,linestyle=none,shapealpha=0.75}%
\pgfkeys{ps blend mode=#1}
\SpecialCoor
\begin{pspicture}[shift=-1.5](-1.5,-1.5)(4.5,1.5)
\pscircle[fillcolor=red](.5;90){1}
\pscircle[fillcolor=green](.5;210){1}
\pscircle[fillcolor=blue](.5;330){1}
\rput(3,0){
\pscircle[fillcolor=yellow](.5;90){1}
\pscircle[fillcolor=cyan](.5;210){1}
\pscircle[fillcolor=magenta](.5;330){1}
}
\end{pspicture}
}

\def\tikzshowblend#1{%
\begin{tikzpicture}[x=0.5cm,y=0.5cm, blend mode=#1, opacity=0.75, baseline={(0,0)}]
\useasboundingbox (-1.5,-1.5) rectangle (4.5,1.5);
\fill [red]  ( 90:.5) circle [radius=1];
\fill [green]    (210:.5) circle [radius=1];
\fill [blue] (330:.5) circle [radius=1];
\tikzset{shift=(0:3)}
\fill [yellow]  ( 90:.5) circle [radius=1];
\fill [cyan]    (210:.5) circle [radius=1];
\fill [magenta] (330:.5) circle [radius=1];
\end{tikzpicture}
}

\catcode`\|=13
\def|{\verb|}
\begin{document}
\begin{minipage}{5in}
\hskip1in\hbox to 2in{\hfil|pstricks|\hfil}\hbox to 2in{\hfil|tikz|\hfil}\par
\vskip0.5cm%
\foreach \mode in {normal, multiply, screen, overlay, darken, lighten, color dodge, color burn, hard light, soft light, difference, exclusion, hue, saturation, color, luminosity}{%
\leavevmode\hbox to 1in{\tt\mode\hfil}%
\hbox to 2in{\hfil\psshowblend{\mode}\hfil}%
\hbox to 2in{\hfil\tikzshowblend{\mode}\hfil}\hfil\par%
}
\end{minipage}
\end{document}

enter image description here

Following the OP's comment above, here is some examples with a picture in the background using only TikZ this time (pstricks can do it as well, I am just more familiar with TikZ).

The picture is not very exciting but the code overlays red, green and blue circles at varying levels of transparency to illustrate the different blend modes:

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}
 \foreach \mode [count=\n from 0, evaluate={\x=mod(\n,2)*5; \y=-floor(\n/2)*4;}] in {normal, multiply, screen, overlay, darken, lighten, color dodge, color burn, hard light, soft light, difference, exclusion, hue, saturation, color, luminosity}{%
  \begin{scope}[shift={(\x,\y)},local bounding box=mode]
  \foreach \c [count=\i] in {red, green, blue}{
    \foreach \j [evaluate={\o=(\j+1)/4;}] in {0,...,3}{
      \begin{scope}[shift=(90:2-\i), shift=(0:\j), scale=0.25]
        \begin{scope}[opacity=0.75]
          \fill [red]   ( 90:.5) circle [radius=1];
          \fill [green] (210:.5) circle [radius=1];
          \fill [blue]  (330:.5) circle [radius=1];
        \end{scope}
        \begin{scope}[blend mode=\mode, opacity=\o]
          \fill [fill=\c] circle [radius=1.875];
        \end{scope}  
      \end{scope}
    }
  }
  \end{scope}
  \node [above] at (mode.north) {\tt\mode};
}
\end{tikzpicture}

\end{document}

enter image description here

14

PSTricks knows one more fill style for transparent colors: shape with using the shapealpha value and one of the possible blendmodes. More can easily be realized if they are supported by Ghostscript:

  • /Normal ->0
  • /Compatible ->1
  • /Screen ->2
  • /Multiply ->3
  • /HardLight ->4
  • /Darken ->5
  • /Lighten ->6
  • /Difference ->7
\documentclass{article}
\usepackage{pstricks}
\def\Frames{%
\psframe*[linecolor=red](0,1)(3,4)
\psframe[fillcolor=blue,fillstyle=shape](2,2)(5,5)
\psframe[fillcolor=green,fillstyle=shape](1,0)(4,3)
\pscircle[fillcolor=cyan,fillstyle=shape,shapealpha=0.3](1.5,3.5){1.25}}

\begin{document}

\begin{pspicture}(5,5)% default blendmode
\Frames\rput(1.5,3.5){\huge\textbf{0}}
\end{pspicture}
\hfill
\begin{pspicture}(5,5)
\psset{blendmode=1}% type /Compatible
\Frames\rput(1.5,3.5){\huge\textbf{1}}
\end{pspicture}
\begin{pspicture}(5,5)
\psset{blendmode=2}% type /Screen
\Frames\rput(1.5,3.5){\huge\textbf{2}}
\end{pspicture}
\hfill
\begin{pspicture}(5,5)
\psset{blendmode=3}% type /Multiply
\Frames\rput(1.5,3.5){\huge\textbf{3}}
\end{pspicture}

\end{document}

enter image description here

2
  • I have several questions about this: 1)Is this documented? (I couldn't find supported blend modes explained in the PSTricks PDF manual); 2)Can blend modes be used with lines too, or only with filled areas? ...and 3) Is there any way of getting additive transparency? (so that R+G+B=White)
    – cesss
    Nov 18, 2017 at 12:50
  • run texdoc pst-news08 or see ctan.org/tex-archive/graphics/pstricks/base/doc
    – user2478
    Nov 18, 2017 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .