From 8d67ad3d86cbc57631c4b56926ff9a0ea5b82897 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 13 Jun 2013 18:13:30 -0500 Subject: NORSPEC-261 No more magic numbers, parity between forward and deferred rendering WRT to windlight and legacy shininess. Reviewed by Graham (a little bit). --- indra/newview/pipeline.cpp | 47 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'indra/newview/pipeline.cpp') diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index b5fbf08786..9a4a233b54 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -1401,7 +1401,8 @@ void LLPipeline::createLUTBuffers() LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_R16F, lightResX, lightResY, GL_RED, GL_FLOAT, ls, false); //LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_UNSIGNED_BYTE, lightResX, lightResY, GL_RED, GL_UNSIGNED_BYTE, ls, false); gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); - gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); delete [] ls; } @@ -5825,9 +5826,9 @@ void LLPipeline::setupAvatarLights(BOOL for_edit) if (LLPipeline::sRenderDeferred) { - diffuse.mV[0] = powf(diffuse.mV[0], 2.2f); + /*diffuse.mV[0] = powf(diffuse.mV[0], 2.2f); diffuse.mV[1] = powf(diffuse.mV[1], 2.2f); - diffuse.mV[2] = powf(diffuse.mV[2], 2.2f); + diffuse.mV[2] = powf(diffuse.mV[2], 2.2f);*/ } mHWLightColors[1] = diffuse; @@ -5872,9 +5873,9 @@ void LLPipeline::setupAvatarLights(BOOL for_edit) if (LLPipeline::sRenderDeferred) { - backlight_diffuse.mV[0] = powf(backlight_diffuse.mV[0], 2.2f); + /*backlight_diffuse.mV[0] = powf(backlight_diffuse.mV[0], 2.2f); backlight_diffuse.mV[1] = powf(backlight_diffuse.mV[1], 2.2f); - backlight_diffuse.mV[2] = powf(backlight_diffuse.mV[2], 2.2f); + backlight_diffuse.mV[2] = powf(backlight_diffuse.mV[2], 2.2f);*/ } mHWLightColors[1] = backlight_diffuse; @@ -6086,9 +6087,9 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) if (LLPipeline::sRenderDeferred) { - light_diffuse.mV[0] = powf(light_diffuse.mV[0], 2.2f); + /*light_diffuse.mV[0] = powf(light_diffuse.mV[0], 2.2f); light_diffuse.mV[1] = powf(light_diffuse.mV[1], 2.2f); - light_diffuse.mV[2] = powf(light_diffuse.mV[2], 2.2f); + light_diffuse.mV[2] = powf(light_diffuse.mV[2], 2.2f);*/ } mHWLightColors[0] = light_diffuse; @@ -6161,9 +6162,9 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) if (LLPipeline::sRenderDeferred) { - light_color.mV[0] = powf(light_color.mV[0], 2.2f); + /*light_color.mV[0] = powf(light_color.mV[0], 2.2f); light_color.mV[1] = powf(light_color.mV[1], 2.2f); - light_color.mV[2] = powf(light_color.mV[2], 2.2f); + light_color.mV[2] = powf(light_color.mV[2], 2.2f);*/ } mHWLightColors[cur_light] = light_color; @@ -6176,7 +6177,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) if (sRenderDeferred) { F32 size = light_radius*1.5f; - light_state->setLinearAttenuation(size*size); + light_state->setLinearAttenuation(size); light_state->setQuadraticAttenuation(light->getLightFalloff()*0.5f+1.f); } else @@ -6241,9 +6242,9 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) if (LLPipeline::sRenderDeferred) { - light_color.mV[0] = powf(light_color.mV[0], 2.2f); + /*light_color.mV[0] = powf(light_color.mV[0], 2.2f); light_color.mV[1] = powf(light_color.mV[1], 2.2f); - light_color.mV[2] = powf(light_color.mV[2], 2.2f); + light_color.mV[2] = powf(light_color.mV[2], 2.2f);*/ } mHWLightColors[2] = light_color; @@ -8489,7 +8490,7 @@ void LLPipeline::renderDeferredLighting() LLFastTimer ftm(FTM_LOCAL_LIGHTS); gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); - gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s); + gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); gGL.syncMatrices(); @@ -8510,7 +8511,7 @@ void LLPipeline::renderDeferredLighting() glh::vec3f tc(c); mat.mult_matrix_vec(tc); - fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s*s)); + fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s)); light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff()*0.5f)); } } @@ -8543,12 +8544,12 @@ void LLPipeline::renderDeferredLighting() setupSpotLight(gDeferredSpotLightProgram, drawablep); LLColor3 col = volume->getLightColor(); - col.mV[0] = powf(col.mV[0], 2.2f); + /*col.mV[0] = powf(col.mV[0], 2.2f); col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); - gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s); + gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); gGL.syncMatrices(); @@ -8595,11 +8596,11 @@ void LLPipeline::renderDeferredLighting() col[count] = light_colors.front(); light_colors.pop_front(); - col[count].mV[0] = powf(col[count].mV[0], 2.2f); + /*col[count].mV[0] = powf(col[count].mV[0], 2.2f); col[count].mV[1] = powf(col[count].mV[1], 2.2f); - col[count].mV[2] = powf(col[count].mV[2], 2.2f); + col[count].mV[2] = powf(col[count].mV[2], 2.2f);*/ - far_z = llmin(light[count].mV[2]-sqrtf(light[count].mV[3]), far_z); + far_z = llmin(light[count].mV[2]-light[count].mV[3], far_z); //col[count] = pow4fsrgb(col[count], 2.2f); count++; if (count == max_count || fullscreen_lights.empty()) @@ -8642,12 +8643,12 @@ void LLPipeline::renderDeferredLighting() LLColor3 col = volume->getLightColor(); - col.mV[0] = powf(col.mV[0], 2.2f); + /*col.mV[0] = powf(col.mV[0], 2.2f); col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v); - gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s); + gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); -- cgit v1.2.3 From ccd04cd66c0a550694fefe41042ef47466780a92 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 18 Jun 2013 17:24:21 -0500 Subject: Occlusion culling overhaul. --- indra/newview/pipeline.cpp | 145 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 132 insertions(+), 13 deletions(-) (limited to 'indra/newview/pipeline.cpp') diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 9a4a233b54..6efdf47ec5 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -279,7 +279,7 @@ std::string gPoolNames[] = "POOL_ALPHA" }; -void drawBox(const LLVector3& c, const LLVector3& r); +void drawBox(const LLVector4a& c, const LLVector4a& r); void drawBoxOutline(const LLVector3& pos, const LLVector3& size); U32 nhpo2(U32 v); LLVertexBuffer* ll_create_cube_vb(U32 type_mask, U32 usage); @@ -929,9 +929,12 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) S32 shadow_detail = RenderShadowDetail; BOOL ssao = RenderDeferredSSAO; + const U32 occlusion_divisor = 3; + //allocate deferred rendering color buffers if (!mDeferredScreen.allocate(resX, resY, GL_SRGB8_ALPHA8, TRUE, TRUE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false; if (!mDeferredDepth.allocate(resX, resY, 0, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false; + if (!mOcclusionDepth.allocate(resX/occlusion_divisor, resY/occlusion_divisor, 0, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false; if (!addDeferredAttachments(mDeferredScreen)) return false; GLuint screenFormat = GL_RGBA16; @@ -972,6 +975,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) for (U32 i = 0; i < 4; i++) { if (!mShadow[i].allocate(sun_shadow_map_width,U32(resY*scale), 0, TRUE, FALSE, LLTexUnit::TT_TEXTURE)) return false; + if (!mShadowOcclusion[i].allocate(mShadow[i].getWidth()/occlusion_divisor, mShadow[i].getHeight()/occlusion_divisor, 0, TRUE, FALSE, LLTexUnit::TT_TEXTURE)) return false; } } else @@ -979,6 +983,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) for (U32 i = 0; i < 4; i++) { mShadow[i].release(); + mShadowOcclusion[i].release(); } } @@ -991,6 +996,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) for (U32 i = 4; i < 6; i++) { if (!mShadow[i].allocate(spot_shadow_map_width, height, 0, TRUE, FALSE)) return false; + if (!mShadowOcclusion[i].allocate(mShadow[i].getWidth()/occlusion_divisor, mShadow[i].getHeight()/occlusion_divisor, 0, TRUE, FALSE)) return false; } } else @@ -998,6 +1004,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) for (U32 i = 4; i < 6; i++) { mShadow[i].release(); + mShadowOcclusion[i].release(); } } @@ -1014,11 +1021,13 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) for (U32 i = 0; i < 6; i++) { mShadow[i].release(); + mShadowOcclusion[i].release(); } mFXAABuffer.release(); mScreen.release(); mDeferredScreen.release(); //make sure to release any render targets that share a depth buffer with mDeferredScreen first mDeferredDepth.release(); + mOcclusionDepth.release(); if (!mScreen.allocate(resX, resY, GL_RGBA, TRUE, TRUE, LLTexUnit::TT_RECT_TEXTURE, FALSE)) return false; } @@ -2433,7 +2442,14 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl if (to_texture) { - mScreen.bindTarget(); + if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + { + mOcclusionDepth.bindTarget(); + } + else + { + mScreen.bindTarget(); + } } if (sUseOcclusion > 1) @@ -2571,7 +2587,14 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl if (to_texture) { - mScreen.flush(); + if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + { + mOcclusionDepth.flush(); + } + else + { + mScreen.flush(); + } } } @@ -2639,6 +2662,75 @@ void LLPipeline::markOccluder(LLSpatialGroup* group) } } +void LLPipeline::downsampleDepthBuffer(LLRenderTarget& source, LLRenderTarget& dest, LLRenderTarget* scratch_space) +{ + LLGLSLShader* last_shader = LLGLSLShader::sCurBoundShaderPtr; + + LLGLSLShader* shader = NULL; + + if (scratch_space) + { + scratch_space->copyContents(source, + 0, 0, source.getWidth(), source.getHeight(), + 0, 0, scratch_space->getWidth(), scratch_space->getHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST); + } + + dest.bindTarget(); + + + gDownsampleDepthProgram.bind(); + + LLStrider vert; + mDeferredVB->getVertexStrider(vert); + LLStrider tc0; + + vert[0].set(-1,1,0); + vert[1].set(-1,-3,0); + vert[2].set(3,1,0); + + if (source.getUsage() == LLTexUnit::TT_RECT_TEXTURE) + { + shader = &gDownsampleDepthRectProgram; + shader->bind(); + shader->uniform2f("delta", 1.f, 1.f); + shader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, source.getWidth(), source.getHeight()); + } + else + { + shader = &gDownsampleDepthProgram; + shader->bind(); + shader->uniform2f("delta", 1.f/source.getWidth(), 1.f/source.getHeight()); + shader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, 1.f, 1.f); + } + + gGL.getTexUnit(0)->bind(scratch_space ? scratch_space : &source, TRUE); + + { + LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS); + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + } + + dest.flush(); + + if (last_shader) + { + last_shader->bind(); + } + else + { + gDownsampleDepthProgram.unbind(); + } +} + +void LLPipeline::doOcclusion(LLCamera& camera, LLRenderTarget& source, LLRenderTarget& dest, LLRenderTarget* scratch_space) +{ + downsampleDepthBuffer(source, dest, scratch_space); + dest.bindTarget(); + doOcclusion(camera); + dest.flush(); +} + void LLPipeline::doOcclusion(LLCamera& camera) { if (LLPipeline::sUseOcclusion > 1 && sCull->hasOcclusionGroups()) @@ -4551,7 +4643,7 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera) gGL.setColorMask(true, false); } -void LLPipeline::renderGeomPostDeferred(LLCamera& camera) +void LLPipeline::renderGeomPostDeferred(LLCamera& camera, bool do_occlusion) { LLFastTimer t(FTM_POST_DEFERRED_POOLS); U32 cur_type = 0; @@ -4566,7 +4658,7 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera) gGL.setColorMask(true, false); pool_set_t::iterator iter1 = mPools.begin(); - BOOL occlude = LLPipeline::sUseOcclusion > 1; + BOOL occlude = LLPipeline::sUseOcclusion > 1 && do_occlusion; while ( iter1 != mPools.end() ) { @@ -4580,7 +4672,7 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera) gGLLastMatrix = NULL; gGL.loadMatrix(gGLModelView); LLGLSLShader::bindNoShader(); - doOcclusion(camera); + doOcclusion(camera, mScreen, mOcclusionDepth, &mDeferredDepth); gGL.setColorMask(true, false); } @@ -4798,6 +4890,7 @@ void LLPipeline::renderPhysicsDisplay() mPhysicsDisplay.flush(); } +extern std::set visible_selected_groups; void LLPipeline::renderDebug() { @@ -5208,6 +5301,27 @@ void LLPipeline::renderDebug() } } + if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCCLUSION) && LLGLSLShader::sNoFixedFunction) + { //render visible selected group occlusion geometry + gDebugProgram.bind(); + LLGLDepthTest depth(GL_TRUE, GL_FALSE); + gGL.diffuseColor3f(1,0,1); + for (std::set::iterator iter = visible_selected_groups.begin(); iter != visible_selected_groups.end(); ++iter) + { + LLSpatialGroup* group = *iter; + + LLVector4a fudge; + fudge.splat(0.25f); //SG_OCCLUSION_FUDGE + + LLVector4a size; + size.setAdd(fudge, group->mBounds[1]); + + drawBox(group->mBounds[0], size); + } + } + + visible_selected_groups.clear(); + if (LLGLSLShader::sNoFixedFunction) { gUIProgram.bind(); @@ -8205,11 +8319,7 @@ void LLPipeline::renderDeferredLighting() LLStrider vert; mDeferredVB->getVertexStrider(vert); - LLStrider tc0; - LLStrider tc1; - mDeferredVB->getTexCoord0Strider(tc0); - mDeferredVB->getTexCoord1Strider(tc1); - + vert[0].set(-1,1,0); vert[1].set(-1,-3,0); vert[2].set(3,1,0); @@ -8390,7 +8500,7 @@ void LLPipeline::renderDeferredLighting() LLPipeline::END_RENDER_TYPES); - renderGeomPostDeferred(*LLViewerCamera::getInstance()); + renderGeomPostDeferred(*LLViewerCamera::getInstance(), false); gPipeline.popRenderTypeMask(); } @@ -9324,9 +9434,15 @@ void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera gDeferredShadowCubeProgram.bind(); } + LLRenderTarget& occlusion_target = mShadowOcclusion[LLViewerCamera::sCurCameraID-1]; + + occlusion_target.bindTarget(); updateCull(shadow_cam, result); + occlusion_target.flush(); + stateSort(shadow_cam, result); + //generate shadow map gGL.matrixMode(LLRender::MM_PROJECTION); gGL.pushMatrix(); @@ -9414,7 +9530,10 @@ void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera gDeferredShadowCubeProgram.bind(); gGLLastMatrix = NULL; gGL.loadMatrix(gGLModelView); - doOcclusion(shadow_cam); + + LLRenderTarget& occlusion_source = mShadow[LLViewerCamera::sCurCameraID-1]; + + doOcclusion(shadow_cam, occlusion_source, occlusion_target); if (use_shader) { -- cgit v1.2.3 From 45b1466de60dc1788353508debbb321b59875884 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 18 Jun 2013 19:51:02 -0500 Subject: Review cleanup --- indra/newview/pipeline.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/pipeline.cpp') diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 6efdf47ec5..30c726f76a 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -2676,9 +2676,7 @@ void LLPipeline::downsampleDepthBuffer(LLRenderTarget& source, LLRenderTarget& d } dest.bindTarget(); - - - gDownsampleDepthProgram.bind(); + dest.clear(GL_DEPTH_BUFFER_BIT); LLStrider vert; mDeferredVB->getVertexStrider(vert); @@ -2719,7 +2717,7 @@ void LLPipeline::downsampleDepthBuffer(LLRenderTarget& source, LLRenderTarget& d } else { - gDownsampleDepthProgram.unbind(); + shader->unbind(); } } -- cgit v1.2.3 From b49594662573959e0d7ccc08a2b266b3abc8130e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 19 Jun 2013 11:30:32 -0500 Subject: Point light color (de)correction. --- indra/newview/pipeline.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/pipeline.cpp') diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 30c726f76a..1e66c40e87 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8592,9 +8592,9 @@ void LLPipeline::renderDeferredLighting() continue; } - col.mV[0] = powf(col.mV[0], 2.2f); + /*col.mV[0] = powf(col.mV[0], 2.2f); col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ LLFastTimer ftm(FTM_LOCAL_LIGHTS); gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); -- cgit v1.2.3