OpenglES alpha纹理深度

时间:2017-03-09 09:20:57

标签: opengl-es

enter image description here enter image description here

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];
}

Bug图像更改depth-z, 和皇冠的透明度区域现在正常运作。

如何才能正确看到错误?

1 个答案:

答案 0 :(得分:0)

您需要:

  1. 对精灵进行排序,使它们在没有深度测试的情况下从前到后渲染,只需依靠混合来提供透明度。
  2. 向片段着色器添加Alpha测试,以删除透明的片段(例如if (alpha < 0.05) discard;,并根据需要调整透明度阈值)