以上是Ogre帮助文档所写的,理论上默认是开启透明物体排序的,但是渲染出来的结果却不是预想的那样,而设置 transparent_sorting force才能达到效果。这跟Ogre对透明物体的判断有关
Ogre中对透明物体的判断并不是只对AlphaBlend参数的判断,还依赖与Depth Check 、Depth Write 、Color Write,具体见以下代码:
void RenderPriorityGroup::addRenderable(Renderable* rend, Technique* pTech)
{
// Transparent and depth/colour settings mean depth sorting is required?
// Note: colour write disabled with depth check/write enabled means
// setup depth buffer for other passes use.
if (pTech->isTransparentSortingForced() ||
(pTech->isTransparent() &&
(!pTech->isDepthWriteEnabled() ||
!pTech->isDepthCheckEnabled() ||
pTech->hasColourWriteDisabled())))
{
if (pTech->isTransparentSortingEnabled())
addTransparentRenderable(pTech, rend);
else
addUnsortedTransparentRenderable(pTech, rend);
}
else
{
//....不透明物体的流程
}
}
所以在默认情况下(transparent_sorting 为on),在Alpha判断成功后,还要进行Depth、Color的判断,当深度检测、深度写入、颜色写入的其中一个操作为false时,才认为是透明物体,从而走透明物体的流程。而transparent_sorting为force时,直接跳过了这一系列的判断,肯定走透明物体的流程。
关于Alpha判断的代码如下:
pTech->isTransparent();
//-----------------------------------------------------------------------------
bool Technique::isTransparent(void) const
{
if (mPasses.empty())
{
return false;
}
else
{
// Base decision on the transparency of the first pass
return mPasses[0]->isTransparent();
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------
bool Pass::isTransparent(void) const
{
// Transparent if any of the destination colour is taken into account
if (mDestBlendFactor == SBF_ZERO &&
mSourceBlendFactor != SBF_DEST_COLOUR &&
mSourceBlendFactor != SBF_ONE_MINUS_DEST_COLOUR &&
mSourceBlendFactor != SBF_DEST_ALPHA &&
mSourceBlendFactor != SBF_ONE_MINUS_DEST_ALPHA)
{
return false;
}
else
{
return true;
}
}
//-----------------------------------------------------------------------