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.

Hi all,

has the issue ever been resolved? I am also trying to make anaglyph running (Windows 10) by using blendMode=‘add’. The following code generates a cross (made of two rectangles one of which at an angle of 45°). The cross (both rectangles) is filled with a blue noisy pattern. I think this is supposed to indicate impossible color values after adding. However, since in this code example I only have values of zeros, I am wondering how this can be. Also when putting in there more reasonable numbers (between 0 and 255 and such without having sums greater than 255) I don’t get a satisfying result. Only when I exchange blendMode=‘add’ by blendMode=‘avg’ do I see what I expect. With the code snipped below, I then get a dark screen since all color values are 0.

win = visual.Window(fullscr = False,
monitor=‘testMonitor’,
colorSpace = ‘rgb255’,
size = [1140,912],
pos = [0,0],
screen = 0,
color=[0,0,0],
useFBO = True,
allowGUI=False,
viewOri = 0.0,
blendMode=‘add’)

dark_bar = visual.Rect(
win=win,
width=0.2,
height=1.0,
fillColor=(0, 0, 0),
pos=[0,0],
ori = 45,
colorSpace = ‘rgb255’,
opacity=0)

dark_bar2 = visual.Rect(
win=win,
width=0.2,
height=1.0,
fillColor=(0, 0, 0),
pos=[0,0],
colorSpace = ‘rgb255’,
opacity=0)

dark_bar.draw()
dark_bar2.draw()

win.flip()
event.waitKeys()

Many thanks,
Ronny

Addendum: Setting “useFBO=False” makes the rectangles shown in the wanted colors. However, at the overlapping portions, the colors are not added. Instead, the dark_bar2 is just plotted on top of the other rectangle. Whether the opacity for both rectangles is 0 or 1 does not matter. Only when I change the opacity to values unequal 0 or 1 but in between 0 and 1 I get transparency (which is not what I was aiming for). I am using Psychopy version 2021.2.3.