From 4f674154d9c97affbb1b54a06c2c68767ba4e248 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Sun, 29 Sep 2024 01:33:14 -0700 Subject: [PATCH] Improve the look of radiance map in Compatibility backend --- drivers/gles3/effects/cubemap_filter.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gles3/effects/cubemap_filter.cpp b/drivers/gles3/effects/cubemap_filter.cpp index b88e6554923..685fee6d1b5 100644 --- a/drivers/gles3/effects/cubemap_filter.cpp +++ b/drivers/gles3/effects/cubemap_filter.cpp @@ -41,7 +41,10 @@ CubemapFilter *CubemapFilter::singleton = nullptr; CubemapFilter::CubemapFilter() { singleton = this; - ggx_samples = GLOBAL_GET("rendering/reflections/sky_reflections/ggx_samples"); + // Use a factor 4 larger for the compatibility renderer to make up for the fact + // That we don't use an array texture. We will reduce samples on low roughness + // to compensate. + ggx_samples = 4 * uint32_t(GLOBAL_GET("rendering/reflections/sky_reflections/ggx_samples")); { String defines; @@ -57,10 +60,10 @@ CubemapFilter::CubemapFilter() { const float qv[6] = { -1.0f, -1.0f, - 3.0f, - -1.0f, -1.0f, 3.0f, + 3.0f, + -1.0f, }; glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, qv, GL_STATIC_DRAW); @@ -146,10 +149,11 @@ void CubemapFilter::filter_radiance(GLuint p_source_cubemap, GLuint p_dest_cubem } if (p_layer > 0) { - const uint32_t sample_counts[4] = { 1, ggx_samples / 4, ggx_samples / 2, ggx_samples }; - uint32_t sample_count = sample_counts[MIN(3, p_layer)]; + const uint32_t sample_counts[5] = { 1, ggx_samples / 16, ggx_samples / 8, ggx_samples / 4, ggx_samples }; + uint32_t sample_count = sample_counts[MIN(4, p_layer)]; - float roughness = float(p_layer) / (p_mipmap_count); + float roughness = float(p_layer) / (p_mipmap_count - 1); + roughness *= roughness; // Convert to non-perceptual roughness. float roughness4 = roughness * roughness; roughness4 *= roughness4; @@ -165,7 +169,7 @@ void CubemapFilter::filter_radiance(GLuint p_source_cubemap, GLuint p_dest_cubem Vector3 dir = importance_sample_GGX(xi, roughness4); Vector3 light_vec = (2.0 * dir.z * dir - Vector3(0.0, 0.0, 1.0)); - if (light_vec.z < 0.0) { + if (light_vec.z <= 0.0) { continue; }