[Bf-blender-cvs] [581c819013] master: Cycles: Fix wrong shading on GPU when background has NaN pixels and MIS enabled
Sergey Sharybin
noreply at git.blender.org
Mon Feb 13 16:33:44 CET 2017
Commit: 581c81901363176b1ce775472ea7c9f97ee504a9
Author: Sergey Sharybin
Date: Mon Feb 13 16:30:16 2017 +0100
Branches: master
https://developer.blender.org/rB581c81901363176b1ce775472ea7c9f97ee504a9
Cycles: Fix wrong shading on GPU when background has NaN pixels and MIS enabled
Quite simple fix for now which only deals with this case. Maybe we want to do
some "clipping" on image load time so regular textures wouldn't give NaN as
well.
===================================================================
M intern/cycles/render/light.cpp
===================================================================
diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp
index 2245c861d5..6a4557506c 100644
--- a/intern/cycles/render/light.cpp
+++ b/intern/cycles/render/light.cpp
@@ -486,10 +486,18 @@ static void background_cdf(int start,
float2 *cond_cdf)
{
/* Conditional CDFs (rows, U direction). */
+ /* NOTE: It is possible to have some NaN pixels on background
+ * which will ruin CDF causing wrong shading. We replace such
+ * pixels with black.
+ */
for(int i = start; i < end; i++) {
float sin_theta = sinf(M_PI_F * (i + 0.5f) / res);
float3 env_color = (*pixels)[i * res];
float ave_luminance = average(env_color);
+ /* TODO(sergey): Consider adding average_safe(). */
+ if(!isfinite(ave_luminance)) {
+ ave_luminance = 0.0f;
+ }
cond_cdf[i * cdf_count].x = ave_luminance * sin_theta;
cond_cdf[i * cdf_count].y = 0.0f;
@@ -497,6 +505,9 @@ static void background_cdf(int start,
for(int j = 1; j < res; j++) {
env_color = (*pixels)[i * res + j];
ave_luminance = average(env_color);
+ if(!isfinite(ave_luminance)) {
+ ave_luminance = 0.0f;
+ }
cond_cdf[i * cdf_count + j].x = ave_luminance * sin_theta;
cond_cdf[i * cdf_count + j].y = cond_cdf[i * cdf_count + j - 1].y + cond_cdf[i * cdf_count + j - 1].x / res;
More information about the Bf-blender-cvs
mailing list