Glew.h and other shaders

Najib Majaj's Avatar

Najib Majaj

08 Jan, 2018 03:26 PM

Hi Chris,

Is there a reason why you removed those?
We have expanded the functionality of the sinusoidal grating plugin relying on those libraries, and now that they are gone, we cannot compile the plugin with new versions of mworks.

Best
Najib

  1. Support Staff 1 Posted by Christopher Sta... on 09 Jan, 2018 04:50 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    Until recently, MWorks' stimulus drawing code used the (rather ancient) OpenGL 2.1 API. As part of porting MWorks to iOS, I updated it to use the (somewhat less ancient) OpenGL 3.3 API, which is largely compatible with the OpenGL ES 3.0 API available on iOS.

    The source files in question were written against OpenGL 2.1 and wouldn't work with the updated stimulus code. Since they were used exactly nowhere in MWorks' core or standard plugins, I simply discarded them.

    Updating your stimulus plugin to function with the current MWorks nightly build (and upcoming 0.8 release) is going to take some work. Apple has an overview document describing the changes required to move from OpenGL 2.1 to 3.3. However, if your grating plugin derives from MWorks' stock grating, then the best starting point in probably the latest drifting grating source code.

    Of course, I'm happy to provide whatever help you need to make this transition. Alternatively, if you're interested in sharing your expanded functionality with the broader MWorks community, then we can discuss integrating your changes in to the standard grating.

    Cheers,
    Chris

  2. Christopher Stawarz closed this discussion on 29 Jan, 2018 02:55 PM.

  3. Najib Majaj re-opened this discussion on 27 Feb, 2018 04:55 PM

  4. 2 Posted by Najib Majaj on 27 Feb, 2018 04:55 PM

    Najib Majaj's Avatar

    Dear Chris,

    I had hoped that it would be easy to port some of our expanded
    functionality to the latest version of mworks, but I am worried that we
    might have hit a wall and would appreciate any help you can provide.

    The two main things we would like to achieve:

    1-Give mworks the ability to set/change gamma.
    2-Expand the drifting grating plugin to allow for multiple gratings that
    can be added and multiplied.

    I am more than happy to share our old code, but I worry that it is probably
    not as documented as you would like. Is there a chance we can chat via
    skype to make a plan.

    I know that you have been in the process of releasing a new version of
    mworks, but maybe we can at least make a plan.

    Best
    Najib

  5. Support Staff 3 Posted by Christopher Sta... on 01 Mar, 2018 03:12 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    Probably the best approach would be for me to take a look at your old code first, as that will give me a clear idea of what needs to be done. Can you point me to it?

    Thanks,
    Chris

  6. 4 Posted by Najib Majaj on 07 Mar, 2018 04:48 PM

    Najib Majaj's Avatar

    Dear Chris,

    Enclosed please fine an archive that includes the changes we care about:

    1-The changes that allowed us to do gamma correction are mostly in the
    server and the stimulus display, I believe Romesh did his best to comment
    on the code.

    2-Our drifting grating plugin builds from the old plugin, it allow for
    multiple gratings that can be added or multiplied and different windowing
    options.

    Take a look and let me know how you would like to proceed. The sooner we
    can implement the easier it is for me to push the lab to adopt the new
    mworks.

    Best
    Najib

  7. 5 Posted by mc7055 on 09 Mar, 2018 03:13 PM

    mc7055's Avatar

    Dear Najib and Chris,

    Chris, I think I got Romesh's modifications to your code to include the monitor gamma correction to work on version 7 of MWorks. I've attached the code for that, hopefully you can see where the changes were made, and incorporate them as appropriate.

    Thank you so much for working on the other aspects of MWorks (drifting gratings and words out on the firmata protocol).

    Best,
    mariana

  8. Support Staff 6 Posted by Christopher Sta... on 09 Mar, 2018 09:31 PM

    Christopher Stawarz's Avatar

    Hi Najib & Mariana,

    Thanks for sending the code. I'll try to take a look at it and get back to you early next week.

    Cheers,
    Chris

  9. 7 Posted by Najib Majaj on 09 Mar, 2018 09:38 PM

    Najib Majaj's Avatar

    Thank you Chris, much appreciated.

    Best
    Najib

  10. Support Staff 8 Posted by Christopher Sta... on 15 Mar, 2018 02:36 PM

    Christopher Stawarz's Avatar

    Hi Najib & Mariana,

    I had a look at the code you sent.

    The changes to support gamma control appear very straightforward, and I think we should make them (or equivalent) a standard MWorks feature. However, this won't happen until after the impending 0.8 release. Is that OK with you?

    The drifting grating changes are a bit more involved, although it still doesn't seem like a huge job. I think it will take a couple days of my time to update the plugin, but, again, this probably won't happen until after the 0.8 release. Are you interested in contributing these changes to MWorks, so that others in the community can use them, too? To be clear, this does not affect my willingness to work on the plugin in any way. Also, I'm not 100% sure at this point if it would even make sense to try to integrate your changes into the standard grating stimulus. I'm just wondering if you're open to that possibility.

    Cheers,
    Chris

  11. 9 Posted by Najib Majaj on 15 Mar, 2018 02:59 PM

    Najib Majaj's Avatar

    Dear Chris,

    Absolutely :-) Completely okay with us, the reason why we didn't want to
    share them is because I wasn't sure that we could support them...
    When do you anticipate the 0.8 release?

    Best
    Najib

  12. Support Staff 10 Posted by Christopher Sta... on 16 Mar, 2018 02:12 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    Absolutely :-) Completely okay with us, the reason why we didn't want to share them is because I wasn't sure that we could support them...

    Great, thanks! One benefit of sharing your code is that maintaining it becomes my job :)

    When do you anticipate the 0.8 release?

    I hope to have it out sometime in the next few weeks.

    Chris

  13. 11 Posted by Najib Majaj on 16 Mar, 2018 03:43 PM

    Najib Majaj's Avatar

    Awesome.
    Next few weeks is completely workable for us.
    Once I have chat with Romesh, there are other plugins that are not so high
    priority that I might ask your advice on.

    Best
    Najib

  14. Support Staff 12 Posted by Christopher Sta... on 08 May, 2018 02:27 PM

    Christopher Stawarz's Avatar

    Hi Najib & Mariana,

    The MWorks nightly build now includes support for setting the display gamma.

    Note that I used different keys than you did in #mainScreenInfo: set_display_gamma controls whether the gamma is set or not; and red_gamma, green_gamma, and blue_gamma specify the (inverse) gamma value for each channel. You can change these settings in MWServer's preferences window (Display -> Advanced…).

    Also, the gamma settings apply only when color management is disabled (which can also be done in Display -> Advanced…). If your goal is linear color response (e.g. for gratings), then profiling your display and enabling color management in MWorks is a better solution than changing the display gamma. But in any case, doing both at the same time makes no sense, so MWorks doesn't allow it.

    When you have a chance, please test these changes and let me know if they meet your needs.

    Thanks,
    Chris

  15. Support Staff 13 Posted by Christopher Sta... on 27 Jun, 2018 03:03 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    I'm trying to understand the definition of the "flattop" mask types in your drifting grating code (and which you also mentioned in another discussion). Searching the web for "flattop distribution" or "flat-top Gaussian" doesn't yield much info. This and this are about all I could find, and neither really matches the equation in the code.

    In said code, the value of the non-flat portion of the mask is the same as that of an un-normalized Gaussian mask with mean 1-2/N and standard deviation 2/(3*N), where N is 8 or 4 (for flattop/flattop8 and flattop4, respectively). The flat portion begins where the distance from the center equals the Gaussian mean.

    My question: Why do you use those particular values for the mean and standard deviation? Is there some reference you can point me to that explains the reasoning behind them?

    Thanks,
    Chris

  16. 14 Posted by Najib Majaj on 27 Jun, 2018 04:18 PM

    Najib Majaj's Avatar

    This comment was split into a new discussion: MATLAB getEvents function is slow

    Hi Christopher,

    Great to hear from you.
    Flatop masks or raised cosine masks are lab jargon that you probably won't
    find references for online.
    Similar to a guassian mask, the idea is to taper the age of the window.
    Hard edges typically introduces very high frequency components that are
    quite visible and the taper is meant to get rid of that.
    If you us an actual gaussian to, the top of the guassian is rounded and not
    flat, in other words the luminance starts dropping as soon as you leave the
    center of the images.
    The flattop mask is meant as work around from that, the middle of the image
    will always have the same luminance and taper only starts at some point.
    The steepness of the taper is then determined by the standard deviation of
    a gaussian and one half of the gaussian is used to taper the edge.

    Hope this is clear, if you can think of a cleaner way of achieving that, I
    would love to discuss it.

    On a different note, I have been meaning to contact you regarding data
    analysis.
    The matlab getEvents funcition is rather slow when trying to import large
    files and signals like eye position that are updated often.
    Is there a faster way to get around that problem?

    Best
    Najib

  17. Support Staff 15 Posted by Christopher Sta... on 27 Jun, 2018 05:12 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    The flattop mask is meant as work around from that, the middle of the image will always have the same luminance and taper only starts at some point.
    The steepness of the taper is then determined by the standard deviation of
    a gaussian and one half of the gaussian is used to taper the edge.

    Yes, that's all fine. The question is, why are the mean (i.e. the radius of the untapered central region) and the standard deviation defined by the particular expressions I mentioned? Do you just like the look of the taper they produce?

    if you can think of a cleaner way of achieving that, I would love to discuss it.

    I can think of a simpler and more general way of achieving it: Instead of having separate "flattop" mask types, just add another parameter for the Gaussian mask that controls what happens in the center when the mean is non-zero. That is, does it decay back toward zero, producing a ring-like mask, or does it stay at 1, producing a flat center with Gaussian outer edge (left vs. right in the attached image)?

    This is what I'll do, unless there's a particular reason to constrain the mean and standard deviation the way your plugin does.

    Thanks,
    Chris

  18. 16 Posted by Najib Majaj on 28 Jun, 2018 04:30 PM

    Najib Majaj's Avatar

    Hi Chris,

    I am a bit confused about the image that you sent, in particular, I am not
    sure why we would need the donut (left image).
    I am attaching a figure that shows a cross section of the tapers that we
    are trying to achieve.
    The idea is that you specify the size of the mask in this case 256 pixels.
    If the mask is a sharp circle, then this cross section profile would like a
    rectangle. Full transparency from -128:128 and opaque elsewhere.
    In the flattop8 condition the taper is on each side is 32 pixels wide 1/8
    of 256 hence the flattop8 designation :-)
    In the flattop4 condition the taper is 64 pixels on each side 1/4 of 256
    producing a flattop4 mask.
    There are multiple ways to achieve this with minor differences. The key is
    that the taper can't be a straight line because you produce artifacts so it
    has to look like a gaussian or a sinewave.

    Best
    Najib

  19. Support Staff 17 Posted by Christopher Sta... on 29 Jun, 2018 02:47 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    I am a bit confused about the image that you sent, in particular, I am not sure why we would need the donut (left image).

    Sorry, I should have provided more context. I don't imagine you (or anyone) would need the donut. I was just illustrating what the drifting grating's mean parameter does, namely, turn the Gaussian peak into a circle, instead of a point. (Why it works this way is not at all clear.) If you modify the Gaussian mask so that the alpha is uniformly one inside the circle (thereby filling the donut hole), you get a mask that's uniform in the center and Gaussian at the edge, which is exactly what your "flattop" masks are.

    In the flattop8 condition the taper is on each side is 32 pixels wide 1/8 of 256 hence the flattop8 designation :-)
    In the flattop4 condition the taper is 64 pixels on each side 1/4 of 256 producing a flattop4 mask.

    And to get these edge widths using MWorks' grating, you would set mean to 0.75 and 0.5, respectively:

    mean = 1 - 2/N
    1 - 2/8 = 0.75
    1 - 2/4 = 0.5
    

    There are multiple ways to achieve this with minor differences. The key is that the taper can't be a straight line because you produce artifacts so it has to look like a gaussian or a sinewave.

    OK, got it. I'll figure out the best way to integrate support for this in to MWorks.

    Thanks,
    Chris

  20. Support Staff 18 Posted by Christopher Sta... on 02 Jul, 2018 02:57 PM

    Christopher Stawarz's Avatar

    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 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

  21. Support Staff 19 Posted by Christopher Sta... on 03 Jul, 2018 03:24 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    Regarding the "flattop" mask again:

    If it's OK with you, I think I'd prefer to add a raised cosine 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

  22. 20 Posted by Najib Majaj on 05 Jul, 2018 06:50 PM

    Najib Majaj's Avatar

    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

  23. 21 Posted by Najib Majaj on 05 Jul, 2018 06:52 PM

    Najib Majaj's Avatar

    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> 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.

  24. Support Staff 22 Posted by Christopher Sta... on 06 Jul, 2018 03:24 PM

    Christopher Stawarz's Avatar

    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. (Hopefully that link works.)

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

    Cheers,
    Chris

  25. Support Staff 23 Posted by Christopher Sta... on 01 Aug, 2018 06:34 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    The current MWorks nightly build includes support for using gratings as masks. Also, as I noted elsewhere, raised cosine masks are now available. I've attached an example experiment (once again, written in MWEL) 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

  26. 24 Posted by mc7055 on 15 Aug, 2018 04:53 PM

    mc7055's Avatar

    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

  27. Support Staff 25 Posted by Christopher Sta... on 15 Aug, 2018 05:30 PM

    Christopher Stawarz's Avatar

    Hi Mariana,

    It should be there. Does my example not work?

    Chris

  28. 26 Posted by mc7055 on 15 Aug, 2018 05:39 PM

    mc7055's Avatar

    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!

  29. Support Staff 27 Posted by Christopher Sta... on 16 Aug, 2018 03:01 PM

    Christopher Stawarz's Avatar

    Hi Mariana,

    The raised cosine mask is provided by the new Mask Stimulus. 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

  30. 28 Posted by mc7055 on 17 Aug, 2018 04:38 PM

    mc7055's Avatar

    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

  31. 29 Posted by mc7055 on 17 Aug, 2018 06:09 PM

    mc7055's Avatar

    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

  32. 30 Posted by mc7055 on 17 Aug, 2018 06:24 PM

    mc7055's Avatar

    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!

  33. Christopher Stawarz closed this discussion on 28 Nov, 2018 03:57 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

07 Feb, 2019 02:24 PM
02 Feb, 2019 01:58 PM
01 Feb, 2019 06:25 PM
26 Jan, 2019 12:15 AM
18 Jan, 2019 05:44 PM