diff options
Diffstat (limited to 'indra/newview/pipeline.cpp')
-rw-r--r-- | indra/newview/pipeline.cpp | 282 |
1 files changed, 116 insertions, 166 deletions
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index f911aea9cd..deafa6900e 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -335,18 +335,6 @@ static LLCullResult* sCull = NULL; void validate_framebuffer_object(); -// override the projection_matrix uniform on the given shader to that which would be set by the main camera -void set_camera_projection_matrix(LLGLSLShader& shader) -{ - auto camProj = LLViewerCamera::getInstance()->getProjection(); - glh::matrix4f projection = get_current_projection(); - projection.set_row(0, glh::vec4f(camProj.mMatrix[0][0], camProj.mMatrix[0][1], camProj.mMatrix[0][2], camProj.mMatrix[0][3])); - projection.set_row(0, glh::vec4f(camProj.mMatrix[1][0], camProj.mMatrix[1][1], camProj.mMatrix[1][2], camProj.mMatrix[1][3])); - projection.set_row(0, glh::vec4f(camProj.mMatrix[2][0], camProj.mMatrix[2][1], camProj.mMatrix[2][2], camProj.mMatrix[2][3])); - projection.set_row(0, glh::vec4f(camProj.mMatrix[3][0], camProj.mMatrix[3][1], camProj.mMatrix[3][2], camProj.mMatrix[3][3])); - shader.uniformMatrix4fv(LLShaderMgr::PROJECTION_MATRIX, 1, FALSE, projection.m); -} - // Add color attachments for deferred rendering // target -- RenderTarget to add attachments to bool addDeferredAttachments(LLRenderTarget& target, bool for_impostor = false) @@ -354,7 +342,7 @@ bool addDeferredAttachments(LLRenderTarget& target, bool for_impostor = false) bool valid = true && target.addColorAttachment(GL_RGBA) // frag-data[1] specular OR PBR ORM && target.addColorAttachment(GL_RGBA16F) // frag_data[2] normal+z+fogmask, See: class1\deferred\materialF.glsl & softenlight - && target.addColorAttachment(GL_RGBA); // frag_data[3] PBR emissive + && target.addColorAttachment(GL_RGB16); // frag_data[3] PBR emissive return valid; } @@ -432,6 +420,7 @@ void LLPipeline::init() getPool(LLDrawPool::POOL_MATERIALS); getPool(LLDrawPool::POOL_GLOW); getPool(LLDrawPool::POOL_GLTF_PBR); + getPool(LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK); resetFrameStats(); @@ -680,8 +669,6 @@ void LLPipeline::destroyGL() resetDrawOrders(); - resetVertexBuffers(); - releaseGLBuffers(); if (mMeshDirtyQueryObject) @@ -801,7 +788,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) gCubeSnapshot = TRUE; mReflectionMapManager.initReflectionMaps(); mRT = &mAuxillaryRT; - U32 res = mReflectionMapManager.mProbeResolution * 2; //multiply by 2 because probes will be super sampled + U32 res = mReflectionMapManager.mProbeResolution * 4; //multiply by 4 because probes will be 16x super sampled allocateScreenBuffer(res, res, samples); mRT = &mMainRT; gCubeSnapshot = FALSE; @@ -1545,6 +1532,9 @@ LLDrawPool *LLPipeline::findPool(const U32 type, LLViewerTexture *tex0) case LLDrawPool::POOL_GLTF_PBR: poolp = mPBROpaquePool; break; + case LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK: + poolp = mPBRAlphaMaskPool; + break; default: llassert(0); @@ -2272,7 +2262,6 @@ bool LLPipeline::getVisibleExtents(LLCamera& camera, LLVector3& min, LLVector3& } LLViewerCamera::sCurCameraID = saved_camera_id; - return res; } @@ -2283,7 +2272,7 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result) LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; //LL_RECORD_BLOCK_TIME(FTM_CULL); LL_PROFILE_GPU_ZONE("updateCull"); // should always be zero GPU time, but drop a timer to flush stuff out - bool water_clip = !sRenderTransparentWater; + bool water_clip = !sRenderTransparentWater && !sRenderingHUDs; if (water_clip) { @@ -2433,6 +2422,26 @@ void LLPipeline::doOcclusion(LLCamera& camera) LL_PROFILE_GPU_ZONE("doOcclusion"); llassert(!gCubeSnapshot); + if (sReflectionProbesEnabled && sUseOcclusion > 1 && !LLPipeline::sShadowRender && !gCubeSnapshot) + { + gGL.setColorMask(false, false); + LLGLDepthTest depth(GL_TRUE, GL_FALSE); + LLGLDisable cull(GL_CULL_FACE); + + gOcclusionCubeProgram.bind(); + + if (mCubeVB.isNull()) + { //cube VB will be used for issuing occlusion queries + mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX); + } + mCubeVB->setBuffer(); + + mReflectionMapManager.doOcclusion(); + gOcclusionCubeProgram.unbind(); + + gGL.setColorMask(true, true); + } + if (LLPipeline::sUseOcclusion > 1 && !LLSpatialPartition::sTeleportRequested && (sCull->hasOcclusionGroups() || LLVOCachePartition::sNeedsOcclusionCheck)) { @@ -3956,7 +3965,7 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion) bool occlude = LLPipeline::sUseOcclusion > 1 && do_occlusion; - setupHWLights(nullptr); + setupHWLights(); { LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWPOOL("deferred pools"); @@ -4083,7 +4092,7 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera) LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE : 0); calcNearbyLights(camera); - setupHWLights(NULL); + setupHWLights(); gGL.setSceneBlendType(LLRender::BT_ALPHA); gGL.setColorMask(true, false); @@ -4688,16 +4697,13 @@ void LLPipeline::renderDebug() mReflectionMapManager.renderDebug(); } - if (gSavedSettings.getBOOL("RenderReflectionProbeVolumes")) + if (gSavedSettings.getBOOL("RenderReflectionProbeVolumes") && !hud_only) { LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("probe debug display"); bindDeferredShader(gReflectionProbeDisplayProgram, NULL); mScreenTriangleVB->setBuffer(); - // Provide our projection matrix. - set_camera_projection_matrix(gReflectionProbeDisplayProgram); - LLGLEnable blend(GL_BLEND); LLGLDepthTest depth(GL_FALSE); @@ -4741,7 +4747,7 @@ void LLPipeline::renderDebug() } } - if (hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) + if (hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !hud_only) { LLVertexBuffer::unbind(); @@ -5193,6 +5199,19 @@ void LLPipeline::addToQuickLookup( LLDrawPool* new_poolp ) } break; + case LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK: + if (mPBRAlphaMaskPool) + { + llassert(0); + LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate PBR Alpha Mask Pool" << LL_ENDL; + } + else + { + mPBRAlphaMaskPool = new_poolp; + } + break; + + default: llassert(0); LL_WARNS() << "Invalid Pool Type in LLPipeline::addPool()" << LL_ENDL; @@ -5309,6 +5328,11 @@ void LLPipeline::removeFromQuickLookup( LLDrawPool* poolp ) mPBROpaquePool = NULL; break; + case LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK: + llassert(poolp == mPBRAlphaMaskPool); + mPBRAlphaMaskPool = NULL; + break; + default: llassert(0); LL_WARNS() << "Invalid Pool Type in LLPipeline::removeFromQuickLookup() type=" << poolp->getType() << LL_ENDL; @@ -5452,7 +5476,7 @@ void LLPipeline::calcNearbyLights(LLCamera& camera) LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; assertInitialized(); - if (LLPipeline::sReflectionRender || gCubeSnapshot) + if (LLPipeline::sReflectionRender || gCubeSnapshot || LLPipeline::sRenderingHUDs) { return; } @@ -5633,11 +5657,16 @@ void LLPipeline::calcNearbyLights(LLCamera& camera) } } -void LLPipeline::setupHWLights(LLDrawPool* pool) +void LLPipeline::setupHWLights() { LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; assertInitialized(); + if (LLPipeline::sRenderingHUDs) + { + return; + } + LLEnvironment& environment = LLEnvironment::instance(); LLSettingsSky::ptr_t psky = environment.getCurrentSky(); @@ -6707,88 +6736,6 @@ void LLPipeline::resetVertexBuffers(LLDrawable* drawable) } } -void LLPipeline::resetVertexBuffers() -{ - mResetVertexBuffers = true; -} - -void LLPipeline::doResetVertexBuffers(bool forced) -{ - if (!mResetVertexBuffers) - { - return; - } - if(!forced && LLSpatialPartition::sTeleportRequested) - { - if(gAgent.getTeleportState() != LLAgent::TELEPORT_NONE) - { - return; //wait for teleporting to finish - } - else - { - //teleporting aborted - LLSpatialPartition::sTeleportRequested = FALSE; - mResetVertexBuffers = false; - return; - } - } - - LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; - mResetVertexBuffers = false; - - mCubeVB = NULL; - mDeferredVB = NULL; - - for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin(); - iter != LLWorld::getInstance()->getRegionList().end(); ++iter) - { - LLViewerRegion* region = *iter; - for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++) - { - LLSpatialPartition* part = region->getSpatialPartition(i); - if (part) - { - part->resetVertexBuffers(); - } - } - } - if(LLSpatialPartition::sTeleportRequested) - { - LLSpatialPartition::sTeleportRequested = FALSE; - - LLWorld::getInstance()->clearAllVisibleObjects(); - clearRebuildDrawables(); - } - - resetDrawOrders(); - - gSky.resetVertexBuffers(); - - LLVOPartGroup::destroyGL(); - - if ( LLPathingLib::getInstance() ) - { - LLPathingLib::getInstance()->cleanupVBOManager(); - } - LLVOPartGroup::destroyGL(); - gGL.resetVertexBuffer(); - - LLVertexBuffer::unbind(); - - updateRenderBump(); - - sBakeSunlight = gSavedSettings.getBOOL("RenderBakeSunlight"); - sNoAlpha = gSavedSettings.getBOOL("RenderNoAlpha"); - LLPipeline::sTextureBindTest = gSavedSettings.getBOOL("RenderDebugTextureBind"); - - gGL.initVertexBuffer(); - - mDeferredVB = new LLVertexBuffer(DEFERRED_VB_MASK); - mDeferredVB->allocateBuffer(8, 0); - - LLVOPartGroup::restoreGL(); -} - void LLPipeline::renderObjects(U32 type, bool texture, bool batch_texture, bool rigged) { assertInitialized(); @@ -7448,40 +7395,6 @@ void LLPipeline::renderFinalize() if (RenderScreenSpaceReflections && !gCubeSnapshot) { -#if 0 - LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - screen space reflections"); - LL_PROFILE_GPU_ZONE("screen space reflections"); - - bindDeferredShader(gPostScreenSpaceReflectionProgram, NULL); - mScreenTriangleVB->setBuffer(); - - set_camera_projection_matrix(gPostScreenSpaceReflectionProgram); - - // We need linear depth. - static LLStaticHashedString zfar("zFar"); - static LLStaticHashedString znear("zNear"); - float nearClip = LLViewerCamera::getInstance()->getNear(); - float farClip = LLViewerCamera::getInstance()->getFar(); - gPostScreenSpaceReflectionProgram.uniform1f(zfar, farClip); - gPostScreenSpaceReflectionProgram.uniform1f(znear, nearClip); - - S32 channel = gPostScreenSpaceReflectionProgram.enableTexture(LLShaderMgr::DIFFUSE_MAP, screenTarget()->getUsage()); - if (channel > -1) - { - screenTarget()->bindTexture(0, channel, LLTexUnit::TFO_POINT); - } - - { - LLGLDisable blend(GL_BLEND); - LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS); - - stop_glerror(); - mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3); - stop_glerror(); - } - - unbindDeferredShader(gPostScreenSpaceReflectionProgram); -#else LL_PROFILE_GPU_ZONE("ssr copy"); LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS); @@ -7503,7 +7416,6 @@ void LLPipeline::renderFinalize() mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3); dst.flush(); -#endif } screenTarget()->bindTarget(); @@ -7529,9 +7441,13 @@ void LLPipeline::renderFinalize() gDeferredPostGammaCorrectProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, screenTarget()->getWidth(), screenTarget()->getHeight()); - F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); + static LLCachedControl<F32> exposure(gSavedSettings, "RenderExposure", 1.f); + + F32 e = llclamp(exposure(), 0.5f, 4.f); - gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f / 2.2f)); + static LLStaticHashedString s_exposure("exposure"); + + gDeferredPostGammaCorrectProgram.uniform1f(s_exposure, e); mScreenTriangleVB->setBuffer(); mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3); @@ -7775,18 +7691,6 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ stop_glerror(); } - channel = shader.enableTexture(LLShaderMgr::SCENE_MAP); - if (channel > -1) - { - gGL.getTexUnit(channel)->bind(&mSceneMap); - } - - channel = shader.enableTexture(LLShaderMgr::SCENE_DEPTH); - if (channel > -1) - { - gGL.getTexUnit(channel)->bind(&mSceneMap, true); - } - if (shader.getUniformLocation(LLShaderMgr::VIEWPORT) != -1) { shader.uniform4f(LLShaderMgr::VIEWPORT, (F32) gGLViewport[0], @@ -8029,7 +7933,7 @@ void LLPipeline::renderDeferredLighting() glh::matrix4f mat = copy_matrix(gGLModelView); - setupHWLights(NULL); // to set mSun/MoonDir; + setupHWLights(); // to set mSun/MoonDir; glh::vec4f tc(mSunDir.mV); mat.mult_matrix_vec(tc); @@ -8165,6 +8069,8 @@ void LLPipeline::renderDeferredLighting() soften_shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0); soften_shader.uniform3fv(LLShaderMgr::LIGHTNORM, 1, environment.getClampedLightNorm().mV); + soften_shader.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, LLDrawPoolAlpha::sWaterPlane.mV); + { LLGLDepthTest depth(GL_FALSE); LLGLDisable blend(GL_BLEND); @@ -8568,10 +8474,13 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) shader.uniform1f(LLShaderMgr::PROJECTOR_SHADOW_FADE, 1.f); } - //if (!gCubeSnapshot) + // make sure we're not already targeting the same spot light with both shadow maps + llassert(mTargetShadowSpotLight[0] != mTargetShadowSpotLight[1] || mTargetShadowSpotLight[0].isNull()); + + if (!gCubeSnapshot) { LLDrawable* potential = drawablep; - //determine if this is a good light for casting shadows + //determine if this light is higher priority than one of the existing spot shadows F32 m_pri = volume->getSpotLightPriority(); for (U32 i = 0; i < 2; i++) @@ -8580,7 +8489,7 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) if (mTargetShadowSpotLight[i].notNull()) { - pri = mTargetShadowSpotLight[i]->getVOVolume()->getSpotLightPriority(); + pri = mTargetShadowSpotLight[i]->getVOVolume()->getSpotLightPriority(); } if (m_pri > pri) @@ -8593,6 +8502,9 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) } } + // make sure we didn't end up targeting the same spot light with both shadow maps + llassert(mTargetShadowSpotLight[0] != mTargetShadowSpotLight[1] || mTargetShadowSpotLight[0].isNull()); + LLViewerTexture* img = volume->getLightTexture(); if (img == NULL) @@ -8713,6 +8625,21 @@ void LLPipeline::bindReflectionProbes(LLGLSLShader& shader) setEnvMat(shader); } + + // reflection probe shaders generally sample the scene map as well for SSR + channel = shader.enableTexture(LLShaderMgr::SCENE_MAP); + if (channel > -1) + { + gGL.getTexUnit(channel)->bind(&mSceneMap); + } + + channel = shader.enableTexture(LLShaderMgr::SCENE_DEPTH); + if (channel > -1) + { + gGL.getTexUnit(channel)->bind(&mSceneMap, true); + } + + } void LLPipeline::unbindReflectionProbes(LLGLSLShader& shader) @@ -9236,6 +9163,24 @@ LLRenderTarget* LLPipeline::getSpotShadowTarget(U32 i) static LLTrace::BlockTimerStatHandle FTM_GEN_SUN_SHADOW("Gen Sun Shadow"); static LLTrace::BlockTimerStatHandle FTM_GEN_SUN_SHADOW_SPOT_RENDER("Spot Shadow Render"); +// helper class for disabling occlusion culling for the current stack frame +class LLDisableOcclusionCulling +{ +public: + S32 mUseOcclusion; + + LLDisableOcclusionCulling() + { + mUseOcclusion = LLPipeline::sUseOcclusion; + LLPipeline::sUseOcclusion = 0; + } + + ~LLDisableOcclusionCulling() + { + LLPipeline::sUseOcclusion = mUseOcclusion; + } +}; + void LLPipeline::generateSunShadow(LLCamera& camera) { if (!sRenderDeferred || RenderShadowDetail <= 0) @@ -9246,6 +9191,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; //LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW); LL_PROFILE_GPU_ZONE("generateSunShadow"); + LLDisableOcclusionCulling no_occlusion; + bool skip_avatar_update = false; if (!isAgentAvatarValid() || gAgentCamera.getCameraAnimating() || gAgentCamera.getCameraMode() != CAMERA_MODE_MOUSELOOK || !LLVOAvatar::sVisibleInFirstPerson) { @@ -9479,7 +9426,7 @@ void LLPipeline::generateSunShadow(LLCamera& camera) F32 dist[] = { near_clip, mSunClipPlanes.mV[0], mSunClipPlanes.mV[1], mSunClipPlanes.mV[2], mSunClipPlanes.mV[3] }; if (mSunDiffuse == LLColor4::black) - { //sun diffuse is totally shadows don't matter + { //sun diffuse is totally black shadows don't matter LLGLDepthTest depth(GL_TRUE); for (S32 j = 0; j < 4; j++) @@ -9862,7 +9809,6 @@ void LLPipeline::generateSunShadow(LLCamera& camera) } } - //hack to disable projector shadows bool gen_shadow = RenderShadowDetail > 1; @@ -9874,6 +9820,9 @@ void LLPipeline::generateSunShadow(LLCamera& camera) F32 fade_amt = gFrameIntervalSeconds.value() * llmax(LLTrace::get_frame_recording().getLastRecording().getSum(*velocity_stat) / LLTrace::get_frame_recording().getLastRecording().getDuration().value(), 1.0); + // should never happen + llassert(mTargetShadowSpotLight[0] != mTargetShadowSpotLight[1] || mTargetShadowSpotLight[0].isNull()); + //update shadow targets for (U32 i = 0; i < 2; i++) { //for each current shadow @@ -9904,6 +9853,9 @@ void LLPipeline::generateSunShadow(LLCamera& camera) } } + // this should never happen + llassert(mShadowSpotLight[0] != mShadowSpotLight[1] || mShadowSpotLight[0].isNull()); + for (S32 i = 0; i < 2; i++) { set_current_modelview(saved_view); @@ -9989,8 +9941,6 @@ void LLPipeline::generateSunShadow(LLCamera& camera) LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); - stop_glerror(); - // mSpotShadow[i].bindTarget(); |