Draw shape with Gaussian-blurred edges

I'm trying to render a shape (circle or square) over a PTB stimulus. Basically, I'm trying to create a mask over my stimulus that greys-out part of the underlying stimulus.


I know how to draw a Gaussian window into a stimulus (e.g. DriftDemo2 or BubblesDemo), which masks everything but a region of the stimulus. I can reverse this mask, for example, in the line:


mask(:, :, 2) = white * (1 - gauss);

... by adjusting to the following:


mask(:, :, 2) = white * gauss;

This produces a small region of the stimulus that is covered by the mask. However, the mask, being defined by its Gaussian function, is only opaque at its very centre. The Gaussian function rolls off from the central pixel, meaning that rather than getting a true mask with a Gaussian edge, I just have a semi-transparent Gaussian blob at the centre of the image. Nothing is truly masked.


One potential solution I figured would be to simply draw my mask as a fixed shape (e.g. FillRect or FillOval), and then use CreateGaussian2DBlurShader() to apply a Gaussian blur to the edge of my shape in post-processing. However, I don't wish to Gaussian blur my entire underlying stimulus (just the edge of the mask), and it seems (I assume) that the Gaussian blur produced by this function doesn't apply any alpha blending to the edge of my FillRect or FillOval shape.


I'm wondering what the best solution to achieve this would be. Essentially, I'm just trying to create a filled shape (a square or circle) of a fixed size (say for example 500x500 pixels), and then have a Gaussian alpha rolloff within that shape, with a known standard deviation (e.g. 5 pixels). The resultant image would thus be my original, unmodified stimulus, with a shape overlaid which is mostly opaque, but has a soft edge produced by a Gaussian alpha rolloff. I'd prefer for the Gaussian rolloff to occur within the shape, but I'd settle for a solution which applies the blur outside the shape, so long as I can know what the SD of the Gaussian is...