2017-03-09 134 views
0

enter image description here enter image description hereOpenglES阿爾法紋理深度

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, 和冠的透明度區域現在正常工作。

如何正確地看到後面的錯誤?

回答

0

您需要:

  1. 排序你的精靈,使他們渲染後端到前端沒有深度測試,僅僅依靠混合提供透明。
  2. 添加阿爾法測試到您的片段着色器丟棄哪些是透明的片段(例如if (alpha < 0.05) discard;,調整透明度閾值適當時)
+0

謝謝你的第二應答運作良好。首先是我想避免它 – nosweet