From 47e311d6e8b9996de3e0a1ac75c13724ce7735aa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Fri, 26 May 2023 16:56:33 -0700 Subject: Addressing some performance related feedback with SSR getting drastically slower. DRTVWR-559 DRTVWR-583 --- indra/llrender/llshadermgr.cpp | 1 + indra/llrender/llshadermgr.h | 1 + indra/newview/app_settings/settings.xml | 15 +++++++++++++-- .../shaders/class3/deferred/screenSpaceReflUtil.glsl | 17 +++++++++++------ indra/newview/pipeline.cpp | 12 +++++++++++- indra/newview/pipeline.h | 3 +++ 6 files changed, 40 insertions(+), 9 deletions(-) (limited to 'indra') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 01bad3a684..1458b98bf5 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1343,6 +1343,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("depthRejectBias"); mReservedUniforms.push_back("glossySampleCount"); mReservedUniforms.push_back("noiseSine"); + mReservedUniforms.push_back("adaptiveStepMultiplier"); mReservedUniforms.push_back("modelview_delta"); mReservedUniforms.push_back("inv_modelview_delta"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 8c19c80cb0..2ab3ba71db 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -168,6 +168,7 @@ public: DEFERRED_SSR_REJECT_BIAS, // "depthRejectBias" DEFERRED_SSR_GLOSSY_SAMPLES, // "glossySampleCount" DEFERRED_SSR_NOISE_SINE, // "noiseSine" + DEFERRED_SSR_ADAPTIVE_STEP_MULT, // "adaptiveStepMultiplier" MODELVIEW_DELTA_MATRIX, // "modelview_delta" INVERSE_MODELVIEW_DELTA_MATRIX, // "inv_modelview_delta" diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 0e72fadec7..533a3361e6 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -9173,7 +9173,7 @@ Type S32 Value - 40 + 25 RenderScreenSpaceReflectionRayStep @@ -9208,6 +9208,17 @@ Value 0.001 + RenderScreenSpaceReflectionAdaptiveStepMultiplier + + Comment + Multiplier to scale adaptive stepping. + Persist + 1 + Type + F32 + Value + 1.6 + RenderScreenSpaceReflectionGlossySamples Comment @@ -9217,7 +9228,7 @@ Type S32 Value - 8 + 4 RenderBumpmapMinDistanceSquared diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index 5ad25c325f..d291196059 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -61,6 +61,8 @@ uniform float rayStep; uniform float distanceBias; uniform float depthRejectBias; uniform float glossySampleCount; +uniform float adaptiveStepMultiplier; +uniform float noiseSine; float epsilon = 0.1; @@ -135,7 +137,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float if (isExponentialStepEnabled) { - step *= 1.05; + step *= adaptiveStepMultiplier; } } if(isBinarySearchEnabled) @@ -302,6 +304,10 @@ uniform vec3 POISSON3D_SAMPLES[128] = vec3[128]( vec3(0.2698198, 0.0002266169, 0.3449324) ); +vec3 getPoissonSample(int i) { + return POISSON3D_SAMPLES[i] * 2 - 1; +} + float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness) { collectedColor = vec4(0); @@ -319,7 +325,7 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, float vignette = clamp((abs(screenpos.x) * abs(screenpos.y)) * 64,0, 1); vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5) * 16, 0, 1); - float zFar = 32.0; + float zFar = 128.0; vignette *= clamp(1.0+(viewPos.z/zFar), 0.0, 1.0); @@ -329,17 +335,16 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, totalSamples = int(max(glossySampleCount, glossySampleCount * glossiness * vignette)); - totalSamples = max(totalSamples, 4); + totalSamples = max(totalSamples, 1); { { for (int i = 0; i < totalSamples; i++) { - vec3 firstBasis = normalize(cross(POISSON3D_SAMPLES[i] * 2 - 1, rayDirection)); + vec3 firstBasis = normalize(cross(getPoissonSample(i), rayDirection)); vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); - vec3 reflectionDirectionRandomized = rayDirection + ((firstBasis * coeffs.x + secondBasis * coeffs.y) * 0.125 * max(glossiness, 0.025)); - //vec3 reflectionDirectionRandomized = rayDirection + (POISSON3D_SAMPLES[i] * 2 - 1) * 0.125 * max(glossiness, 0.025); + vec3 reflectionDirectionRandomized = rayDirection + ((firstBasis * coeffs.x + secondBasis * coeffs.y) * glossiness); //float hitDepth; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index a49c57ba1e..2112993859 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -195,6 +195,7 @@ S32 LLPipeline::RenderScreenSpaceReflectionIterations; F32 LLPipeline::RenderScreenSpaceReflectionRayStep; F32 LLPipeline::RenderScreenSpaceReflectionDistanceBias; F32 LLPipeline::RenderScreenSpaceReflectionDepthRejectBias; +F32 LLPipeline::RenderScreenSpaceReflectionAdaptiveStepMultiplier; S32 LLPipeline::RenderScreenSpaceReflectionGlossySamples; S32 LLPipeline::RenderBufferVisualization; LLTrace::EventStatHandle LLPipeline::sStatBatchSize("renderbatchsize"); @@ -552,7 +553,8 @@ void LLPipeline::init() connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionRayStep"); connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionDistanceBias"); connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionDepthRejectBias"); - connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionsGlossySamples"); + connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionAdaptiveStepMultiplier"); + connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionGlossySamples"); connectRefreshCachedSettingsSafe("RenderBufferVisualization"); gSavedSettings.getControl("RenderAutoHideSurfaceAreaLimit")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings)); } @@ -1039,6 +1041,7 @@ void LLPipeline::refreshCachedSettings() RenderScreenSpaceReflectionRayStep = gSavedSettings.getF32("RenderScreenSpaceReflectionRayStep"); RenderScreenSpaceReflectionDistanceBias = gSavedSettings.getF32("RenderScreenSpaceReflectionDistanceBias"); RenderScreenSpaceReflectionDepthRejectBias = gSavedSettings.getF32("RenderScreenSpaceReflectionDepthRejectBias"); + RenderScreenSpaceReflectionAdaptiveStepMultiplier = gSavedSettings.getF32("RenderScreenSpaceReflectionAdaptiveStepMultiplier"); RenderScreenSpaceReflectionGlossySamples = gSavedSettings.getS32("RenderScreenSpaceReflectionGlossySamples"); RenderBufferVisualization = gSavedSettings.getS32("RenderBufferVisualization"); sReflectionProbesEnabled = LLFeatureManager::getInstance()->isFeatureAvailable("RenderReflectionsEnabled") && gSavedSettings.getBOOL("RenderReflectionsEnabled"); @@ -8421,6 +8424,13 @@ void LLPipeline::bindReflectionProbes(LLGLSLShader& shader) shader.uniform1f(LLShaderMgr::DEFERRED_SSR_RAY_STEP, RenderScreenSpaceReflectionRayStep); shader.uniform1f(LLShaderMgr::DEFERRED_SSR_GLOSSY_SAMPLES, RenderScreenSpaceReflectionGlossySamples); shader.uniform1f(LLShaderMgr::DEFERRED_SSR_REJECT_BIAS, RenderScreenSpaceReflectionDepthRejectBias); + mPoissonOffset++; + + if (mPoissonOffset > 128 - RenderScreenSpaceReflectionGlossySamples) + mPoissonOffset = 0; + + shader.uniform1f(LLShaderMgr::DEFERRED_SSR_NOISE_SINE, mPoissonOffset); + shader.uniform1f(LLShaderMgr::DEFERRED_SSR_ADAPTIVE_STEP_MULT, RenderScreenSpaceReflectionAdaptiveStepMultiplier); channel = shader.enableTexture(LLShaderMgr::SCENE_DEPTH); if (channel > -1) diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index d9e6cf9933..19c8b06a46 100644 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -630,6 +630,8 @@ public: S32 mNumVisibleFaces; + S32 mPoissonOffset; + static S32 sCompiles; static bool sShowHUDAttachments; @@ -1034,6 +1036,7 @@ public: static F32 RenderScreenSpaceReflectionRayStep; static F32 RenderScreenSpaceReflectionDistanceBias; static F32 RenderScreenSpaceReflectionDepthRejectBias; + static F32 RenderScreenSpaceReflectionAdaptiveStepMultiplier; static S32 RenderScreenSpaceReflectionGlossySamples; static S32 RenderBufferVisualization; }; -- cgit v1.2.3