簡體   English   中英

OpenglES alpha紋理深度

[英]OpenglES alpha texture depth

在此處輸入圖片說明在此處輸入圖片說明

glClear( GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT );

glUseProgram(_program);
GLKVector2 poz= { 0, 0};
if (_Sprite2)
{
    float aspect = ( GLfloat ) _screenWidth/ ( GLfloat ) _screenHeight;
    [self esMatrixLoadIdentity : &perspective];
    [self esPerspective:&perspective pos_fovy:60.0f pos_aspect:aspect  pos_nearZ:1.0f pos_farZ:30.0f];


    [self esMatrixLoadIdentity : &modelview];
    [self esTranslate : &modelview trans_x:0.0f trans_y:-0.5f trans_z:-5 ];
    [self esRotate : &modelview gl_angle:0.0f _x:1.0 _y:0.0 _z:1.0];
    [self esMatrixMultiply :&mvpMatrix src_A:&modelview src_B:&perspective];

    glUniformMatrix4fv ( mvpLoc, 1, GL_FALSE, (GLfloat*) &mvpMatrix.m[0][0] );

    [_Sprite2 update : poz];
    [_Sprite2 draw];
}/// crown

if(_sprite)//bug
{
    float aspect = ( GLfloat ) _screenWidth/ ( GLfloat ) _screenHeight;
    [self esMatrixLoadIdentity : &perspective];
    [self esPerspective:&perspective pos_fovy:60.0f pos_aspect:aspect  pos_nearZ:1.0f pos_farZ:30.0f];

    [self esMatrixLoadIdentity : &modelview];
    [self esTranslate : &modelview trans_x:0.0f trans_y:0.0f trans_z:_zPoz + _zPoz_2];
    [self esRotate : &modelview gl_angle:0.0f _x:1.0 _y:0.0 _z:1.0];

    [self esMatrixMultiply :&mvpMatrix src_A:&modelview src_B:&perspective];

    glUniformMatrix4fv ( mvpLoc, 1, GL_FALSE, (GLfloat*) &mvpMatrix.m[0][0] );

    [_sprite update : poz];
    [_sprite draw];
}

錯誤圖像會更改深度z,並且表冠的透明區域現在可以正常工作。

我如何才能正確看到錯誤的背后?

您需要:

  1. 對您的Sprite進行排序,使它們無需深度測試即可直接渲染,而僅依靠混合來提供透明膠片。
  2. 將alpha測試添加到片段着色器中以刪除透明片段(例如, if (alpha < 0.05) discard;適當調整透明度閾值)

暫無
暫無

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

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