merge changes for storm-1823

meow-7.2.2
Oz Linden 2012-04-02 09:56:40 -04:00
commit 564121fca4
9 changed files with 93 additions and 55 deletions

View File

@ -395,6 +395,8 @@ Frontera Thor
Fury Rosewood
Gaberoonie Zanzibar
Ganymedes Costagravas
Geenz Spad
STORM-1823
Gene Frostbite
GeneJ Composer
Geneko Nemeth

View File

@ -8217,7 +8217,7 @@
<key>Type</key>
<string>U32</string>
<key>Value</key>
<real>128</real>
<real>512</real>
</map>
<key>RenderSpecularResY</key>
@ -8241,7 +8241,7 @@
<key>Type</key>
<string>F32</string>
<key>Value</key>
<real>8</real>
<real>384</real>
</map>
<key>RenderDeferred</key>

View File

@ -126,7 +126,7 @@ void main()
if (sa > 0.0)
{
sa = texture2D(lightFunc,vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0);
sa = 6 * texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0);
sa *= noise;
col += da*sa*light_col[i].rgb*spec.rgb;
}

View File

@ -107,7 +107,7 @@ void main()
float sa = dot(normalize(lv-normalize(pos)),norm);
if (sa > 0.0)
{
sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0);
sa = 6 * texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0);
sa *= noise;
col += da*sa*color.rgb*spec.rgb;
}

View File

@ -299,11 +299,11 @@ void main()
//
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
float sa = dot(refnormpersp, sun_dir.xyz);
vec3 dumbshiny = vary_SunlitColor*texture2D(lightFunc, vec2(sa, spec.a)).r;
vec3 dumbshiny = vary_SunlitColor*(6 * texture2D(lightFunc, vec2(sa, spec.a)).r);
// add the two types of shiny together
vec3 spec_contrib = dumbshiny * spec.rgb;
bloom = dot(spec_contrib, spec_contrib);
bloom = dot(spec_contrib, spec_contrib) / 4;
col += spec_contrib;
//add environmentmap

View File

@ -307,11 +307,11 @@ void main()
//
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
float sa = dot(refnormpersp, sun_dir.xyz);
vec3 dumbshiny = vary_SunlitColor*scol_ambocc.r*texture2D(lightFunc, vec2(sa, spec.a)).r;
vec3 dumbshiny = vary_SunlitColor*scol_ambocc.r*(6 * texture2D(lightFunc, vec2(sa, spec.a)).r);
// add the two types of shiny together
vec3 spec_contrib = dumbshiny * spec.rgb;
bloom = dot(spec_contrib, spec_contrib);
bloom = dot(spec_contrib, spec_contrib) / 4;
col += spec_contrib;
//add environmentmap

View File

