簡體   English   中英

OpenGL透視投影剪切多邊形與頂點外部的Frustum =錯誤的紋理映射?

[英]OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?

我看到一個問題,如果所有頂點都保留在透視投影中的屏幕上,我可以正確地繪制紋理多邊形,但是如果我將四邊形縮放到足夠大以使得一個或多個頂點落在“觀察體積太遠”之后,那么生成的OpenGL繪圖不正確(見截圖)。 紋理映射變得歪斜,看起來好像屏幕外頂點“移動”並變得扭曲。 我在GLES 3.0兼容驅動程序上使用GLES 2.0代碼(詳情見底部)。 我現在將更詳細地解釋我的測試 -

我正在繪制一個由兩個簡單多邊形組成的GL_TRIANGLE_STRIP'正方形',並在四邊形上應用簡單的紋理貼圖(紋理完美地映射到四邊形上一次,沒有重復.UV坐標0-> 1映射為您所期望的。

另外,我正在使用GLM函數為矩陣變換提供幫助,然后使用glm :: PerspectiveFov()來設置查看量(視錐體)。 結果是相機略微向下看到四邊形,形成一個“地面”狀表面,上面有一個格子圖案紋理。

正確繪制四邊形截圖的視圖

從這里,如果我進一步增加四邊形上的比例變換因子,或者旋轉相機使得屏幕外的頂點頂點“遠離觀察區域”,我突然看到極端奇怪的行為,就像紋理映射發生變化一樣,或者如果多邊形的一個頂點移動不正確。 看這里:

多邊形紋理映射變得錯誤

對於相機旋轉我使用glm :: lookAt() - 有效地移動'眼睛'位置,同時將目標保持在場景中的0,0(多邊形的中心)。

還要注意,當我越過這個閾值時,我看到我繪制的紅色調試線連接所有頂點突然將其方向從它應該的位置移開。

有誰知道這個問題是如何產生的? 有沒有辦法解決它所以我可以繪制一個巨大的四邊形,並在屏幕上有頂點沒有這些問題/工件? 謝謝!!!

GPU信息:

GL供應商:Vivante Corporation

GL渲染器:Vivante GC2000

GL版本:OpenGL ES 3.0 V5.0.11.p8.41671

GLSL版本:OpenGL ES GLSL ES 3.00

對我原始問題的一些研究和評論使我相信觀察到的效果是Vivante GPU GC2000上OpenGL驅動程序實現中的錯誤的結果。 顯然這種錯誤在嵌入式GPU硬件驅動程序中很常見 - 這種ES實現的源代碼永遠不可用的事實加劇了這個問題。

為了通過解決方法解決這個問題,我能夠獲取原始正方形的尺寸,而是創建紋理正方形的網格陣列,以便所有多邊形最終足夠小以“適合”足夠接近觀察區域(或者可選地)完全修剪,避免bug行為)。 C ++中的代碼:

// measurements we will add as we move along the grid
float tile_size = 1.0 / num_grid_subdivisions; // square width 1
float tile_uv_dist = 1.0 / num_grid_subdivisions; // assume 0->1 texture mapping
XY curr_bl = XY(-0.5, -0.5); // quad from -0.5 to 0.5 in x and y (1x1)
float cu = 0; //current texture coordinates in x dimension
float cv = 0; //current texture coordinates in y dimension
for (int row = 0; row < num_grid_subdivisions; ++row)
{
        for (int row_item = 0; row_item < num_grid_subdivisions; ++row_item)
        {
            // GL_TRIANGLES to keep simple, but could use STRIP later
            VertXYUV bl(curr_bl, cu, cv); // bottomleft
            // if we know bottomleft, we know the rest of the points of the square
            VertXYUV tl(XY(curr_bl.x, curr_bl.y + tile_size), cu, cv + tile_uv_dist);
            VertXYUV br(XY(curr_bl.x + tile_size, curr_bl.y), cu+ tile_uv_dist, cv );
            VertXYUV tr(XY(curr_bl.x + tile_size, curr_bl.y + tile_size),
            cu + tile_uv_dist, cv + tile_uv_dist);
            // our square tile is two triangle polygons
            AddVert(bl); AddVert(tl); AddVert(br); // triangle 1
            AddVert(br); AddVert(tl); AddVert(tr); // triangle 2

            // current info should always be tracking 'bl' of current tile
            // increment row item, moving across to the right (+x)
            cu += tile_uv_dist;
            curr_bl.x += tile_size;
        }

        // current info should always be tracking 'bl' of current tile
        // incrementing row, moving up (+y)
        cv += tile_uv_dist;
        cu = 0; // reset x space texture coordinate back to left side (0)
        curr_bl.y += tile_size;
        curr_bl.x = grid_bl.x;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM