Hi Chris,
hope you are doing fine, this is Jaime from Fribourg University.
I want to display some drifting gratings with a Gaussian mask. The negative and positive parts of the drifting gratings should have different colours. So far, I’ve found that I can control this in MWorks, but the negative will always be black. Therefore, I’ve written the following code to render the stimuli I intend to present. I wanted to ask you if there’s a more efficient way of doing this.
Thanks in advance!
Apologies for the delayed response. I had to think about this a bit.
The first thing to note is that the technique you’re using only really works for square gratings. You can see this by replacing the two colors with black and white, and comparing your composite grating with a standard grating. With any grating type other than square, the luminance pattern of the composite grating is noticeably different from the standard one. Perhaps you’re already aware of this, but I didn’t realize it at first, so I thought I should point it out.
If you only want to use square gratings, then you could simplify things by having a single layer with two non-mask gratings and using source_blend_factor and dest_blend_factor to add the top grating’s color to the bottom grating’s color, as demonstrated below:
I have a follow up question: this solution would work as well if we use a grating different from square one?
No, my previous suggestion only works for square gratings. However, after some additional thought, I came up with another solution that does seem to work correctly for all grating types.
The attached experiment demonstrates this new approach. The composite grating consists of three parts. From top to bottom, these are
a rectangle of the “low” color,
a layer containing a rectangle of the “high” color with a mask grating on top of it, and
a second layer containing a 50% gray rectangle with an inverted mask on top of it.
The experiment alternately displays the composite grating and a standard grating at one-second intervals. If you set color_low to [0,0,0] (i.e. black), you can see that the two gratings are identical, even when you change the grating type or the mask.
I think this version will do what you want. If you have any questions or run in to any issues, please let me know!