4

I'm having trouble to blend colors with TikZ. The MWE below does not render the blend in my system. I'm on Windows Xp with MiKTeX 2.9 and the latest version of TikZ/PGF downloaded and installed from CTAN. I don't know if this comes from my PDF viewer, since Sumatra doesn't even show but the first blend group, and Adobe Reader does render all the groups, but incorrectly. Any hints?

The code is pretty lame, just with the aim to make it as direct as possible and avoid any chance of issues coming from expansion, groups, or the likes.

EDIT: There must be something wrong with my code, because with Adobe Reader as PDF viewer, the code in Blend/transparency styles in pstricks and TikZ renders correctly.

\documentclass[11pt]{article}

\usepackage{tikz}

\pagestyle{empty}

\begin{document}

\begin{tikzpicture}[
  %remember picture,
  %overlay,
]
 \begin{scope}[blend group=lighten]
   \fill[green] (90:1) circle[radius=1.5];
   \fill[blue] (180:1) circle[radius=1.5];
   \fill[red] (0:1) circle[radius=1.5];
 \end{scope}
 \begin{scope}[xshift=6cm,blend group=darken]
   \fill[green] (90:1) circle[radius=1.5];
   \fill[blue] (180:1) circle[radius=1.5];
   \fill[red] (0:1) circle[radius=1.5];
 \end{scope}
 \begin{scope}[xshift=12cm,blend group=multiply]
   \fill[green] (90:1) circle[radius=1.5];
   \fill[blue] (180:1) circle[radius=1.5];
   \fill[red] (0:1) circle[radius=1.5];
 \end{scope}
 \begin{scope}[yshift=-4cm,blend group=screen]
   \fill[green] (90:1) circle[radius=1.5];
   \fill[blue] (180:1) circle[radius=1.5];
   \fill[red] (0:1) circle[radius=1.5];
 \end{scope}
 \begin{scope}[yshift=-8cm,blend group=overlay]
   \fill[green] (90:1) circle[radius=1.5];
   \fill[blue] (180:1) circle[radius=1.5];
   \fill[red] (0:1) circle[radius=1.5];
 \end{scope}
\end{tikzpicture}
\end{document} 

PNG obtained from the PDF file through ImageMagick

Marcos
  • 5,422
  • I do not know, if it is TikZ' fault or the readers fault (unfortunately I am having the same tools as you), but it helps a bit, if you take green instead of yellow. Maybe easier to calculate the RGB-mixes then... I dunno. – LaRiFaRi Jun 05 '15 at 08:37
  • @LaRiFaRi: Right. I have made the amendment, although it doesn't solve the issue. – Marcos Jun 05 '15 at 08:42
  • Sure. Well, your example does look correct. Referring to here http://tex.stackexchange.com/a/162018 and page 342 of the PGF manual. I set my document to \pdfminorversion=7 but that has no effect. – LaRiFaRi Jun 05 '15 at 08:47
  • I would report this to the maintainer. I also tried rgb definitions like \definecolor{YELLOW}{rgb}{1,1,0}. If this blending is just supported for red|green|blue and \definecolor{rg}{rgb}{1,1,0}|\definecolor{gb}{rgb}{0,1,1}|\definecolor{br}{rgb}{1,0,1} (and all mixes with white and black), it should at least be mentioned in the manual. – LaRiFaRi Jun 05 '15 at 09:02
  • Actually, I had not contemplated the possibility of such a constraint! I'll wait a little longer to see if somebody comes up with a way to tackle this problem. – Marcos Jun 05 '15 at 09:24
  • Can you add the screenshot of what you see? What do you mean by does not render? – percusse Jun 05 '15 at 09:49
  • @percusse: Added. Sorry about the white space. By "not rendering the blend" I just mean that the blend is not there (but with a couple of blend groups). I hope this helps. – Marcos Jun 05 '15 at 10:01
  • 2
    I think this is the intended output. For example change the blue to orange in the dark ones and you'll see that it multiplies. Here you are using orthogonal colors in RGB and no opacity or transparency. Hence you are burning the colors. Atlernatively, add every path/.append style={fill opacity=0.75} and it should again show meaningful results. – percusse Jun 05 '15 at 10:12
  • @percusse: So it was a matter of opacity... If you turn your comment into an answer I'll check it. I have a problem with the overlay option and blend groups, but that's another post. – Marcos Jun 05 '15 at 15:57
  • 1
    See http://tex.stackexchange.com/questions/326252/how-can-i-render-filled-paths-correctly-within-blend-groups-in-tikz ! – cfr Aug 24 '16 at 02:06
  • @cfr: A great post indeed. The truth is I haven't been able to get systematically all the supposedly available blend modes to work as I expected in any of the PDF viewers I used (Sumatra and Adobe). – Marcos Aug 24 '16 at 02:18
  • @cfr: Right. Let's hope some PGF/TikZ whizz knows what to do about that. – Marcos Aug 24 '16 at 02:31
  • @Marcos A whizz who reads the manual ;). See Christopher Frings's answer to my question. In your example, I'm not sure whether my viewer just doesn't render blended colours correctly or whether the descriptions of the blend modes in the manual are simply very poor. Your output matches the examples in the manual as far as I can see. (The top left image is the relevant one in each case, I assume, or at least the closest.) – cfr Aug 24 '16 at 12:36
  • @cfr: Right enough. Now I remember I had a related problem about opacity and filling that was solved by switching to shading. I was thinking that in your case the difference was about filling with \nodes or with \fillings in that scenario. Good that it was as simple as that and it did not require any hacks or debugging. It was a bit hidden under a TikZ ball color actually being a shading, though. – Marcos Aug 24 '16 at 12:58

1 Answers1

1

This is the intended output. For example change the blue to orange in the dark ones and you'll see that it multiplies. Here you are using orthogonal colors in RGB and with no opacity or transparency. Hence you are burning the colors (they get saturated). The analogy to think about is

(1,0,0) + (0,1,0) + (0,0,1) = (1,1,1)
  red      green      blue  =  white or black or something else depending on the blend mode

Alternatively, add every path/.append style={fill opacity=0.75} and it should again show meaningful results.

Note that these are kind of the bleeding edge features of the PDF specs and not every viewer responded in the same fashion. Also some printers might dislike these.

percusse
  • 157,807