Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is explicit multisampling different from regular multisampling in OpenGL

I was reading this tutorial on MSAA in deferred shading, from 28byteslater.com.

It says that in explicit multisampling we can access a particular sample.

Could not we do the same from a regular texture that was bound to GL_TEXTURE_2D_MULTISAMPLE for instance?

This was the shader code that I used to use earlier for accessing individual samples (without using explict multisampling):

uniform sampler2DMS Diffuse;

ivec2 Texcoord          = ivec2(textureSize(Diffuse) * In.Texcoord);
vec4  colorFirstSample  = texelFetch(Diffuse, Texcoord, 0);
vec4  colorSecondSample = texelFetch(Diffuse, Texcoord, 1);
vec4  colorThirdSample  = texelFetch(Diffuse, Texcoord, 2);

The only thing I see different in explicit multisampling is that they are using texelFetchRenderbuffer() in shader and texture is bound to GL_TEXTURE_RENDERBUFFER_NV. Plus If I remember correctly its not possible to use a RenderBuffer in shader and now we can?

like image 489
viktorzeid Avatar asked Mar 21 '23 23:03

viktorzeid


1 Answers

I think you are a little confused. Before OpenGL 3.2 / DirectX 10 came along, the only way to do multisample anti-aliasing (MSAA) was to blit a multisample buffer and have it do the "resolve" (the process by which multiple samples are literally resolved into a single sample for normal output). This was about all multisampling was good for, too - it could not be used explicitly in shaders.

GL3.2 / DX10 introduced "explicit" (programmable) multisample resolve, in the form of multisample textures. The way you access the individual samples in a shader is through the use of texelFetch (...). This new functionality allows MSAA to be implemented in deferred shading engines, because now the lighting shader is able to multisample resolve the G-Buffers when they are fetched. This new feature also opened up the possibility of using multisample buffers for things unrelated to anti-aliasing, order-independent transparency through a technique called Stencil Routed A-Buffering comes to mind immediately.

In short, DX10-class hardware allows multisample buffers to function as textures. This means very little had to be done to existing shading languages like HLSL and GLSL in order to expose multisample fetches; you do sacrifice certain things like mipmaps and filtering, but you can actually implement those yourself if you are so inclined. One thing DX10 lacked, however, was support for multisample depth textures - DX10.1 added this.

Prior to OpenGL 3.2, there were vendor specific extensions (e.g. NV_explicit_multisample) that allowed multisample texturing, since the hardware had already supported it since ~2007 (with the release of DX10). On OpenGL 3.2 implementations, ignore the vendor specific stuff and simply use ARB_texture_multisample.

like image 113
Andon M. Coleman Avatar answered Apr 25 '23 04:04

Andon M. Coleman