DirectX 10 中多重采样的操作顺序

发布于 2024-11-26 02:25:33 字数 537 浏览 4 评论 0原文

我对 DirectX 10 中抗锯齿所需完成的过程感到困惑。我以前根本没有做过,所以可能只是我对一般过程感到困惑。

这是我到目前为止所知道的(或者我认为我知道的):您需要为着色器中使用的 RasterizerState 对象启用多重采样,并且交换链描述 (DXGI_SWAP_CHAIN_DESC) 中的 SampleDesc 需要设置为支持的值计数(质量应该保持为 0,因为其他值或特定于硬件 - 尽管我不知道有什么用)。在准备更多绘制的调用(ClearRenderTargetView 和 IASetInputLayout)和对 Present 的调用之间,应将后台缓冲区下采样(通过 ResolveSubresource)为其他大小相等的纹理。然后,(这是我找不到任何东西的部分)以某种方式呈现下采样的纹理。

难道是我一路上遇到了什么麻烦事?或者我只是在最后一步犯了错误?我看到一些资源提到在最后一次绘制具有多重采样着色器纹理(Texture2DMS<>)的全屏四边形时进行采样分辨率,但无法弄清楚这会带来什么,或者为什么要这样做通过设备调用来解决它。

我对此所做的任何尝试都不会提高图像质量。

I'm confused on the process that needs to be done for anti-aliasing in DirectX 10. I haven't done it at all before, so it may just be that I'm confused on the procedure in general.

Here's what I know so far (or think I know): you need to enable multisampling for your RasterizerState object that you use in the shader, and that the SampleDesc in the swap chain description (DXGI_SWAP_CHAIN_DESC) needs to be set to a supported value for Count (and that Quality should stay 0, since other values or hardware-specific - though I don't know what for). Between the calls to prepare for more drawing (ClearRenderTargetView and IASetInputLayout) and the call to Present, the back buffer should be downsampled (via ResolveSubresource) to an otherwise equal-sized texture. Then, (this is the part I can't find anything on) somehow present the downsampled texture.

Do I have something messed up along the way? Or am I just mistaken on the last step? I saw a few resources refer to doing the sampling resolution during one last draw to a full-screen quad with a multisampled shader texture (Texture2DMS<>), but can't figure out what that would entail, or why you would do it over the device call to just resolve it that way.

Any attempt I've made at this doesn't produce any increase in image quality.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城泪 2024-12-03 02:25:33

编辑:我正在使用DX11,你只需使用D3D10_而不是D3D11_,谢谢DeadMG。

您不需要进行任何下采样。

了解您的 GPU 支持哪种质量模式和样本数量。
你说质量等级应该是0,这是错误的。使用它来获取支持的质量模式和样本计数:

UINT GetMSAAQuality(UINT numSamples,DXGI_FORMAT format)
    {
        UINT q=-1;
        HR(m_device->CheckMultisampleQualityLevels(format,numSamples,&q));
        return q-1;
    }

    // Use it like this:
    UINT sampleCount=4; // You set this
    UINT sampleQuality=GetMSAAQuality(sampleCount,DXGI_FORMAT_CHOOSE_ONE);

    // For swap chain
    DXGI_SWAP_CHAIN_DESC d;
    d.SampleDesc.Count=sampleCount;
    d.SampleDesc.Quality=sampleQuality;

        // Now for all the textures that you create for your
        // render targets and also for your depth buffer
        D3D11_TEXTURE2D_DESC dtex;
        dtex.SampleDesc.Quality=sampleQuality;
        dtex.SampleDesc.Count=sampleCount;

        // Now for all your render target views you must set the correct dimension type
        // based on if you use multisampling or not
        D3D11_RENDER_TARGET_VIEW_DESC drtv;
        dRtSwapChain.ViewDimension=sampleQuality==0?D3D11_RTV_DIMENSION_TEXTURE2D:D3D11_RTV_DIMENSION_TEXTURE2DMS;

 // For depth stencil view
D3D11_DEPTH_STENCIL_VIEW_DESC ddsv;
ddsv.ViewDimension=sampleQuality==0?D3D11_DSV_DIMENSION_TEXTURE2D:D3D11_DSV_DIMENSION_TEXTURE2DMS;

如果您想在着色器中读取多重采样纹理(例如,如果您渲染全屏四边形),则必须声明纹理Texture2DMS<>。

EDIT: I'm using DX11, you just use D3D10_ instead of D3D11_, thanks DeadMG.

You don't need to do any downsampling.

Find out what kind of quality modes and sample count your GPU supports.
You said that the quality level should be 0, that is wrong. Use this to get the supported quality modes with sample counts:

UINT GetMSAAQuality(UINT numSamples,DXGI_FORMAT format)
    {
        UINT q=-1;
        HR(m_device->CheckMultisampleQualityLevels(format,numSamples,&q));
        return q-1;
    }

    // Use it like this:
    UINT sampleCount=4; // You set this
    UINT sampleQuality=GetMSAAQuality(sampleCount,DXGI_FORMAT_CHOOSE_ONE);

    // For swap chain
    DXGI_SWAP_CHAIN_DESC d;
    d.SampleDesc.Count=sampleCount;
    d.SampleDesc.Quality=sampleQuality;

        // Now for all the textures that you create for your
        // render targets and also for your depth buffer
        D3D11_TEXTURE2D_DESC dtex;
        dtex.SampleDesc.Quality=sampleQuality;
        dtex.SampleDesc.Count=sampleCount;

        // Now for all your render target views you must set the correct dimension type
        // based on if you use multisampling or not
        D3D11_RENDER_TARGET_VIEW_DESC drtv;
        dRtSwapChain.ViewDimension=sampleQuality==0?D3D11_RTV_DIMENSION_TEXTURE2D:D3D11_RTV_DIMENSION_TEXTURE2DMS;

 // For depth stencil view
D3D11_DEPTH_STENCIL_VIEW_DESC ddsv;
ddsv.ViewDimension=sampleQuality==0?D3D11_DSV_DIMENSION_TEXTURE2D:D3D11_DSV_DIMENSION_TEXTURE2DMS;

If you want to read a multisampled texture in your shader (if you render a fullscreen quad for example) you must declare the texture Texture2DMS<>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文