• [转]硬件遮挡查询(Hardware Occlusion Queries)


    http://blog.csdn.net/skybreaker/article/details/1828104

    本节将详细介绍硬件遮挡查询的使用以及优化策略。

    如同上面提到的,通过硬件遮挡查询,我们能够直接获得所提交的物体是否被绘制到场景中。从而得知物体是否被遮挡(被遮挡的物体是不会出现在场景中的)。如果直接提交整个物体mesh,遮挡查询的开销显然太大了。我们只要提交物体的AABB(轴向包围盒)即可,这样仍然可以保证算法是“保守”的。包围盒越接近于物体效率就会越高。另外,使用一个小的渲染目标(如320*240)可以明显加快速度,同时基本不会产生任何副面效果。但是,仅仅是使用AABB和小渲染目标,遮挡查询的开销仍然十分巨大。为此我们还需要进一步对遮挡查询的执行序列进行优化:

    下图是优化前CPU和GPU的执行情况:

    从上图我们可以看出:虽然硬件遮挡查询操作本身十分耗时,但是进行遮挡查询时只有GPU在高负荷工作,CPU在提交查询之后就处于闲置状态。因此需要将提交查询和获得查询结果之间的时间间隔尽可能的充分利用。

    下图是经过优化后的执行序列:

    从上图我们可以看出:

    原先用于等待查询结果的时间被用于提交其他查询,在GPU进行遮挡运算的同时CPU并没有空闲等待,而是进行其他工作。
    为了进一步提高遮挡查询效率,还可以在提交查询之后进行各类其他运算,如AI,物理等等。

    Simple hardware occlusion query usage

    An occlusion query is fundamentally simple. The GPU tells us how many pixels should have ended up visible on-screen.

    These pixels successfully passed various tests at the end of the pipeline-such as the frustum visibility test, the scissor test, the alpha test, the stencil test, and the depth test.


    The step:
    1.Create a query
    2.Disable rendering to screen(set the color mask of all chanels to False).
    3.Disable writing to depth buffer(just test against, but don't update, the depthe buffer).
    4.Issue query begin(which resets the counter of visible pixels).
    5."Render" the object's bounding box(it will only do depth testing; pixels that pass depth testing will not be rendered on-screen because rendering and depth writing were disabled).
    6.End query(stop counting visible pixels).
    7.Enable rendering to screen.
    8.Enable depth writing(if required).
    9.Get query result(the number of "visible" pixels).
    10. If the number of visible pixels is greater than 0(or some threshold), render the complete object.

    LPDIRECT3DDEVICE9 g_pd3dDevice;
    LPDIRECT3DQUERY9  g_pSphereQuery;
    g_pd3dDevice->CreateQuery( D3DQUERYTYPE_OCCLUSION, &g_pSphereQuery );
    g_pSphereQuery->Issue( D3DISSUE_BEGIN );
    g_pSphereMesh->DrawSubset(0);
    g_pSphereQuery->Issue( D3DISSUE_END );
    DWORD dwSphereData;
    while( g_pSphereQuery->GetData( (void*)&dwSphereData, sizeof(DWORD), 0) == S_FALSE )
    {
    // GetData is asynchronous so, if possible, try to find some extra work
    // to do here if the hardware is still rendering our scene.
    }

    Ogre Smaple_Lighting demonstrates usage of occlusion queries for lens flare.

    硬件遮挡查询存在的两个主要问题:

    1. 调用遮挡查询本身的开销。因为每次查询都增加了一次另外的绘制调用。

    2. 等待查询结果引起的延迟。

    遮挡查询可用来做遮挡剔除。适用场景:在城市中漫步,在这种视角下,有大量建筑模型被遮挡,可以提前根据遮挡查询剔除掉。

  • 相关阅读:
    appium 元素定位方法
    Mac 使用MuMu模拟器调试
    渗透测试工具Drozer安装使用(Mac)
    渗透测试工具Drozer安装使用(Windows)
    python虚拟环境搭建
    HDU 6900 Residual Polynomial【分治 NTT】
    CF 1405E Fixed Point Removal【线段树上二分】
    Educational Codeforces Round 41
    Educational Codeforces Round 39
    Educational Codeforces Round 36
  • 原文地址:https://www.cnblogs.com/pulas/p/2982842.html
Copyright © 2020-2023  润新知