Trouble with blendMode='add'

Dear Forum- I could use some help trying to get demo code working where colors add (for use with anaglyph glasses). I’m surely doing something old-fashioned and wrong, but any idea why the code snippet below does not show red and blue rectangles, with their intersection magenta (red+blue)? Thanks, Steve Engel


import psychopy.visual
import psychopy.event
win = psychopy.visual.Window(
screen=0,
size=[400, 400],
units=“pix”,
fullscr=False,
colorSpace=‘rgb1’,
blendMode=‘add’,
color=[0, 0, 0],
)
rect = psychopy.visual.Rect(
win=win,
units=“pix”,
width=200,
height=50,
opacity=1.0,
lineWidth=0.0,
colorSpace=‘rgb1’,
fillColor=[1, 0, 0],
)
rect2 = psychopy.visual.Rect(
win=win,
units=“pix”,
width=50,
height=200,
opacity=1.0,
lineWidth=0.0,
colorSpace=‘rgb1’,
fillColor=[0, 0, 1],
)
rect.draw()
rect2.draw()
win.flip()
psychopy.event.waitKeys()
win.close()

you may have misunderstand what psychopy means by drawing colors

I don’t know about blender mode but what happens if you set the opacity of the rectangles to .5 ?

Opacity works, but as if blendMode is not ‘add’…

Hi There,

Just to confirm - are you running psychopy version 2021.2.3 ?

Thanks,
Becca

yep! thanks.

Description of the problem: I have an experiment where two images are drawn one on top of the other and the colors are added using blend mode = ‘add’. The experiment is working in PsychoPy (Builder) but when I display it on Pavlovia only one image is displayed. I think this is likely because of the blend mode. If I change the opacity to be 0.5 on both images I can then see the two images but I need them at full brightness. Does js/pavlovia not display blend mode = ‘add’ just ‘average’?

Here is what it should look like

I moved your online post here Karen because it seemed to be the same issue. However, you say that it works offline. What version are you using?

Yes, it works perfectly offline. I am using version v2021.2.3 here is the repo. Taking a closer look at the python vs the js code it seems like blendmode is ignored in the js code? Here are screenshots of the code that sets up the window

Python:

JS:

P.S. Steve and I are working on the problem together. We worked out that to blend our images properly with a black background we had to draw two white polygons behind the images. The first white polygon blends with the black background to make gray and the second polygon blends with the other two to make white. We can then draw the two images on top of these polygons and they blend properly. We now just need a way to display these on pavlovia.

So does that mean that Steve’s issue in this thread (which shows Python coder code) is solved, since he doesn’t mention online?

Well, not quite, but almost. We got it to work in builder, but it is not clear still what is missing from the python code I posted to get it to work. But we can start subtracting line by line from the builder-created python code back to something simpler and see what it is.