Merge branch 'V2MultiWear' of git://github.com/Shyotl/SingularityViewer into V2MultiWear

This commit is contained in:
Lirusaito
2012-05-23 03:46:48 -04:00
31 changed files with 313 additions and 215 deletions

View File

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

View File

@@ -128,7 +128,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

@@ -109,7 +109,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

@@ -29,11 +29,11 @@ out vec4 frag_color;
#define frag_color gl_FragColor
#endif
uniform float minimum_alpha;
uniform sampler2D diffuseMap;
VARYING vec4 post_pos;
VARYING float pos_zd2;
VARYING float pos_w;
VARYING float target_pos_x;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
@@ -41,12 +41,20 @@ void main()
{
float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a;
if (alpha < minimum_alpha)
if (alpha < 0.05) // treat as totally transparent
{
discard;
}
if (alpha < 0.88) // treat as semi-transparent
{
if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25)
{
discard;
}
}
frag_color = vec4(1,1,1,1);
gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);
gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0);
}

View File

@@ -25,12 +25,15 @@
uniform mat4 texture_matrix0;
uniform mat4 modelview_projection_matrix;
uniform float shadow_target_width;
ATTRIBUTE vec3 position;
ATTRIBUTE vec4 diffuse_color;
ATTRIBUTE vec2 texcoord0;
VARYING vec4 post_pos;
VARYING float pos_zd2;
VARYING float pos_w;
VARYING float target_pos_x;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
@@ -39,8 +42,11 @@ void passTextureIndex();
void main()
{
//transform vertex
vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0);
post_pos = pos;
vec4 pre_pos = vec4(position.xyz, 1.0);
vec4 pos = modelview_projection_matrix * pre_pos;
target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x;
pos_w = pos.w;
pos_zd2 = pos.z * 0.5;
gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w);

View File

@@ -301,11 +301,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

@@ -857,7 +857,10 @@ void LLAgentWearables::popWearable(const LLWearableType::EType type, U32 index)
if (wearable)
{
mWearableDatas[type].erase(mWearableDatas[type].begin() + index);
if (isAgentAvatarValid())
{
gAgentAvatarp->wearableUpdated(wearable->getType(), TRUE);
}
wearable->setLabelUpdated();
}
}

View File

@@ -722,7 +722,7 @@ void LLMediaCtrl::draw()
// to get render origin for this view (with unit scale)
gGL.translatef(floorf(LLFontGL::sCurOrigin.mX * LLUI::sGLScaleFactor.mV[VX]),
floorf(LLFontGL::sCurOrigin.mY * LLUI::sGLScaleFactor.mV[VY]),
LLFontGL::sCurOrigin.mZ);
LLFontGL::sCurDepth);
}
// scale texture to fit the space using texture coords

View File

@@ -36,7 +36,8 @@
#include "llpanel.h"
#include "llviewermedia.h"
class LLCoordWindow;
#include "llcoord.h"
class LLViewerMediaImpl;
class LLPanelMediaHUD : public LLPanel

View File

@@ -38,8 +38,8 @@
#include "llstat.h"
#include "lltimer.h"
#include "m4math.h"
#include "llcoord.h"
class LLCoordGL;
class LLViewerObject;
// This rotation matrix moves the default OpenGL reference frame

View File