@ -181,6 +181,16 @@ static bool handleReleaseGLBufferChanged(const LLSD& newvalue)
return true;
}
static bool handleLUTBufferChanged(const LLSD& newvalue)
{
if (gPipeline.isInit())
{
gPipeline.releaseLUTBuffers();
gPipeline.createLUTBuffers();
}
return true;
}
static bool handleAnisotropicChanged(const LLSD& newvalue)
{
LLImageGL::sGlobalUseAnisotropic = newvalue.asBoolean();
@ -569,9 +579,9 @@ void settings_setup_listeners()
gSavedSettings.getControl("RenderUIBuffer")->getSignal()->connect(boost::bind(&handleReleaseGLBufferChanged, _2));
gSavedSettings.getControl("RenderDepthOfField")->getSignal()->connect(boost::bind(&handleReleaseGLBufferChanged, _2));
gSavedSettings.getControl("RenderFSAASamples")->getSignal()->connect(boost::bind(&handleReleaseGLBufferChanged, _2));
gSavedSettings.getControl("RenderSpecularResX")->getSignal()->connect(boost::bind(&handleReleaseGLBufferChanged, _2));
gSavedSettings.getControl("RenderSpecularResY")->getSignal()->connect(boost::bind(&handleReleaseGLBufferChanged, _2));
gSavedSettings.getControl("RenderSpecularExponent")->getSignal()->connect(boost::bind(&handleReleaseGLBufferChanged, _2));
gSavedSettings.getControl("RenderSpecularResX")->getSignal()->connect(boost::bind(&handleLUTBufferChanged, _2));
gSavedSettings.getControl("RenderSpecularResY")->getSignal()->connect(boost::bind(&handleLUTBufferChanged, _2));
gSavedSettings.getControl("RenderSpecularExponent")->getSignal()->connect(boost::bind(&handleLUTBufferChanged, _2));
gSavedSettings.getControl("RenderAnisotropic")->getSignal()->connect(boost::bind(&handleAnisotropicChanged, _2));
gSavedSettings.getControl("RenderShadowResolutionScale")->getSignal()->connect(boost::bind(&handleReleaseGLBufferChanged, _2));
gSavedSettings.getControl("RenderGlow")->getSignal()->connect(boost::bind(&handleReleaseGLBufferChanged, _2));

View File

@ -1032,11 +1032,7 @@ void LLPipeline::releaseGLBuffers()
mTrueNoiseMap = 0;
}
if (mLightFunc)
{
LLImageGL::deleteTextures(1, &mLightFunc);
mLightFunc = 0;
}
releaseLUTBuffers();
mWaterRef.release();
mWaterDis.release();
@ -1052,6 +1048,15 @@ void LLPipeline::releaseGLBuffers()
LLVOAvatar::resetImpostors();
}
void LLPipeline::releaseLUTBuffers()
{
if (mLightFunc)
{
LLImageGL::deleteTextures(1, &mLightFunc);
mLightFunc = 0;
}
}
void LLPipeline::releaseScreenBuffers()
{
mUIScreen.release();
@ -1146,50 +1151,69 @@ void LLPipeline::createGLBuffers()
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
}
if (!mLightFunc)
{
U32 lightResX = gSavedSettings.getU32("RenderSpecularResX");
U32 lightResY = gSavedSettings.getU32("RenderSpecularResY");
U8* lg = new U8[lightResX*lightResY];
for (U32 y = 0; y < lightResY; ++y)
{
for (U32 x = 0; x < lightResX; ++x)
{
//spec func
F32 sa = (F32) x/(lightResX-1);
F32 spec = (F32) y/(lightResY-1);
//lg[y*lightResX+x] = (U8) (powf(sa, 128.f*spec*spec)*255);
//F32 sp = acosf(sa)/(1.f-spec);
sa = powf(sa, gSavedSettings.getF32("RenderSpecularExponent"));
F32 a = acosf(sa*0.25f+0.75f);
F32 m = llmax(0.5f-spec*0.5f, 0.001f);
F32 t2 = tanf(a)/m;
t2 *= t2;
F32 c4a = (3.f+4.f*cosf(2.f*a)+cosf(4.f*a))/8.f;
F32 bd = 1.f/(4.f*m*m*c4a)*powf(F_E, -t2);
lg[y*lightResX+x] = (U8) (llclamp(bd, 0.f, 1.f)*255);
}
}
LLImageGL::generateTextures(1, &mLightFunc);
gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_R8, lightResX, lightResY, GL_RED, GL_UNSIGNED_BYTE, lg);
gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
delete [] lg;
}
createLUTBuffers();
}
gBumpImageList.restoreGL();
}
void LLPipeline::restoreGL()
void LLPipeline::createLUTBuffers()
{
if (sRenderDeferred)
{
if (!mLightFunc)
{
U32 lightResX = gSavedSettings.getU32("RenderSpecularResX");
U32 lightResY = gSavedSettings.getU32("RenderSpecularResY");
U8* ls = new U8[lightResX*lightResY];
F32 specExp = gSavedSettings.getF32("RenderSpecularExponent");
// Calculate the (normalized) Blinn-Phong specular lookup texture.
for (U32 y = 0; y < lightResY; ++y)
{
for (U32 x = 0; x < lightResX; ++x)
{
ls[y*lightResX+x] = 0;
F32 sa = (F32) x/(lightResX-1);
F32 spec = (F32) y/(lightResY-1);
F32 n = spec * spec * specExp;
// Nothing special here. Just your typical blinn-phong term.
spec = powf(sa, n);
// Apply our normalization function.
// Note: This is the full equation that applies the full normalization curve, not an approximation.
// This is fine, given we only need to create our LUT once per buffer initialization.
// The only trade off is we have a really low dynamic range.
// This means we have to account for things not being able to exceed 0 to 1 in our shaders.
spec *= (((n + 2) * (n + 4)) / (8 * F_PI * (powf(2, -n/2) + n)));
// Always sample at a 1.0/2.2 curve.
// This "Gamma corrects" our specular term, boosting our lower exponent reflections.
spec = powf(spec, 1.f/2.2f);
// Easy fix for our dynamic range problem: divide by 6 here, multiply by 6 in our shaders.
// This allows for our specular term to exceed a value of 1 in our shaders.
// This is something that can be important for energy conserving specular models where higher exponents can result in highlights that exceed a range of 0 to 1.
// Technically, we could just use an R16F texture, but driver support for R16F textures can be somewhat spotty at times.
// This works remarkably well for higher specular exponents, though banding can sometimes be seen on lower exponents.
// Combined with a bit of noise and trilinear filtering, the banding is hardly noticable.
ls[y*lightResX+x] = (U8)(llclamp(spec * (1.f / 6), 0.f, 1.f) * 255);
}
}
LLImageGL::generateTextures(1, &mLightFunc);
gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_R8, lightResX, lightResY, GL_RED, GL_UNSIGNED_BYTE, ls);
gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
delete [] ls;
}
}
}
void LLPipeline::restoreGL()
{
LLMemType mt_cb(LLMemType::MTYPE_PIPELINE_RESTORE_GL);
assertInitialized();

View File

@ -113,8 +113,10 @@ public:
void resetVertexBuffers();
void resizeScreenTexture();
void releaseGLBuffers();
void releaseLUTBuffers();
void releaseScreenBuffers();
void createGLBuffers();
void createLUTBuffers();
void allocateScreenBuffer(U32 resX, U32 resY);
bool allocateScreenBuffer(U32 resX, U32 resY, U32 samples);