显式多重采样与OpenGL中的常规多重采样有何不同 [英] How is explicit multisampling different from regular multisampling in OpenGL

查看:188
本文介绍了显式多重采样与OpenGL中的常规多重采样有何不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读本教程在MSAA中以递减阴影显示,来自28byteslater.com.

它表示在显式多重采样中,我们可以访问特定样本.

我们不能从绑定到GL_TEXTURE_2D_MULTISAMPLE的常规纹理上做同样的事情吗?

这是我以前用来访问单个样本(不使用显式多重采样)的着色器代码:

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

我在显式多重采样中唯一看到的不同是它们在着色器中使用了texelFetchRenderbuffer(),并且纹理绑定到了GL_TEXTURE_RENDERBUFFER_NV. 另外,如果我没记错的话,无法在着色器中使用RenderBuffer,现在可以了吗?

解决方案

我认为您有点困惑.在OpenGL 3.2/DirectX 10出现之前,进行多样本抗锯齿(MSAA)的唯一方法是将多样本缓冲区变为b并使其解析"(将多个样本从字面上解析为单个样本的过程).正常输出).这也说明了所有多重采样也是有好处的-无法在着色器中明确使用.

GL3.2/DX10以多样本纹理的形式引入了显式"(可编程)多样本解析.在着色器中访问单个样本的方式是通过使用texelFetch (...).这项新功能使MSAA可以在延迟着色引擎中实现,因为现在,照明着色器能够在提取G缓冲区时对G缓冲区进行多重采样解析.这一新功能还使人们立即想到了使用多样本缓冲区处理与抗锯齿无关,与顺序无关的透明性的事情,这种技术立即被想到.该模板称为Stencil Routed A-Buffering.

简而言之,DX10类硬件允许多重采样缓冲区充当纹理.这意味着要暴露多重采样,几乎不需要对诸如HLSL和GLSL之类的现有着色语言进行任何操作.您确实牺牲了某些东西,例如mipmap和过滤,但是如果您愿意的话,实际上可以自己实现这些东西. DX10缺少的一件事是对多样本深度纹理的支持-DX10.1添加了此功能.

在OpenGL 3.2之前,存在特定于供应商的扩展名(例如NV_explicit_multisample),该扩展名允许多样本纹理化,因为自2007年以来(DX10发行版),硬件已经支持它.在OpenGL 3.2实现上,请忽略供应商特定的内容,而只需使用ARB_texture_multisample.

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?

解决方案

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.

这篇关于显式多重采样与OpenGL中的常规多重采样有何不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