Commits

David Bucciarelli committed 9ce274e

Fixed a problem in the computation of mean intensity in Metropolis sampler with user driven sampling

  • Participants
  • Parent commits 68df4b4
  • Branches pmc_test

Comments (0)

Files changed (2)

File core/film.cpp

 	}
 
 	// DEBUG: for testing the user sampling map functionality
-	/*userSamplingMap = new float[xPixelCount * yPixelCount];
+	/*userSamplingMap.reset(new float[xPixelCount * yPixelCount]);
 	for (u_int x = 0; x < xPixelCount; ++x) {
 		for (u_int y = 0; y < yPixelCount; ++y) {
 			const float xx = (x / (float)xPixelCount) - 0.5f;
 			const float yy = (y / (float)yPixelCount) - 0.5f;
 
-			userSamplingMap[x + y * xPixelCount] = (xx * xx + yy * yy < 0.25f * 0.25f) ? 1.f : 0.f;
+			userSamplingMap[x + y * xPixelCount] = (xx * xx + yy * yy < 0.25f * 0.25f) ? 1.f : 0.01f;
 		}
 	}
 	userSamplingMapVersion = 1;*/

File samplers/metrosampler.cpp

 							newTotal += data->userSamplingMap[i];
 					} else {
 						// This should never happen
-						LOG(LUX_ERROR, LUX_SYSTEM)<< "Internal error in MetropolisSampler::GetNextSample()";
+						LOG(LUX_ERROR, LUX_SYSTEM) << "Internal error in MetropolisSampler::GetNextSample()";
 					}
 				}					
 				newTotal /= nPix;
 
-				// NOTE: totalLY store the average target function value (this is usually not known but in this case, it is)
-				data->totalLY = newTotal;
+				if (useNoiseAware) {
+					// NOTE: totalLY store the average target function value (this is usually not known but in this case, it is)
+					data->totalLY = newTotal;
+				} else
+					data->totalLY = 0.0;
 				data->sampleCount = 0.f;
 				data->consecRejects = 0;
 				data->LY = 0.f;
 			} else {
 				if (data->userSamplingMapVersion > 0) {
 					const float ly = newContributions[i].color.Y();
-					const float us = data->userSamplingMap[index];
 
 					if (ly > 0.f && !isinf(ly)) {
+						const float us = data->userSamplingMap[index];
+
 						if (useVariance && newContributions[i].variance > 0.f)
 							newLY += ly * newContributions[i].variance * us;
 						else
 						newContributions[i].color = XYZColor(0.);
 				} else {
 					// This should never happen
-					LOG(LUX_ERROR, LUX_SYSTEM)<< "Internal error in MetropolisSampler::AddSample()";
+					LOG(LUX_ERROR, LUX_SYSTEM) << "Internal error in MetropolisSampler::AddSample()";
 				}
 			}
 		}
-
-		meanIntensity = data->totalLY > 0. ? data->totalLY : 1.f;
 	} else {
 		for(u_int i = 0; i < newContributions.size(); ++i) {
 			const float ly = newContributions[i].color.Y();
 			} else
 				newContributions[i].color = XYZColor(0.f);
 		}
-		
+	}
+
+	// Calculate meanIntensity. Required only for standard metropolis (and/or user
+	// sampling), it is a known quantity when noise-aware is enabled
+	if (data->noiseAwareMapVersion > 0)
+		meanIntensity = data->totalLY > 0. ? data->totalLY : 1.f;
+	else {
 		// Calculate meanIntensity. Required only for standard metropolis, it
 		// is a known quantity when noise-aware is enabled
 		if (data->large) {
 		}
 
 		meanIntensity = data->totalLY > 0. ? static_cast<float>(data->totalLY / data->sampleCount) : 1.f;
-	}
+	}	
 
 	sample.contribBuffer->AddSampleCount(1.f);