Skip to content

Commit

Permalink
Improve the look of radiance map in Compatibility backend
Browse files Browse the repository at this point in the history
  • Loading branch information
clayjohn committed Sep 29, 2024
1 parent 1fc8208 commit 4f67415
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions drivers/gles3/effects/cubemap_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down

0 comments on commit 4f67415

Please sign in to comment.