# Vary drifting grating contrast

**URL:** <https://mworks.discourse.group/t/vary-drifting-grating-contrast/699>\
**Category:** Support\
**Created:** [July 28, 2010, 2:59pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699 "2010-07-28T14:59:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 28, 2010, 2:59pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/1 "2010-07-28T14:59:06Z")

</div>

The attached patch makes the alpha\_multiplier parameter work to vary the contrast of the drifting\_grating.  
Works for me with very light testing (attached example).

M

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 28, 2010, 2:59pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/2 "2010-07-28T14:59:06Z")

</div>

Attachments:

- [0001-Make-alpha\_multiplier-work.patch](https://mworks.discourse.group/uploads/short-url/pASM46d98Jna9B7HNxl9NRDD5Tm.patch) (2.04 KB)
- [TestDynamic.xml](https://mworks.discourse.group/uploads/short-url/9EB3iVvaaO5V811G0ep1nvvCJJ5.xml) (1.75 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 28, 2010, 7:23pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/3 "2010-07-28T19:23:28Z")

</div>

After thinking about this a bit, I should clarify: this only works when the background is at (0.5, 0.5, 0.5). However, all the gratings have a mean luminance of 0.5, as far as I can tell. So I don’t think there are many reasons to use a different color background.

One way to make it work with all backgrounds would be to get the background color and use it to set the RGB values in this patch. However it’s probably cleaner to just have the grating blend correctly on the background. Because the texture uses GL\_COMBINE (not GL\_BLEND), I didn’t spend time to figure out how to do that correctly.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 28, 2010, 8:14pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/4 "2010-07-28T20:14:53Z")

</div>

Thanks for the patch, Mark. I’ll check it out and get back to you.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 29, 2010, 11:43pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/5 "2010-11-29T23:43:32Z")

</div>

Hi Chris,

Any progress on this? If you have something to test I can pull the nightly and test it.

best  
Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 30, 2010, 4:39pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/6 "2010-11-30T16:39:13Z")

</div>

Hi Mark,

Sorry for ignoring this for so long. I wanted to think about it some more before committing it, but then it completely fell off my radar.

Anyway, the patch seems fine, and I just [committed it](https://github.com/mworks-project/mw_core_plugins/commit/97d921ec3c4c8dac435a4b24053601c4e4a575e3). It’ll be in tonight’s nightly build.

For future reference: It’s possible to get the same effect by drawing a semi-transparent rectangle over the grating in your experiment. I’ve attached an example that does this for gray, red, green, and blue backgrounds. If you ever want to adjust the contrast of a grating against a background that’s not neutral gray, this is a way to do it.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 30, 2010, 4:39pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/7 "2010-11-30T16:39:13Z")

</div>

Attachment: [DGContrast.xml](https://mworks.discourse.group/uploads/short-url/qERBx2S8KAcJjLBCeKBT9kGAjsf.xml) (4.8 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 30, 2010, 8:36pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/8 "2010-11-30T20:36:34Z")

</div>

Thank you Chris. I’ll look into both options next week and let you know.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [December 8, 2010, 10:30pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/9 "2010-12-08T22:30:07Z")

</div>

This all works. Thanks!

One additional comment - can you add some sort of error checking on XML field names in the server? For example, if an XML property name is specified that is unsupported for that object, have the server display an error at parse time. Right now if you set the ‘alpha’ or ‘contrast’ or ‘alapha\_multiplier’ field of a rectangle object, those fields are ignored silently.

T hanks!  
Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [December 9, 2010, 12:04am UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/10 "2010-12-09T00:04:11Z")

</div>

> One additional comment - can you add some sort of error checking on XML field names in the server?

Big changes / improvements are coming on this front. Stay tuned.

– Dave

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 11:51pm UTC](https://mworks.discourse.group/t/vary-drifting-grating-contrast/699/11 "2022-07-19T23:51:55Z")

</div>

Closed on July 19, 2022, 11:51pm UTC


