D3D疑问记录

4 篇文章 0 订阅
3 篇文章 0 订阅

1.Supersampling 和 Multisampling之间有什么差别?

在龙书《Introduction to 3D Game Programming with Directx 11》的4.1.7小节有这么一段话:

Observe the key difference between supersampling and multisampling. With supersampling, the image color is computed per subpixel, and so each subpixel could potentially be a different color. With multisampling ( Figure 4.5), the image color is computed once per pixel and that color is replicated into all visible subpixels that are covered by the polygon. Because computing the image color is one of the most expensive steps in the graphics pipeline, the savings from multisampling over supersampling is significant. On the other hand, supersampling is technically more accurate and handles texture and shader aliasing, which multisampling does not.

Multisampling
段落中提到的图也附在上面。看起来Supersampling很容易理解,但相对的Multisampling到底如何产生抗锯齿的作用,却显得让人费解了。
结合其他资料,反复读了很久这段话才明白,所谓的With multisampling, the image color is computed once per pixel and that color is replicated into all visible subpixels 与不采用Multisampling时的区别:无论采用Multisampling还是不采用任何抗锯齿技术,每个pixel只计算一次颜色值。但是Multisampling下,这个计算出来的颜色值被赋值到subpixel中被多边形覆盖的部分(也就是需要着色的部分),未覆盖区域保留原来的值(可能是背景色或上次着色的值)。
这也是为什么在一个论坛上看到这样的描述(其中it指Multisampling),说Multisampling只在画edge时有用:

OTOH, it doesn’t do anything to solve aliasing within the interior of the primitive. It only antialiases at edges; either the actual edges of primitives or when fragments are clipped by depth or stencil tests. Note that it doesn’t antialias “edges” resulting from the alpha channel.


2.texture数据类型中,颜色类型的alpha通道是干什么用的?

我们在设置texture类型时,发现DXGI_FORMAT枚举的数据中有类似以下这样的:

DXGI_FORMAT_R8G8B8A8_UNORM;  // Each element has four 8-bit unsigned components mapped to the [0, 1] range.
DXGI_FORMAT_R8G8B8A8_SNORM;  // Each element has four 8-bit signed components mapped to the [−1, 1] range.
DXGI_FORMAT_R8G8B8A8_SINT;  // Each element has four 8-bit signed integer components mapped to the [−128, 127] range.
DXGI_FORMAT_R8G8B8A8_UINT;  // Each element has four 8-bit unsigned integer components mapped to the [0, 255] range.

类型中的RGB很容易理解,但A是什么?

《Introduction to 3D Game Programming with Directx 11》中4.1.3小节回答了这个问题:

The alpha channel or alpha component is generally used to control transparency.


3.IDXGIFactory以及IDXGIFactory1,2,3…分别是什么关系?

在通过device获取对应的IDXGIFactory时,MSDN的官方示例里采用了这样的写法:

IDXGIFactory1* dxgiFactory = nullptr;
    {
        IDXGIDevice* dxgiDevice = nullptr;
        hr = g_pd3dDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice));
        if (SUCCEEDED(hr))  {
            IDXGIAdapter* adapter = nullptr;
            hr = dxgiDevice->GetAdapter(&adapter);
            if (SUCCEEDED(hr))  {
                hr = adapter->GetParent(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory));
                adapter->Release();
            }
            dxgiDevice->Release();
        }
    }
    if (FAILED(hr))
        return hr;

    IDXGIFactory2* dxgiFactory2 = nullptr;
    hr = dxgiFactory->QueryInterface(__uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory2));
    if (dxgiFactory2)
        // 说明是DirectX 11.1 or later,后续略

在龙书中的代码只实现了前半段(除去倒数四行),并且第一行和第九行中不是IDXGIFactory1而是IDXGIFactory。原因是:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值