Added an experimental new alphamask detection method(set SHUseRMSEAutoMask to TRUE to use. Adjust SHAlphaMaskMaxRMSE to tweak cutoff). Fixed per-frame sky updates hammering analyzeAlpha.

This commit is contained in:
Shyotl
2013-04-06 02:04:46 -05:00
parent e2255f419d
commit b16bb264cc
17 changed files with 170 additions and 28 deletions

View File

@@ -482,7 +482,11 @@ void LLImageGL::init(BOOL usemipmaps)
mHasExplicitFormat = FALSE;
mAutoGenMips = FALSE;
mCanMask = TRUE;
mIsMask = FALSE;
mMaskRMSE = 1.f ;
mNeedsAlphaAndPickMask = TRUE ;
mAlphaStride = 0 ;
mAlphaOffset = 0 ;
@@ -1749,7 +1753,7 @@ void LLImageGL::setNeedsAlphaAndPickMask(BOOL need_mask)
else //do not need alpha mask
{
mAlphaOffset = INVALID_OFFSET ;
mIsMask = FALSE;
mCanMask = FALSE;
}
}
}
@@ -1773,7 +1777,7 @@ void LLImageGL::calcAlphaChannelOffsetAndStride()
break;
case GL_RGB:
mNeedsAlphaAndPickMask = FALSE ;
mIsMask = FALSE;
mCanMask = FALSE;
return ; //no alpha channel.
case GL_RGBA:
mAlphaStride = 4;
@@ -1820,17 +1824,20 @@ void LLImageGL::calcAlphaChannelOffsetAndStride()
llwarns << "Cannot analyze alpha for image with format type " << std::hex << mFormatType << std::dec << llendl;
mNeedsAlphaAndPickMask = FALSE ;
mIsMask = FALSE;
mCanMask = FALSE;
}
}
std::map<LLGLuint, std::list<std::pair<std::string,std::string> > > sTextureMaskMap;
void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
{
if(!mNeedsAlphaAndPickMask)
if(!mNeedsAlphaAndPickMask || !mCanMask)
{
return ;
}
F64 sum = 0;
U32 length = w * h;
U32 alphatotal = 0;
@@ -1871,11 +1878,19 @@ void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
const U32 asum = (s1+s2+s3+s4);
alphatotal += asum;
sample[asum/(16*4)] += 4;
S32 avg = (s1+s2+s3+s4)/4;
if(avg >=128)
{
avg-=255;
}
sum+=F64(avg*avg*4)/F64(length);
}
rowstart += 2 * w * mAlphaStride;
}
length *= 2; // we sampled everything twice, essentially
}
else
@@ -1887,9 +1902,17 @@ void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
alphatotal += s1;
++sample[s1/16];
current += mAlphaStride;
if(i%2==0)
{
S32 avg = (s1+current[mAlphaStride])/2;
if(avg >=128)
avg-=255;
sum+=F64(avg*avg*2)/F64(length);
}
}
}
// if more than 1/16th of alpha samples are mid-range, this
// shouldn't be treated as a 1-bit mask
@@ -1898,7 +1921,7 @@ void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
// this to be an intentional effect and don't treat as a mask.
U32 midrangetotal = 0;
for (U32 i = 2; i < 13; i++)
for (U32 i = 3; i < 13; i++)
{
midrangetotal += sample[i];
}
@@ -1923,6 +1946,22 @@ void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
{
mIsMask = TRUE;
}
mMaskRMSE = sqrt(sum)/255.0;
std::list<std::pair<std::string,std::string> > &data = sTextureMaskMap[getTexName()];
data.clear();
data.push_back(std::make_pair("RMSE", llformat("%f",mMaskRMSE)));
data.push_back(std::make_pair(" sum", llformat("%lf",sum)));
data.push_back(std::make_pair(" n", llformat("%u",h*w)));
data.push_back(std::make_pair("legacymask", mIsMask ? "TRUE" : "FALSE"));
data.push_back(std::make_pair(" index", llformat("%u",getTexName())));
data.push_back(std::make_pair(" length", llformat("%u",length)));
data.push_back(std::make_pair(" stride", llformat("%i",S32(mAlphaOffset))));
data.push_back(std::make_pair(" split", llformat("%u|%u|%u",lowerhalftotal,midrangetotal,upperhalftotal)));
data.push_back(std::make_pair(" alphatotal", llformat("%u",alphatotal)));
data.push_back(std::make_pair(" alphatotal/48", llformat("%u",length/48)));
}
//----------------------------------------------------------------------------