2

I'm interested in sub-pixel sampling my OpenGL renders around the edge silhouettes of my meshes for a computer vision task. I'm thinking of using MSAA to do it efficiently (but the application is not for anti-aliasing). The problem I find with multisampling is that in order to read the samples from the GPU I can only blit the framebuffers into a non multisampling one, thus I cannot recover individual sample information. My questions are:

  • Is there a way to impelement a fragment shader that stores the results of a per-sample (GL_SAMPLE_SHADING) computation such that I can read those samples back to CPU? I've thought of using glSampleID to index the output to different out buffers but don't know if that's possible at all. Perhaps a method like the linked-list structures used for OIT (i.e. http://on-demand.gputechconf.com/gtc/2014/presentations/S4385-order-independent-transparency-opengl.pdf)? However, there they perform all computations on GPU so I'm not sure if I can read the linked list data from the CPU in any way.

Maybe MSAA is the wrong approach and there are other methods to do so. I guess my last resort is to super sample the render x times and thus recover individual samples, but that seems to be a very inefficient solution.

PolMC
  • 21
  • 1
  • Are you rendering to a multi sampled framebuffer? If yes you can get individual samples with `texelfetch()`. – dari May 11 '17 at 14:26
  • Ah I missed texefetch, looks like a useful method. If I understand correctly then, I'd have to: Store on the first pass all the results of my shader computations on a multisampled texture (via imageStore?). Then, run a shader N times (where N is number of samples used) that simply retrieves the image samples using texelfetch? – PolMC May 11 '17 at 14:41
  • You can render to it the same way as to normal textures. A for retrieving you can make a loop over all samples in the fragment shader. – dari May 11 '17 at 14:54

1 Answers1

1

You can write a compute shader which reads the samples and writes each sample's data via imageLoad, and then writes it to an SSBOs (FS outputs and image load/store would not be appropriate for the output). You'll need the usual memory barrier synchronization when it comes time to read it, but this way, you can write directly to a buffer object, rather than having to use a PBO to read from a texture.

The hardest part will be converting gl_GlobalInvocationID and the other compute shader inputs into the index in the SSBO array as well as the texture coordinate and sample index for your imageLoad operation.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982