• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            醬壇子

            專注C++技術(shù) 在這里寫下自己的學(xué)習(xí)心得 感悟 和大家討論 共同進(jìn)步(歡迎批評(píng)!!!)

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              66 Posts :: 16 Stories :: 236 Comments :: 0 Trackbacks

            公告

            王一偉 湖南商學(xué)院畢業(yè) 電子信息工程專業(yè)

            常用鏈接

            留言簿(19)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            積分與排名

            • 積分 - 387834
            • 排名 - 64

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

                    OpenGL,或者D3D 的深度緩存都存在精度問(wèn)題,在最新的Nvidia GF8 系列顯卡中已經(jīng)開(kāi)始應(yīng)用float point depth buffer. 而在此之間,深度緩存其實(shí)只有位平面的概念. 這隨API的不同,都需要指定后緩存深度緩存精度, Depth ,我一般使用24位,也就是D3D中常見(jiàn)的 D24S8. 但除非你是用浮點(diǎn),否則都會(huì)有精度損失的問(wèn)題,這種情況總是發(fā)生在2個(gè)幾乎共面的片面,他們投影在后裁減平面時(shí)都會(huì)被賦予一個(gè)深度(當(dāng)然,如果深度緩存可寫的話),而上面已經(jīng)說(shuō)過(guò),目前來(lái)說(shuō),深度只是位平面, 你可以把他假設(shè)為這樣的形勢(shì)

            depth              w
            0                  [near_clip,               near_clip + 0.1]
            1                 [near_clip + 0.1,        near_clip +0.2]
            2                 [near_clip + 0.3 ,        near_clip +0.4]
            ........
            max             [far_clip - 0.1,                 far_clip]
            上面假設(shè)硬件的最小深度單元 r = 0.1

            那么將會(huì)出現(xiàn)這樣的問(wèn)題.
            當(dāng)2個(gè)片元距離近裁減平面 w  落在同一個(gè)區(qū)間的時(shí)候,他們的深度是相等的. 最終你所看到的結(jié)果,就是下面的這種樣子:

            注意到藍(lán)色線框里面.


            要解決這個(gè)問(wèn)題, 你只要google 或者去 beyond3d,等論壇,搜索 depth fighting ,得到的答案往往就是設(shè)置深度偏移. OpenGL : Polygon offset. D3D: Depth Bais.
            拿OpenGL 來(lái)說(shuō),就是對(duì)有存在深度沖突的2個(gè) Mesh Object  A,B如下方式渲染.
            A.Render();
            glEnable(GL_POLYGON_OFFSET_FILL);
            glPolygonOffset(
            0.0f,-1.0f);
            B.Render();
            glDisable(GL_POLYGON_OFFSET_FILL);

            這是一個(gè)不錯(cuò)的方法,但是實(shí)際操作起來(lái)很麻煩,而且沒(méi)有效率. 注意到,你必須一先一后的渲染這2個(gè)對(duì)象, 拿上圖來(lái)說(shuō),我需要在MAX 中把手套和手臂脫離,形成一個(gè)獨(dú)立的節(jié)點(diǎn),然后我起碼需要新建立2個(gè)頂點(diǎn)緩存,并在渲染的過(guò)程中設(shè)置2次.這對(duì)于帶寬是個(gè)不小的代價(jià).所以我不是很贊成這樣去處理,當(dāng)然,有的時(shí)候無(wú)法避免了,也會(huì)如此..

                   如果避免發(fā)生Z-Fighting 才是關(guān)鍵. 注意到上面的depth - w 的位平面對(duì)應(yīng)關(guān)系. 由于硬件都只能支持一定的深度格式,也就是說(shuō),Depth bits 是一定的,假為 D.而頂點(diǎn)的投影深度則毫無(wú)限制,他可以是 near_clip ---> far_clip 的任意一個(gè)浮點(diǎn)數(shù).因此
                  dw/D = (far_clip - near_clip)/near_clip;
                從上面可以看出, 要想dw 更精確,那么 near_clip 必然要更大(適用范圍是far_clip >> near_clip).
            上面那張存在depth-fighting 的截圖當(dāng)時(shí)的情況是 near_clip :0.0001 far_clip : 64000.0
            下面的是在near_clip 0.1 far_clip 不變.


            繼續(xù)提高定點(diǎn)投影深度,也不會(huì)出現(xiàn)難看的深度沖突了.
            posted on 2009-03-27 11:31 @王一偉 閱讀(4097) 評(píng)論(7)  編輯 收藏 引用

            Feedback

            # re: 最近做地圖遇到Z-buffer精度問(wèn)題 2009-03-27 11:35 @王一偉
            找到一些英文資料
            Depth Bias收藏

            An application can help ensure that coplanar polygons are rendered properly by adding a bias to the z-values that the system uses when rendering the sets of coplanar polygons. To add a z-bias to a set of polygons, call the SetRenderState method just before rendering them, setting the State parameter to D3DRS_DEPTHBIAS, and the value parameter to a value between 0-16 inclusive. A higher z-bias value increases the likelihood that the polygons you render will be visible when displayed with other coplanar polygons.


            Offset = m * D3DRS_SLOPESCALEDEPTHBIAS + D3DRS_DEPTHBIAS

            where m is the maximum depth slope of the triangle being rendered.

            m = max(abs(delta z / delta x), abs(delta z / delta y))

            The units for the D3DRS_DEPTHBIAS and D3DRS_SLOPESCALEDEPTHBIAS render states depend on whether z-buffering or w-buffering is enabled. The application must provide suitable values.

            The bias is not applied to any line and point primitive. However, this bias needs to be applied to triangles drawn in wireframe mode.

            // RenderStates
            D3DRS_SLOPESCALEDEPTHBIAS, // Defaults to zero
            D3DRS_DEPTHBIAS, // Defaults to zero

            // Caps
            D3DPRASTERCAPS_DEPTHBIAS
            D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS

              回復(fù)  更多評(píng)論
              

            # re: 最近做地圖遇到Z-buffer精度問(wèn)題 2009-03-27 11:37 @王一偉
            另外一篇 英文資料(轉(zhuǎn)自 http://www.intel.com/cd/ids/developer/apac/zho/dc/games/optimization/170939.htm?page=4
            使用Z-Bias解決Z-Fighting問(wèn)題的替代方案
            |
            目錄
            Introduction
            Alternative Method 1: Projection Matrix
            Alternative Method 2: Viewport
            Alternative Method 3: Depth Bias
            Conclusion
            Additional Resources

            Alternative Method 3: Depth Bias

            The last method addressed in this article uses the DirectX 9 Depth Bias method to solve z-fighting. A check to verify that the graphics card is capable of performing depth bias is needed. Intel Integrated Graphics will support depth bias in the next graphics core code named Grantsdale. After checking the cap bits to verify that depth bias is supported, this technique merely requires setting D3DRS_SLOPESCALEDEPTHBIAS and D3DRS_DEPTHBIAS to the proper values to get the desired effect.

            The following code snippet shows the depth-bias alternative to using a DirectX z-bias call:

            BOOL m_bDepthBiasCap; // TRUE, if device has DepthBias Caps

            // Globals used for Depth Bias
            float g_fSlopeScaleDepthBias = 1.0f;
            float g_fDepthBias = -0.0005f;
            float g_fDefaultDepthBias = 0.0f;

            // Check for devices which support the new depth bias caps
            if ((pCaps->RasterCaps & D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS) &&
            (pCaps->RasterCaps & D3DPRASTERCAPS_DEPTHBIAS))
            {
            m_bDepthBiasCap = true; // TRUE, if DepthBias Caps
            }

            // Billboards are rendered...

            // DepthBias work around
            if ( m_bDepthBiasCap ) // TRUE, if DepthBias supported
            {
            // Used to determine how much bias can be applied
            // to co-planar primitives to reduce z fighting
            // bias = (max * D3DRS_SLOPESCALEDEPTHBIAS) + D3DRS_DEPTHBIAS,
            // where max is the maximum depth slope of the triangle being rendered.
            m_pd3dDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, F2DW(g_fSlopeScaleDepthBias));
            m_pd3dDevice->SetRenderState(D3DRS_DEPTHBIAS, F2DW(g_fDepthBias));
            }

            // Posters are rendered...

            if ( m_bDepthBiasCap ) // TRUE, if DepthBias supported
            {
            // DepthBias work around
            // set it back to zero (default)
            m_pd3dDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, F2DW(g_fDefaultDepthBias));
            m_pd3dDevice->SetRenderState(D3DRS_DEPTHBIAS, F2DW(g_fDefaultDepthBias));
            }

            . . .

            Like the other methods (and like the original z-bias), some tweaking may be necessary, but using D3DRS_SLOPESCALEDEPTHBIAS and D3DRS_DEPTHBIAS is a relatively consistent technique for resolving z-fighting issues across a wide selection of graphics devices. The figure below shows the result of this alternate solution:


            Figure 4. Z-fighting solved with depth bias solution.
            As Figure 4 shows, care should be taken for adjusting the D3DRS_SLOPESCALEDEPTHBIAS and D3DRS_DEPTHBIAS. They can be very sensitive and lead to other issues like the problem below for distant objects:


            Figure 5. Depth-bias solution possible issue: unwanted overlapping polygons.  回復(fù)  更多評(píng)論
              

            # re: 最近做地圖遇到Z-buffer精度問(wèn)題[未登錄](méi) 2009-06-16 11:32 dd
            dw/D = (far_clip - near_clip)/near_clip;
            這個(gè)公式怎么得出來(lái)的?  回復(fù)  更多評(píng)論
              

            # re: 最近做地圖遇到Z-buffer精度問(wèn)題[未登錄](méi) 2009-06-16 11:34 dd
            (x,y,z,1) *
            xScale 0 0 0
            0 yScale 0 0
            0 0 zf/(zf-zn) 1
            0 0 -zn*zf/(zf-zn) 0
            之后,z變?yōu)榱藌'
            z' = zf*(z - zn)/(zf-zn)
            怎么會(huì)是dw/D = (far_clip - near_clip)/near_clip?  回復(fù)  更多評(píng)論
              

            # re: 最近做地圖遇到Z-buffer精度問(wèn)題 2009-09-05 21:44 hi
            good  回復(fù)  更多評(píng)論
              

            # re: 最近做地圖遇到Z-buffer精度問(wèn)題 2010-04-02 16:47 tsyat
            這個(gè)東西好像沒(méi)法用哦  回復(fù)  更多評(píng)論
              

            # re: 最近做地圖遇到Z-buffer精度問(wèn)題 2011-03-28 20:35 David Lee
            懶東西,最近怎么不跟新博客了?  回復(fù)  更多評(píng)論
              


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            亚洲国产精品无码久久久久久曰| 久久国产欧美日韩精品| 国产欧美一区二区久久| 久久成人精品视频| 欧美精品福利视频一区二区三区久久久精品 | 久久久久国产精品| 久久久受www免费人成| 99精品久久久久久久婷婷| 久久精品国产亚洲av高清漫画| 久久本道伊人久久| 久久久久久久久久久| 99re这里只有精品热久久| 天堂无码久久综合东京热| 人妻精品久久久久中文字幕69| 色综合久久精品中文字幕首页| 伊人伊成久久人综合网777| 国产精品美女久久久久网| 欧美久久一级内射wwwwww.| 亚洲AV无一区二区三区久久| 久久久精品人妻无码专区不卡| 亚洲AV无一区二区三区久久| 欧美色综合久久久久久| 品成人欧美大片久久国产欧美...| 国产色综合久久无码有码| 精品久久久久久久久久中文字幕| 粉嫩小泬无遮挡久久久久久| 99久久香蕉国产线看观香| 久久国产热这里只有精品| 99久久国产综合精品五月天喷水| 久久亚洲精品成人AV| 亚洲中文字幕无码久久2017| 国产女人aaa级久久久级| 久久精品国产亚洲一区二区| 久久人人爽人人爽人人AV东京热 | 国产精品久久久福利| 亚洲AV日韩AV天堂久久| 久久SE精品一区二区| 一级做a爰片久久毛片免费陪| 人人狠狠综合久久亚洲| 久久久久亚洲精品中文字幕| 久久亚洲天堂|