BlendFunc——图形学混合方式

 

1、根据 纹理 是否alpha预乘,决定混合方式

void Sprite::updateBlendFunc(void)
{
    CCASSERT(! _batchNode, "CCSprite: updateBlendFunc doesn't
         work when the sprite is rendered using a SpriteBatchNode
"); // it is possible to have an untextured sprite if (! _texture || ! _texture->hasPremultipliedAlpha()) { _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; setOpacityModifyRGB(false); } else { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); } }

 

2、混合方式示例:

const BlendFunc BlendFunc::DISABLE = {GL_ONE, GL_ZERO};
const BlendFunc BlendFunc::ALPHA_PREMULTIPLIED = {GL_ONE, GL_ONE_MINUS_SRC_ALPHA};
const BlendFunc BlendFunc::ALPHA_NON_PREMULTIPLIED = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA};
const BlendFunc BlendFunc::ADDITIVE = {GL_SRC_ALPHA, GL_ONE};

 

对于 alpha 预乘的纹理,默认选择  {GL_ONE, GL_ONE_MINUS_SRC_ALPHA} 

即src以100%混合,dst以(1-src_alpha)混合;

 

对于未作alpha预乘的纹理,选择  {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}

即src需要乘以src_alpha混合,dst以(1-src_alpha)混合;

 

3、在使用 ASTC 压缩纹理时,默认未作alpha预乘;

4、png、jpg默认作 alpha预乘;

posted @ 2023-02-28 15:40  会飞的斧头  阅读(81)  评论(0编辑  收藏  举报