self downsampling multisample texture to classical

Hello and Happy new Year everyone. :slight_smile:

I was optimize my post processing when i see that i can won memory band-witch.

For having a antialiased rendering, I render my scene in an multisample texture. But at the end of the post processing, it have to be on the frame buffer 0 witch is not multi sampled. So between depth of field blur stage and the bloom stage, i make a glBlitFramebuffer from my multisample texture to a non multisample texture.

Actually :
multisample texture -(Depth of field blur stage) -> multisample texture
multisample texture -(Downsampling by glBlitFramebuffer function)-> classical texture
classical texture -(Bloom stage)-> …

What i want to do :
multisample texture -(Depth of field blur stage) -> classical texture
classical texture -(Bloom stage)-> …

As you can see, i may won memory band-witch. :eek: Accessing each samples of a texel in the multisample texture from a shader isn’t a problem. My problem is : i have to do a linear combination of every texel samples to determine my output texel. But how compute each samples’ weight ? How does the blit function perform in this case ? I expect they shouldn’t have the same … Or maybe i’m doing a mistake ? :smiley:

Thank you for reading and answers.

(excuse my english, i’m also working on it ;))

AFAIK, each sample is just equally weighted. So, if you got 4xMSAA, each sample gets a weight of 0.25.

Mmmmmh okay. That what i expect first, until i read this paragraphs from the OpenGL 4.2 specification (in 4.3.2 Copying Pixels, at page 319)

Note that the samples in the draw buffer are not guaranteed to be at the same sample location as the read buffer, so rendering using this newly created buffer can potentially have geometry cracks or incorrect antialiasing.

That why i wasn’t sure if they are equally weighted. ^^

Thank you skynet.

I think, this doesn’t apply to your scenario, as you do downsampling and not blitting between two MSAA buffers.

What this sentence means is that if you blit from MS buffer A to MS buffer B and try to do subsequent rendering in buffer B, antialiasing might be screwed up a little, because the sample locations of A and B don’t necessarily match.
Imagine for instance, sample 0 in buffer A is on the ‘left side’ of the pixel, but in buffer B sample 0 is on the ‘right side’. While rendering into A, sample 0 might have turned blue without touching the rest of the samples. When you now blit that into B, that blue sample suddenly ‘moves’ from the left side to the right side of the pixel, alongside with the depth/stencil information.
If you then render to B, you render against slightly misplaced samples which could screw up antialiasing at pixels where polygons of A and B meet.