Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrit committed Jan 22, 2024
1 parent 10411b3 commit aafa5b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions SeeSharp/Integrators/Bidir/BidirBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public struct CameraPath {
/// Roughness of the material at the currently last vertex of the path.
/// </summary>
public float CurrentRoughness;

public int Depth => Vertices.Count;
}

/// <summary>
Expand Down
17 changes: 16 additions & 1 deletion SeeSharp/Integrators/Bidir/VertexConnectionAndMerging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ protected override void OnAfterRender() {
Scene.FrameBuffer.MetaData["AverageCameraPathLength"] = AverageCameraPathLength;
Scene.FrameBuffer.MetaData["AverageLightPathLength"] = AverageLightPathLength;
Scene.FrameBuffer.MetaData["AveragePhotonsPerQuery"] = AveragePhotonsPerQuery;
Scene.FrameBuffer.MetaData["MergeAccelBuildTime"] = mergeBuildTimer.ElapsedMilliseconds;
}

protected override void OnBeforeRender() {
base.OnBeforeRender();
mergeBuildTimer = new();
}

protected override void OnStartIteration(uint iteration) {
Expand All @@ -137,7 +143,9 @@ protected override void OnCameraPathTerminate(CameraPath path)

private float ComputeAverageLightPathLength() {
float average = 0;
if (LightPaths == null) return 0;
if (LightPaths == null)
return 0;

for (int i = 0; i < LightPaths.NumPaths; ++i) {
int length = LightPaths.PathCache.Length(i);
average = (length + i * average) / (i + 1);
Expand Down Expand Up @@ -186,13 +194,17 @@ public override void Render(Scene scene) {
photonMap = null;
}

Stopwatch mergeBuildTimer;

/// <summary>
/// Generates the acceleration structure for merging
/// </summary>
protected override void ProcessPathCache() {
base.ProcessPathCache();

if (EnableMerging) {
mergeBuildTimer.Start();

photonMap.Clear();
for (int i = 0; i < LightPaths.PathCache.NumVertices; ++i) {
var vertex = LightPaths.PathCache[i];
Expand All @@ -201,6 +213,8 @@ protected override void ProcessPathCache() {
}
}
photonMap.Build();

mergeBuildTimer.Stop();
}
}

Expand Down Expand Up @@ -307,6 +321,7 @@ protected virtual float ComputeLocalMergeRadius(float primaryDistance) {
protected virtual RgbColor PerformMerging(SurfaceShader shader, RNG rng, CameraPath path, float cameraJacobian) {
if (path.Vertices.Count == 1 && !MergePrimary) return RgbColor.Black;
if (!EnableMerging) return RgbColor.Black;
if (!MergePrimary && path.Depth == 1) return RgbColor.Black;
float localRadius = ComputeLocalMergeRadius(path.Distances[0]);

RgbColor estimate = RgbColor.Black;
Expand Down
5 changes: 4 additions & 1 deletion SeeSharp/Integrators/Common/PathCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public void Prepare() {
this.overflow += overflow;
totalUnused += unused;
}
threadCaches.Values.Clear();

// TODO compact the holes after flushing incomplete caches
}

Expand Down Expand Up @@ -124,7 +126,8 @@ class ThreadCache {
int overflow = next - (vertices.Length - insertPos);
if (overflow > 0) next -= overflow;

Array.ConstrainedCopy(batch, 0, vertices, insertPos, next);
if (next > 0)
Array.ConstrainedCopy(batch, 0, vertices, insertPos, next);

// For uncompleted batches, add a guard
int unused = overflow > 0 ? 0 : (BatchSize - next);
Expand Down

0 comments on commit aafa5b8

Please sign in to comment.