简体   繁体   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];
}

Bug image changes depth-z, and crown's transparency region is now working correctly. 错误图像会更改深度z,并且表冠的透明区域现在可以正常工作。

How can I see behind bug correctly? 我如何才能正确看到错误的背后?

You need to either: 您需要:

  1. Sort your sprites so they render back-to-front without depth testing, and just rely on blending to provide transparencies. 对您的Sprite进行排序,使它们无需深度测试即可直接渲染,而仅依靠混合来提供透明胶片。
  2. Add an alpha test to your fragment shader to drop fragments which are transparent (eg if (alpha < 0.05) discard; , adjust transparency threshold as appropriate) 将alpha测试添加到片段着色器中以删除透明片段(例如, if (alpha < 0.05) discard;适当调整透明度阈值)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM