summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclayjohn <claynjohn@gmail.com>2024-09-29 01:33:14 -0700
committerclayjohn <claynjohn@gmail.com>2024-09-29 01:33:14 -0700
commit4f674154d9c97affbb1b54a06c2c68767ba4e248 (patch)
tree8d78e729d06d1977720c336a309130ab6daa3a30
parent1fc82087658066935bed9e1350d62e334c7e0309 (diff)
downloadredot-engine-4f674154d9c97affbb1b54a06c2c68767ba4e248.tar.gz
Improve the look of radiance map in Compatibility backend
-rw-r--r--drivers/gles3/effects/cubemap_filter.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/gles3/effects/cubemap_filter.cpp b/drivers/gles3/effects/cubemap_filter.cpp
index b88e655492..685fee6d1b 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;
}