From b0a5216b272d24055735d73e1b51176a8635f3b3 Mon Sep 17 00:00:00 2001 From: William Weaver Date: Sun, 9 Mar 2025 17:51:45 +0300 Subject: [PATCH] Fixes: Improve SSAO Appearance Consistency for High-Resolution Snapshots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Detailed description of the changes. This commit addresses an issue where Screen Space Ambient Occlusion (SSAO) appearance was inconsistent, particularly in high-resolution snapshots compared to the main viewer window. Previously, the SSAO radii parameters (RenderSSAOScale and RenderSSAOMaxScale) were directly applied to the shader without considering the resolution difference between the viewer window and the render target (snapshot). This resulted in SSAO appearing too small and under-sampled in high-resolution snapshots, as the sampling radius was not scaled up to match the larger snapshot resolution. To resolve this, a scaling factor is now calculated based on the ratio of the viewer window's height to the snapshot's height: scale_factor = viewer_window_height / snapshot_height This scale factor is then used to divide the user-defined SSAO radius values before they are passed to the shader. When the snapshot resolution is higher than the viewer resolution, the `scale_factor` becomes less than 1. Dividing by this factor effectively increases the SSAO radii, ensuring the ambient occlusion effect scales proportionally to the higher resolution. For example, if the viewer is running at 1080p height and a snapshot is taken at 4096p height, the scale factor would be approximately 1080 / 4096 ≈ 0.2637. Dividing the SSAO radii by 0.2637 results in multiplying them by approximately 3.79, thus scaling up the SSAO effect to maintain visual consistency in the high-resolution snapshot. Intended Impact & Benefits: - **Visual Consistency:** Ensures that the SSAO effect maintains a consistent visual scale and intensity between the interactive viewer display and high-resolution snapshots, providing a more predictable and professional output. - **Improved User Experience:** Users capturing high-resolution snapshots will now experience a more accurate and visually pleasing SSAO effect, preventing the unintended diminishment of ambient occlusion and preserving the intended scene aesthetics. - **Balanced Quality Across Resolutions:** The fix dynamically adjusts the SSAO radii based on resolution, maintaining a balanced and consistent level of detail and intensity across varying output resolutions without requiring manual user adjustments. Testing: - **Build:** Rebuild the Aperture Viewer after applying this commit. - **Run:** Launch the viewer and ensure that Screen Space Ambient Occlusion (SSAO) is enabled in the graphics settings. - **Visual Comparison (Viewer vs. High-Resolution Snapshot):** 1. In the viewer, observe the appearance of SSAO in a scene with noticeable ambient occlusion effects. 2. Take a high-resolution snapshot to disk (e.g., 4096p or higher). 3. Compare the SSAO effect in the saved snapshot image to the SSAO in the live viewer window. The SSAO in the snapshot should now appear visually consistent in scale and intensity with the viewer, and not diminished or under-sampled. - **Resolution Variation (Recommended):** Test with different viewer window sizes (e.g., 720p, 1080p) and snapshot resolutions (including resolutions higher than the viewer) to verify that the SSAO consistency is maintained across a range of rendering targets. Documentation: - No specific updates to the Wiki are required as this commit is a bug fix that improves the existing SSAO feature's consistency. - It is recommended to include a note about this fix in the Viewer release notes to inform users about the improved SSAO behavior in high-resolution snapshots. --- indra/newview/pipeline.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index b9d9830298..8f86a1cda3 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8796,14 +8796,20 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ shader.uniform1f(LLShaderMgr::DEFERRED_SHADOW_NOISE, RenderShadowNoise); shader.uniform1f(LLShaderMgr::DEFERRED_BLUR_SIZE, RenderShadowBlurSize); - shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_RADIUS, RenderSSAOScale); - shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_MAX_RADIUS, (GLfloat)RenderSSAOMaxScale); +// Compute scale factor to match AO appearance between view and snapshot. + F32 screen_to_target_scale_factor = (F32)gViewerWindow->getWindowHeightRaw() / deferred_target->getHeight(); + //shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_RADIUS, RenderSSAOScale); + shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_RADIUS, RenderSSAOScale / screen_to_target_scale_factor); + //shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_MAX_RADIUS, (GLfloat)RenderSSAOMaxScale); + shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_MAX_RADIUS, RenderSSAOMaxScale / screen_to_target_scale_factor); + // F32 ssao_factor = RenderSSAOFactor; shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR, ssao_factor); shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR_INV, 1.0f/ssao_factor); LLVector3 ssao_effect = RenderSSAOEffect; + F32 matrix_diag = (ssao_effect[0] + 2.0f*ssao_effect[1])/3.0f; F32 matrix_nondiag = (ssao_effect[0] - ssao_effect[1])/3.0f; // This matrix scales (proj of color onto <1/rt(3),1/rt(3),1/rt(3)>) by