Skip to content

Commit 4f67415

Browse files
committed
Improve the look of radiance map in Compatibility backend
1 parent 1fc8208 commit 4f67415

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/gles3/effects/cubemap_filter.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ CubemapFilter *CubemapFilter::singleton = nullptr;
4141

4242
CubemapFilter::CubemapFilter() {
4343
singleton = this;
44-
ggx_samples = GLOBAL_GET("rendering/reflections/sky_reflections/ggx_samples");
44+
// Use a factor 4 larger for the compatibility renderer to make up for the fact
45+
// That we don't use an array texture. We will reduce samples on low roughness
46+
// to compensate.
47+
ggx_samples = 4 * uint32_t(GLOBAL_GET("rendering/reflections/sky_reflections/ggx_samples"));
4548

4649
{
4750
String defines;
@@ -57,10 +60,10 @@ CubemapFilter::CubemapFilter() {
5760
const float qv[6] = {
5861
-1.0f,
5962
-1.0f,
60-
3.0f,
61-
-1.0f,
6263
-1.0f,
6364
3.0f,
65+
3.0f,
66+
-1.0f,
6467
};
6568

6669
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
146149
}
147150

148151
if (p_layer > 0) {
149-
const uint32_t sample_counts[4] = { 1, ggx_samples / 4, ggx_samples / 2, ggx_samples };
150-
uint32_t sample_count = sample_counts[MIN(3, p_layer)];
152+
const uint32_t sample_counts[5] = { 1, ggx_samples / 16, ggx_samples / 8, ggx_samples / 4, ggx_samples };
153+
uint32_t sample_count = sample_counts[MIN(4, p_layer)];
151154

152-
float roughness = float(p_layer) / (p_mipmap_count);
155+
float roughness = float(p_layer) / (p_mipmap_count - 1);
156+
roughness *= roughness; // Convert to non-perceptual roughness.
153157
float roughness4 = roughness * roughness;
154158
roughness4 *= roughness4;
155159

@@ -165,7 +169,7 @@ void CubemapFilter::filter_radiance(GLuint p_source_cubemap, GLuint p_dest_cubem
165169
Vector3 dir = importance_sample_GGX(xi, roughness4);
166170
Vector3 light_vec = (2.0 * dir.z * dir - Vector3(0.0, 0.0, 1.0));
167171

168-
if (light_vec.z < 0.0) {
172+
if (light_vec.z <= 0.0) {
169173
continue;
170174
}
171175

0 commit comments

Comments
 (0)