# Glew.h and other shaders

**URL:** <https://mworks.discourse.group/t/glew-h-and-other-shaders/308>\
**Category:** Support\
**Created:** [January 8, 2018, 3:26pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308 "2018-01-08T15:26:13Z")\
**Posts on this page:** 16\
**Page:** 2

<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 2, 2018, 2:57pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/21 "2018-07-02T14:57:13Z")

</div>

Hi Najib,

Another point that needs some clarification:

> Our drifting grating plugin builds from the old plugin, it allows for multiple gratings that can be added or multiplied

I understand that you’re referring to the “overlay” gratings that your plugin supports. However, saying that these are “added or multiplied” to/with the grating they overlay doesn’t accurately describe what the code you gave me actually does.

In effect, your overlays are a second mask on the base grating. That is, they modify the alpha channel of the underlying grating+mask, but _not_ the color (i.e. RGB values). The “shape” of the mask is itself a grating (sinusoid or square, which you’ve called “pulse”). While the net effect of this masking may look similar to multiplying two gratings, the operations aren’t identical.

I bring this up not to dispute what you’re doing, but just to confirm that this is, in fact, what you want. Personally, I think having the option to use a grating as a mask is pretty neat, particularly in concert with the [layer and mask](https://mworks.discourse.group/discussions/questions/790) functionality I’m also working on. (For example, you could apply a grating mask to a static image or moving dot field.)

Alternatively, if you actually want to multiply two gratings, we can add support for that. In fact, we could support both techniques (grating-as-mask and grating multiplication), if that would be useful.

Please let me know how you’d like to proceed.

Thanks,  
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:** [July 3, 2018, 3:24pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/22 "2018-07-03T15:24:09Z")

</div>

Hi Najib,

Regarding the “flattop” mask again:

If it’s OK with you, I think I’d prefer to add a [raised cosine](https://en.wikipedia.org/wiki/Raised-cosine_filter) mask to MWorks. That will avoid the confusion of having two, sort-of-Gaussian mask types.

The raised cosine mask will be characterized by a single parameter, `edge_width`, which specifies the width of the sinusoidal edge as a fraction of the total width (i.e. diameter) of the mask. Hence, an edge width of 0.125 will produce a mask similar to your “flattop8”. (This will also be the default edge width.)

Does this sound OK to you?

Thanks,  
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:** [July 5, 2018, 6:50pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/23 "2018-07-05T18:50:18Z")

</div>

Hi Chris,

Thanks again for staying on top of this. We are in the process of upgrading  
one of our rigs and it will be great to have this plugin available, it will  
make the transition so much easier.

> I understand that you’re referring to the “overlay” gratings that your  
> plugin supports. However, saying that these are “added or multiplied”  
> to/with the grating they overlay doesn’t accurately describe what the code  
> you gave me actually do

You are absolutely right my description was brief and inaccurate.

> In effect, your overlays are a second mask on the base grating. That is,  
> they modify the alpha channel of the underlying grating+mask, but _not_  
> the color (i.e. RGB values). The “shape” of the mask is itself a grating  
> (sinusoid or square, which you’ve called “pulse”). While the net effect of  
> this masking may look similar to multiplying two gratings, the operations  
> aren’t identical.

Correct. When I said multiply, I meant alpha multiply, but your reading of  
the code is the correct thing.

> I bring this up not to dispute what you’re doing, but just to confirm that  
> this is, in fact, what you want. Personally, I think having the option to  
> use a grating as a mask is pretty neat, particularly in concert with the layer  
> and mask http:///discussions/questions/790 functionality I’m also  
> working on. (For example, you could apply a grating mask to a static image  
> or moving dot field.)

Yes, this functionally basically allows you to do many thing including  
combine two gratings in different ways, either to produce a plaid, or to  
produce and inter-digitated pattern that alternates between a two grating  
of different orientation.

> Alternatively, if you actually want to multiply two gratings, we can add  
> support for that. In fact, we could support both techniques  
> (grating-as-mask and grating multiplication), if that would be useful.

Multiplying two grating might be useful, but can’t think of any direct  
needs right now. I think that focusing on the above is what’s important. I  
also am looking forward for the layer and mask functionality, your link  
doesn’t work but I hope it will be coming soon.

Best  
Najib

---

<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 5, 2018, 6:52pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/24 "2018-07-05T18:52:49Z")

</div>

Hi Chris,

> Regarding the “flattop” mask again:
> 
> If it’s OK with you, I think I’d prefer to add a raised cosine  
> [https://en.wikipedia.org/wiki/Raised-cosine\_filter](https://en.wikipedia.org/wiki/Raised-cosine_filter) mask to MWorks. That  
> will avoid the confusion of having two, sort-of-Gaussian mask types.

It is funny that you mention that, I was just chatting with our resident  
programmer and he suggested a raised cosine since it is nice and defined  
over particular ranges, unlike a guassian that extends to infinity and you  
have to decide when to cut it off.

> The raised cosine mask will be characterized by a single parameter,  
> edge\_width, which specifies the width of the sinusoidal edge as a  
> fraction of the total width (i.e. diameter) of the mask. Hence, an edge  
> width of 0.125 will produce a mask similar to your “flattop8”. (This will  
> also be the default edge width.)
> 
> Does this sound OK to you?

This sounds great to me. Thanks.

---

<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 6, 2018, 3:24pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/25 "2018-07-06T15:24:30Z")

</div>

Hi Najib,

> Multiplying two grating might be useful, but can’t think of any direct needs right now. I think that focusing on the above is what’s important.

OK, we’ll stick with grating-as-mask for now.

> I also am looking forward for the layer and mask functionality, your link doesn’t work but I hope it will be coming soon.

Sorry, I was just linking to the [relevant discussion](https://mworks.tenderapp.com/discussions/questions/790). (Hopefully that link works.)

The layer and mask stuff is mostly done. I’ll send you more info on it soon.

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:** [August 1, 2018, 6:34pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/26 "2018-08-01T18:34:44Z")

</div>

Hi Najib,

The current MWorks [nightly build](https://mworks.github.io/downloads/) includes support for using [gratings as masks](https://mworks.github.io/documentation/latest/components/drifting_grating_stimulus.html#mask). Also, as I [noted elsewhere](https://mworks.tenderapp.com/discussions/questions/790#comment_45822690), [raised cosine masks](https://mworks.github.io/documentation/latest/components/mask_stimulus.html#mask) are now available. I’ve attached an example experiment (once again, written in [MWEL](https://mworks.github.io/documentation/latest/mwel/index.html)) that demonstrates both features.

As you can see, the base grating, raised-cosine mask, and mask grating are all separate stimuli, brought together in a layer. This differs from your implementation, where they were all part of a single stimulus. However, the end result should be equivalent. Also, breaking the pieces out separately lets you use them in other contexts, too.

When you have a chance, please check this out, and let me know if it meets your needs.

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:** [August 1, 2018, 6:34pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/27 "2018-08-01T18:34:44Z")

</div>

Attachment: [mask\_grating.zip](https://mworks.discourse.group/uploads/short-url/yymFf5LXgSCwygucWkbTmMUbW7W.zip) (629 Bytes)

---

<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:** [August 15, 2018, 4:53pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/28 "2018-08-15T16:53:00Z")

</div>

Hi Chris,

Did I make a mistake with my download or the current (downloaded yesterday)  
‘nightly built’ version of MWorks does not have the ‘raised-cosine mask’?

Thank you!  
mariana

---

<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:** [August 15, 2018, 5:30pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/29 "2018-08-15T17:30:54Z")

</div>

Hi Mariana,

It should be there. Does my example not work?

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:** [August 15, 2018, 5:39pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/30 "2018-08-15T17:39:50Z")

</div>

Hi Chris,

Your example works, but I was trying to edit an exiting script on XML  
format (or via the MWorksEditor), and I could find the property:  
‘edge\_width’, and it was giving me an error message saying that  
‘raised\_cosine’ is not a valid type of mask. It seems a bit mysterious to  
me; as your script works.

Thanks!

---

<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:** [August 16, 2018, 3:01pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/31 "2018-08-16T15:01:13Z")

</div>

Hi Mariana,

The raised cosine mask is provided by the new [Mask Stimulus](https://mworks.github.io/documentation/latest/components/mask_stimulus.html). The drifting grating doesn’t support it. In fact, the grating’s integrated support for masks should be considered deprecated. The support that’s there will remain, but any new mask types and features will only go in the mask stimulus. (However, the grating’s support for _being_ a mask is not deprecated, obviously.)

I’ve attached an XML version of the mask\_demo experiment, in case that’s helpful.

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:** [August 16, 2018, 3:01pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/32 "2018-08-16T15:01:13Z")

</div>

Attachment: [mask\_demo.xml](https://mworks.discourse.group/uploads/short-url/3CKqMumeQgl6iewxXtNvThIs1Dv.xml) (3.02 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:** [August 17, 2018, 4:38pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/33 "2018-08-17T16:38:21Z")

</div>

Hi Chris,

Thank you! I couldn’t find a ‘mask’ on the MWEditor, and I was not sure how  
to call it in XML. It’s working nicely.

Thank you!  
mariana

---

<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:** [August 17, 2018, 6:09pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/34 "2018-08-17T18:09:29Z")

</div>

Hi Chris,

One more question, did the gamma calibration got also included on the last  
nightly built? The masking looks great, but it seems like it does not have  
the gamma calibration working.

Thank you,  
mariana

---

<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:** [August 17, 2018, 6:24pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/35 "2018-08-17T18:24:01Z")

</div>

Hello again, Chris,

Apologies, it seems to be working.

I’ll do a small calibration test, but if I don’t bug you again, please  
disregard the last email.

Thank you!

---

<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, 9:43pm UTC](https://mworks.discourse.group/t/glew-h-and-other-shaders/308/36 "2022-07-19T21:43:22Z")

</div>



[Previous page](https://mworks.discourse.group/t/glew-h-and-other-shaders/308.md?page=1)
