Skip to content

Fix error spam when using SSAO or SSIL on less than 32x32 - #125822

Open
Joy-less wants to merge 1 commit into
godotengine:masterfrom
Joy-less:fix-error-spam-when-using-ssao-or-ssil-on-less-than-32x32
Open

Joy-less wants to merge 1 commit into
godotengine:masterfrom
Joy-less:fix-error-spam-when-using-ssao-or-ssil-on-less-than-32x32

Conversation

@Joy-less

@Joy-less Joy-less commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What problem(s) does this PR solve?

Additional information

SSAO and SSIL appear to always create exactly 5 mipmaps, which is not possible when the resolution is less than 32x32. This fix makes them reduce the number of mipmaps if the resolution is less than 32x32.

This PR seems to fix my Mirror3D addon:
ssao-ssil-small-viewport-test.zip

Although SSIL may need to be double-checked, because at high intensities, it looks overly bright when under 32x32. But this only happens in the editor, not in game. No idea what the reason could be.

No AI used (except to discover that log2 is the correct function to use).

I also tested the limit_mipmaps function to ensure it works for all values. Test it yourself:

See more
#include <iostream>
#include <cstdint>
#include <cmath>

using namespace std;

struct Size2i {
    int32_t x;
    int32_t y;
};

static uint32_t limit_mipmaps(uint32_t p_desired_mipmaps, Size2i resolution) {
	uint32_t min_resolution = std::max(1u, (uint32_t)std::min(resolution.x, resolution.y));
	uint32_t max_mipmaps = (uint32_t)std::log2((double)min_resolution) + 1;
	return std::min(p_desired_mipmaps, max_mipmaps);
}

static void test(uint32_t p_desired_mipmaps, Size2i resolution) {
    std::cout << "Desired Mipmaps: " << p_desired_mipmaps
        << " | Resolution: " << resolution.x << ", " << resolution.y << " | "
        << "Limited Mipmaps: " << limit_mipmaps(p_desired_mipmaps, resolution) << "\n";
}

int main() {
    for (int32_t i = 0; i <= 128; i++) {
        test(5, { i, i });
    }
}

Alternative fix

I also tried fixing it by disabling SSAO and SSIL if the resolution is under 32x32. This seems to work fine as well:

Replace:

			ss_flags |= environment_get_ssao_enabled(p_render_data->environment) ? SCREEN_SPACE_EFFECTS_FLAGS_USE_SSAO : 0;
			ss_flags |= environment_get_ssil_enabled(p_render_data->environment) ? SCREEN_SPACE_EFFECTS_FLAGS_USE_SSIL : 0;

With:

			ss_flags |= (p_viewport_size.x >= 32 && p_viewport_size.y >= 32 && environment_get_ssao_enabled(p_render_data->environment)) ? SCREEN_SPACE_EFFECTS_FLAGS_USE_SSAO : 0;
			ss_flags |= (p_viewport_size.x >= 32 && p_viewport_size.y >= 32 && environment_get_ssil_enabled(p_render_data->environment)) ? SCREEN_SPACE_EFFECTS_FLAGS_USE_SSIL : 0;

Replace:

	p_render_data->scene_data->emissive_exposure_normalization = -1.0;

With:

	// SSAO and SSIL use 5 mipmaps (1x1, 2x2, 4x4, 8x8, 16x16), meaning the minimum resolution is 32x32.
	if (screen_size.x < 32 || screen_size.y < 32) {
		using_ssao = false;
		using_ssil = false;
	}

	p_render_data->scene_data->emissive_exposure_normalization = -1.0;

@Joy-less
Joy-less requested a review from a team as a code owner November 25, 2026 23:40
@clayjohn

Copy link
Copy Markdown
Member

I would just have a WARN_PRINT_ONCE and then disable SSAO/SSIL when the viewport is less than 32 pixels in either dimension. It will be much simpler

@Joy-less

Copy link
Copy Markdown
Contributor Author

I would just have a WARN_PRINT_ONCE and then disable SSAO/SSIL when the viewport is less than 32 pixels in either dimension. It will be much simpler

Disabling SSAO/SSIL is reasonable, however having a WARN_PRINT_ONCE would be unnecessary noise (there would be no good way to prevent that warning, if you were using a low-res SubViewport inside a game with SSAO/SSIL).

I will say that the Compatibility renderer supports SSAO with any resolution (SSIL is not supported at all), so currently Compatibility is more effective for this feature.

I will say I tested this pull request with SSAO, and it works perfectly. SSIL seems to be questionable at some intensities but arguably still better than nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enabling SSAO or SSIL causes error spam in scenes with SubViewport when SubViewport.size is too small

3 participants