Skip to content

Commit

Permalink
fix mis
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrit committed Apr 2, 2024
1 parent 804b83c commit d044c6f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions SeeSharp/Integrators/Bidir/BidirBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ RgbColor Connect(in SurfaceShader shader, PathVertex vertex, PathVertex ancestor

RgbColor weight = vertex.Weight * bsdfWeightLight * bsdfWeightCam / distanceSqr / lightVertexProb;

Debug.Assert(float.IsFinite(weight.Average));
Debug.Assert(float.IsFinite(misWeight));

RegisterSample(weight * path.Throughput, misWeight, path.Pixel,
path.Vertices.Count, vertex.Depth, depth);
OnBidirConnectSample(weight * path.Throughput, misWeight, path, vertex, pathPdfs);
Expand Down
6 changes: 4 additions & 2 deletions SeeSharp/Integrators/Bidir/ClassicBidir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public override float BidirConnectMis(in CameraPath cameraPath, PathVertex light
int lastCameraVertexIdx = cameraPath.Vertices.Count - 1;
sumReciprocals += CameraPathReciprocals(lastCameraVertexIdx, pathPdfs, cameraPath.Pixel);
sumReciprocals += LightPathReciprocals(lastCameraVertexIdx, pathPdfs, cameraPath.Pixel);
Debug.Assert(float.IsFinite(sumReciprocals));
return 1 / sumReciprocals;
}

Expand Down Expand Up @@ -182,12 +183,13 @@ protected virtual float LightPathReciprocals(int lastCameraVertexIdx, in BidirPa
float sumReciprocals = 0.0f;
float nextReciprocal = 1.0f;
for (int i = lastCameraVertexIdx + 1; i < pdfs.NumPdfs; ++i) {
if (i == pdfs.NumPdfs - 1) // Next event
sumReciprocals += nextReciprocal * pdfs.PdfNextEvent / pdfs.PdfsLightToCamera[i];
nextReciprocal *= pdfs.PdfsCameraToLight[i] / pdfs.PdfsLightToCamera[i];
if (EnableConnections && i < pdfs.NumPdfs - 2) // Next event is treated separately
if (EnableConnections && i < pdfs.NumPdfs - 2) // Connections
sumReciprocals += nextReciprocal;
}
sumReciprocals += nextReciprocal; // Hitting the emitter directly
sumReciprocals += pdfs.PdfNextEvent * nextReciprocal / pdfs.PdfsCameraToLight[^1];
return sumReciprocals;
}
}
3 changes: 2 additions & 1 deletion SeeSharp/Integrators/Bidir/VertexCacheBidir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,13 @@ protected virtual float LightPathReciprocals(int lastCameraVertexIdx, in BidirPa
float sumReciprocals = 0.0f;
float nextReciprocal = 1.0f;
for (int i = lastCameraVertexIdx + 1; i < pdfs.NumPdfs; ++i) {
if (i == pdfs.NumPdfs - 1) // Next event
sumReciprocals += nextReciprocal * pdfs.PdfNextEvent / pdfs.PdfsLightToCamera[i];
nextReciprocal *= pdfs.PdfsCameraToLight[i] / pdfs.PdfsLightToCamera[i];
if (i < pdfs.NumPdfs - 2 && NumConnections > 0) // Connections to the emitter (next event) are treated separately
sumReciprocals += nextReciprocal * BidirSelectDensity(pixel);
}
if (EnableHitting) sumReciprocals += nextReciprocal; // Hitting the emitter directly
sumReciprocals += pdfs.PdfNextEvent * nextReciprocal / pdfs.PdfsCameraToLight[^1];
return sumReciprocals;
}
}
4 changes: 3 additions & 1 deletion SeeSharp/Integrators/Bidir/VertexConnectionAndMerging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ protected virtual float LightPathReciprocals(int lastCameraVertexIdx, in BidirPa
float sumReciprocals = 0.0f;
float nextReciprocal = 1.0f;
for (int i = lastCameraVertexIdx + 1; i < pdfs.NumPdfs; ++i) {
if (i == pdfs.NumPdfs - 1) // Next event
sumReciprocals += nextReciprocal * pdfs.PdfNextEvent / pdfs.PdfsLightToCamera[i];

if (i < pdfs.NumPdfs - 1 && (MergePrimary || i > 0)) { // no merging on the emitter itself
// Account for merging at this vertex
if (EnableMerging) {
Expand All @@ -617,7 +620,6 @@ protected virtual float LightPathReciprocals(int lastCameraVertexIdx, in BidirPa
if (NumConnections > 0) sumReciprocals += nextReciprocal * BidirSelectDensity(pixel);
}
if (EnableHitting) sumReciprocals += nextReciprocal; // Hitting the emitter directly
sumReciprocals += pdfs.PdfNextEvent * nextReciprocal / pdfs.PdfsCameraToLight[^1];
return sumReciprocals;
}
}

0 comments on commit d044c6f

Please sign in to comment.