@@ -210,6 +210,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();
@@ -636,9 +646,9 @@ void settings_setup_listeners()
gSavedSettings.getControl("VertexShaderEnable")->getSignal()->connect(boost::bind(&handleSetShaderChanged, _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

@@ -769,7 +769,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo
LLGLState::checkStates();
LLGLState::checkClientArrays();
if (!for_snapshot || tiling)
//if (!for_snapshot)
{
LLAppViewer::instance()->pingMainloopTimeout("Display:Imagery");
gPipeline.generateWaterReflection(*LLViewerCamera::getInstance());
@@ -921,13 +921,14 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo
if (to_texture)
{
gGL.setColorMask(true, true);
if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender)
{
gPipeline.mDeferredScreen.bindTarget();
glClearColor(1,0,1,1);
gPipeline.mDeferredScreen.clear();
}
else if(!tiling)
else
{
gPipeline.mScreen.bindTarget();
if (LLPipeline::sUnderWaterRender && !gPipeline.canUseWindLightShaders())
@@ -994,7 +995,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo
GL_DEPTH_BUFFER_BIT, GL_NEAREST);
}
}
else if(!tiling)
else
{
gPipeline.mScreen.flush();
if(LLRenderTarget::sUseFBO)
@@ -1017,7 +1018,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo
LLPipeline::sUnderWaterRender = FALSE;
LLAppViewer::instance()->pingMainloopTimeout("Display:RenderUI");
if (!for_snapshot)
if (!for_snapshot || LLPipeline::sRenderDeferred)
{
LLFastTimer t(FTM_RENDER_UI);
gFrameStats.start(LLFrameStats::RENDER_UI);

View File

@@ -904,6 +904,13 @@ U32 LLViewerObject::processUpdateMessage(LLMessageSystem *mesgsys,
LLMemType mt(LLMemType::MTYPE_OBJECT);
U32 retval = 0x0;
// If region is removed from the list it is also deleted.
if (!LLWorld::instance().isRegionListed(mRegionp))
{
llwarns << "Updating object in an invalid region" << llendl;
return retval;
}
// Coordinates of objects on simulators are region-local.
U64 region_handle;
mesgsys->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
@@ -3556,7 +3563,8 @@ LLNameValue *LLViewerObject::getNVPair(const std::string& name) const
void LLViewerObject::updatePositionCaches() const
{
if(mRegionp)
// If region is removed from the list it is also deleted.
if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
{
if (!isRoot())
{
@@ -3573,7 +3581,8 @@ void LLViewerObject::updatePositionCaches() const
const LLVector3d LLViewerObject::getPositionGlobal() const
{
if(mRegionp)
// If region is removed from the list it is also deleted.
if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
{
LLVector3d position_global = mRegionp->getPosGlobalFromRegion(getPositionRegion());
@@ -3592,7 +3601,8 @@ const LLVector3d LLViewerObject::getPositionGlobal() const
const LLVector3 &LLViewerObject::getPositionAgent() const
{
if (mRegionp)
// If region is removed from the list it is also deleted.
if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
{
if (mDrawable.notNull() && (!mDrawable->isRoot() && getParent()))
{

View File

@@ -1486,6 +1486,11 @@ void LLWorld::getAvatars(std::vector<LLUUID>* avatar_ids, std::vector<LLVector3d
}
}
bool LLWorld::isRegionListed(const LLViewerRegion* region) const
{
region_list_t::const_iterator it = find(mRegionList.begin(), mRegionList.end(), region);
return it != mRegionList.end();
}
LLHTTPRegistration<LLEstablishAgentCommunication>
gHTTPRegistrationEstablishAgentCommunication(

View File

@@ -163,6 +163,11 @@ public:
std::vector<LLVector3d>* positions = NULL,
const LLVector3d& relative_to = LLVector3d(), F32 radius = FLT_MAX) const;
// Returns 'true' if the region is in mRegionList,
// 'false' if the region has been removed due to region change
// or if the circuit to this simulator had been lost.
bool isRegionListed(const LLViewerRegion* region) const;
private:
region_list_t mActiveRegionList;
region_list_t mRegionList;

View File

@@ -52,7 +52,6 @@ const S32 DEFAULT_TRACKING_ARROW_SIZE = 16;
class LLColor4;
class LLColor4U;
class LLCoordGL;
class LLViewerTexture;
class LLTextBox;

View File

@@ -718,9 +718,10 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
if (shadow_detail > 0)
{ //allocate 4 sun shadow maps
U32 sun_shadow_map_width = ((U32(resX*scale)+1)&~1); // must be even to avoid a stripe in the horizontal shadow blur
for (U32 i = 0; i < 4; i++)
{
if (!mShadow[i].allocate(U32(resX*scale),U32(resY*scale), 0, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE)) return false;
if (!mShadow[i].allocate(sun_shadow_map_width,U32(resY*scale), 0, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE)) return false;
}
}
else
@@ -736,9 +737,10 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
if (shadow_detail > 1)
{ //allocate two spot shadow maps
U32 spot_shadow_map_width = width;
for (U32 i = 4; i < 6; i++)
{
if (!mShadow[i].allocate(width, height, 0, TRUE, FALSE)) return false;
if (!mShadow[i].allocate(spot_shadow_map_width, height, 0, TRUE, FALSE)) return false;
}
}
else
@@ -845,15 +847,11 @@ void LLPipeline::releaseGLBuffers()
mTrueNoiseMap = 0;
}
if (mLightFunc)
{
LLImageGL::deleteTextures(1, &mLightFunc);
mLightFunc = 0;
}
releaseLUTBuffers();
mWaterRef.release();
mWaterDis.release();
for (U32 i = 0; i < 3; i++)
{
mGlow[i].release();
@@ -865,6 +863,15 @@ void LLPipeline::releaseGLBuffers()
LLVOAvatar::resetImpostors();
}
void LLPipeline::releaseLUTBuffers()
{
if (mLightFunc)
{
LLImageGL::deleteTextures(1, &mLightFunc);
mLightFunc = 0;
}
}
void LLPipeline::releaseScreenBuffers()
{
mScreen.release();
@@ -957,50 +964,68 @@ 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);
static const LLCachedControl<F32> render_specular_exponent("RenderSpecularExponent");
sa = powf(sa, render_specular_exponent);
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, false);
gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
delete [] lg;
}
createLUTBuffers();
}
gBumpImageList.restoreGL();
}
void LLPipeline::createLUTBuffers()
{
if (sRenderDeferred)
{
if (!mLightFunc)
{
U32 lightResX = gSavedSettings.getU32("RenderSpecularResX");
U32 lightResY = gSavedSettings.getU32("RenderSpecularResY");
U8* ls = new U8[lightResX*lightResY];
static const LLCachedControl<F32> specExp("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, false);
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);
@@ -8173,7 +8198,7 @@ static LLFastTimer::DeclareTimer FTM_SHADOW_RENDER("Render Shadows");
static LLFastTimer::DeclareTimer FTM_SHADOW_ALPHA("Alpha Shadow");
static LLFastTimer::DeclareTimer FTM_SHADOW_SIMPLE("Simple Shadow");
void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& shadow_cam, LLCullResult &result, BOOL use_shader, BOOL use_occlusion)
void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& shadow_cam, LLCullResult &result, BOOL use_shader, BOOL use_occlusion, U32 target_width)
{
LLFastTimer t(FTM_SHADOW_RENDER);
@@ -8264,6 +8289,7 @@ void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera
LLFastTimer ftm(FTM_SHADOW_ALPHA);
gDeferredShadowAlphaMaskProgram.bind();
gDeferredShadowAlphaMaskProgram.setMinimumAlpha(0.598f);
gDeferredShadowAlphaMaskProgram.uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
U32 mask = LLVertexBuffer::MAP_VERTEX |
LLVertexBuffer::MAP_TEXCOORD0 |
@@ -9050,11 +9076,13 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
mShadow[j].getViewport(gGLViewport);
mShadow[j].clear();
U32 target_width = mShadow[j].getWidth();
{
static LLCullResult result[4];
//LLGLEnable enable(GL_DEPTH_CLAMP_NV);
renderShadow(view[j], proj[j], shadow_cam, result[j], TRUE);
renderShadow(view[j], proj[j], shadow_cam, result[j], TRUE, TRUE, target_width);
}
mShadow[j].flush();
@@ -9193,11 +9221,13 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
mShadow[i+4].getViewport(gGLViewport);
mShadow[i+4].clear();
U32 target_width = mShadow[i+4].getWidth();
static LLCullResult result[2];
LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_SHADOW0+i+4;
renderShadow(view[i+4], proj[i+4], shadow_cam, result[i], FALSE, FALSE);
renderShadow(view[i+4], proj[i+4], shadow_cam, result[i], FALSE, FALSE, target_width);
mShadow[i+4].flush();
}

View File

@@ -118,8 +118,10 @@ public:
void doResetVertexBuffers();
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);
@@ -263,7 +265,7 @@ public:
void generateSunShadow(LLCamera& camera);
void renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& camera, LLCullResult& result, BOOL use_shader = TRUE, BOOL use_occlusion = TRUE);
void renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& camera, LLCullResult& result, BOOL use_shader, BOOL use_occlusion, U32 target_width);
void renderHighlights();
void renderDebug();
void renderPhysicsDisplay();