Skip to content

Commit

Permalink
clean callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrit committed Jan 25, 2024
1 parent 05b81e1 commit ba9b4bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 64 deletions.
13 changes: 7 additions & 6 deletions SeeSharp.IntegrationTests/BidirZeroLightPaths.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SeeSharp.Geometry;
using SeeSharp.Integrators;
using SeeSharp.Integrators.Bidir;
using SeeSharp.Shading.Emitters;
using SimpleImageIO;
Expand All @@ -12,16 +13,16 @@ protected override void OnStartIteration(uint iteration) {
LightPaths.NumPaths = 0;
}

protected override void OnNextEventSample(RgbColor weight, float misWeight, CameraPath cameraPath, float pdfEmit, float pdfNextEvent, float pdfHit, float pdfReverse, Emitter emitter, Vector3 lightToSurface, SurfacePoint lightPoint) {
protected override void OnNextEventSample(RgbColor weight, float misWeight, CameraPath cameraPath, float pdfNextEvent, float pdfHit, in BidirPathPdfs pathPdfs, Emitter emitter, Vector3 lightToSurface, SurfacePoint lightPoint) {
Debug.Assert(float.IsFinite(misWeight));
}
}

static class BidirZeroLightPaths {
public static void Run() {
var scene = SeeSharp.Scene.LoadFromFile("Data/Scenes/CornellBox/CornellBox.json");
scene.FrameBuffer = new SeeSharp.Images.FrameBuffer(512, 512, "test.exr",
SeeSharp.Images.FrameBuffer.Flags.SendToTev);
var scene = Scene.LoadFromFile("Data/Scenes/CornellBox/CornellBox.json");
scene.FrameBuffer = new Images.FrameBuffer(512, 512, "test.exr",
Images.FrameBuffer.Flags.SendToTev);
scene.Prepare();

var integrator = new Dummy() {
Expand All @@ -30,8 +31,8 @@ public static void Run() {
};
integrator.Render(scene);

scene.FrameBuffer = new SeeSharp.Images.FrameBuffer(512, 512, "test.exr",
SeeSharp.Images.FrameBuffer.Flags.SendToTev);
scene.FrameBuffer = new Images.FrameBuffer(512, 512, "test.exr",
Images.FrameBuffer.Flags.SendToTev);
integrator.Render(scene);
}
}
Expand Down
74 changes: 16 additions & 58 deletions SeeSharp/Integrators/Bidir/BidirBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,47 +286,29 @@ protected virtual void RegisterSample(RgbColor weight, float misWeight, Pixel pi
/// <param name="misWeight">The MIS weight that will be multiplied on the sample weight</param>
/// <param name="pixel">The pixel to which this sample contributes</param>
/// <param name="lightVertex">The last vertex on the light path</param>
/// <param name="pdfCamToPrimary">
/// Surface area pdf of sampling the last light path vertex when starting from the camera
/// </param>
/// <param name="pdfReverse">
/// Surface area pdf of sampling the ancestor of the last light path vertex, when starting from the
/// camera.
/// </param>
/// <param name="pdfNextEvent">
/// Surface area pdf of sampling the ancestor of the last light path vertex via next event estimation.
/// Will be zero unless this is a direct illumination sample.
/// </param>
/// <param name="pathPdfs">Surface area pdfs of all sampling techniques. </param>
/// <param name="distToCam">Distance of the last vertex to the camera</param>
protected virtual void OnLightTracerSample(RgbColor weight, float misWeight, Pixel pixel,
PathVertex lightVertex, float pdfCamToPrimary, float pdfReverse,
float pdfNextEvent, float distToCam) { }
PathVertex lightVertex, in BidirPathPdfs pathPdfs, float distToCam) { }

/// <summary>
/// Called for each full path sample generated via next event estimation on a camera path.
/// </summary>
/// <param name="weight">The sample contribution not yet weighted by MIS</param>
/// <param name="misWeight">The MIS weight that will be multiplied on the sample weight</param>
/// <param name="cameraPath">The camera path until the point where NEE was performed</param>
/// <param name="pdfEmit">
/// Surface area pdf of sampling the last camera vertex when starting at the light source.
/// This also includes the pdf of sampling the point on the light during emission.
/// </param>
/// <param name="pdfNextEvent">Surface area pdf used for next event estimation</param>
/// <param name="pdfHit">
/// Surface area pdf of sampling the same light source point by continuing the path
/// </param>
/// <param name="pdfReverse">
/// Surface area pdf of sampling the ancestor of the last camera vertex, when starting at the light
/// source.
/// </param>
/// <param name="pathPdfs">Surface area pdfs of all sampling techniques. </param>
/// <param name="emitter">The emitter that was connected to</param>
/// <param name="lightToSurface">
/// Direction from the point on the light to the last camera vertex.
/// </param>
/// <param name="lightPoint">The point on the light</param>
protected virtual void OnNextEventSample(RgbColor weight, float misWeight, CameraPath cameraPath,
float pdfEmit, float pdfNextEvent, float pdfHit, float pdfReverse,
float pdfNextEvent, float pdfHit, in BidirPathPdfs pathPdfs,
Emitter emitter, Vector3 lightToSurface, SurfacePoint lightPoint) { }

/// <summary>
Expand All @@ -336,10 +318,7 @@ protected virtual void OnNextEventSample(RgbColor weight, float misWeight, Camer
/// <param name="weight">The sample contribution not yet weighted by MIS</param>
/// <param name="misWeight">The MIS weight that will be multiplied on the sample weight</param>
/// <param name="cameraPath">The camera path until the point where NEE was performed</param>
/// <param name="pdfEmit">
/// Surface area pdf of sampling the last camera vertex when starting at the light source.
/// This also includes the pdf of sampling the point on the light during emission.
/// </param>
/// <param name="pathPdfs">Surface area pdfs of all sampling techniques. </param>
/// <param name="pdfNextEvent">
/// Surface area pdf of sampling the same light source point via next event estimation instead.
/// </param>
Expand All @@ -349,7 +328,7 @@ protected virtual void OnNextEventSample(RgbColor weight, float misWeight, Camer
/// </param>
/// <param name="lightPoint">The point on the light</param>
protected virtual void OnEmitterHitSample(RgbColor weight, float misWeight, CameraPath cameraPath,
float pdfEmit, float pdfNextEvent, Emitter emitter,
float pdfNextEvent, in BidirPathPdfs pathPdfs, Emitter emitter,
Vector3 lightToSurface, SurfacePoint lightPoint) { }

/// <summary>
Expand All @@ -360,28 +339,9 @@ protected virtual void OnEmitterHitSample(RgbColor weight, float misWeight, Came
/// <param name="misWeight">The MIS weight that will be multiplied on the sample weight</param>
/// <param name="cameraPath">The camera path until the point where NEE was performed</param>
/// <param name="lightVertex">Last vertex of the camera sub-path that was connected to</param>
/// <param name="pdfCameraReverse">
/// Surface area pdf of sampling the ancestor of the last camera vertex when continuing the light
/// sub-path instead
/// </param>
/// <param name="pdfCameraToLight">
/// Surface area pdf of sampling the connecting edge by continuing the camera path instead
/// </param>
/// <param name="pdfLightReverse">
/// Surface area pdf of sampling the ancestor of the last light vertex when continuing the camera
/// sub-path instead
/// </param>
/// <param name="pdfLightToCamera">
/// Surface area pdf of sampling the connecting edge by continuing the light path instead
/// </param>
/// <param name="pdfNextEvent">
/// Zero if the light sub-path has more than one edge. Otherwise, the surface area pdf of sampling
/// that edge via next event estimation from the camera instead
/// </param>
/// <param name="pathPdfs">Surface area pdfs of all sampling techniques. </param>
protected virtual void OnBidirConnectSample(RgbColor weight, float misWeight, CameraPath cameraPath,
PathVertex lightVertex, float pdfCameraReverse,
float pdfCameraToLight, float pdfLightReverse,
float pdfLightToCamera, float pdfNextEvent) { }
PathVertex lightVertex, in BidirPathPdfs pathPdfs) { }

/// <summary>
/// Computes the MIS weight of a light tracer sample, for example via the balance heuristic.
Expand Down Expand Up @@ -451,8 +411,7 @@ void ConnectLightVertexToCamera(in PathVertex vertex, in PathVertex ancestor, Ve

// Log the sample
RegisterSample(weight, misWeight, response.Pixel, 0, vertex.Depth, vertex.Depth + 1);
OnLightTracerSample(weight, misWeight, response.Pixel, vertex, response.PdfEmit, pdfReverse,
pdfNextEvent, distToCam);
OnLightTracerSample(weight, misWeight, response.Pixel, vertex, pathPdfs, distToCam);
}

/// <summary>
Expand Down Expand Up @@ -553,8 +512,7 @@ RgbColor Connect(in SurfaceShader shader, PathVertex vertex, PathVertex ancestor

RegisterSample(weight * path.Throughput, misWeight, path.Pixel,
path.Vertices.Count, vertex.Depth, depth);
OnBidirConnectSample(weight * path.Throughput, misWeight, path, vertex, pdfCameraReverse,
pdfCameraToLight, pdfLightReverse, pdfLightToCamera, pdfNextEvent);
OnBidirConnectSample(weight * path.Throughput, misWeight, path, vertex, pathPdfs);

return misWeight * weight;
}
Expand Down Expand Up @@ -712,8 +670,8 @@ protected virtual RgbColor PerformNextEventEstimation(in SurfaceShader shader, r
var weight = sample.Weight * bsdfTimesCosine;
RegisterSample(weight * path.Throughput, misWeight, path.Pixel,
path.Vertices.Count, 0, path.Vertices.Count + 1);
OnNextEventSample(weight * path.Throughput, misWeight, path, pdfEmit, sample.Pdf,
bsdfForwardPdf, bsdfReversePdf, null, -sample.Direction,
OnNextEventSample(weight * path.Throughput, misWeight, path, sample.Pdf,
bsdfForwardPdf, pathPdfs, null, -sample.Direction,
new() { Position = shader.Point.Position });
return misWeight * weight;
}
Expand Down Expand Up @@ -763,8 +721,8 @@ protected virtual RgbColor PerformNextEventEstimation(in SurfaceShader shader, r
var weight = emission * bsdfTimesCosine * (jacobian / lightSample.Pdf);
RegisterSample(weight * path.Throughput, misWeight, path.Pixel,
path.Vertices.Count, 0, path.Vertices.Count + 1);
OnNextEventSample(weight * path.Throughput, misWeight, path, pdfEmit, lightSample.Pdf,
bsdfForwardPdf, bsdfReversePdf, light, lightToSurface, lightSample.Point);
OnNextEventSample(weight * path.Throughput, misWeight, path, lightSample.Pdf,
bsdfForwardPdf, pathPdfs, light, lightToSurface, lightSample.Point);
return misWeight * weight;
}
}
Expand Down Expand Up @@ -813,7 +771,7 @@ protected virtual RgbColor OnEmitterHit(Emitter emitter, SurfacePoint hit, Vecto
float misWeight = numPdfs == 1 ? 1.0f : EmitterHitMis(path, pdfNextEvent, pathPdfs);
RegisterSample(emission * path.Throughput, misWeight, path.Pixel,
path.Vertices.Count, 0, path.Vertices.Count);
OnEmitterHitSample(emission * path.Throughput, misWeight, path, pdfEmit, pdfNextEvent, emitter, outDir, hit);
OnEmitterHitSample(emission * path.Throughput, misWeight, path, pdfNextEvent, pathPdfs, emitter, outDir, hit);
return misWeight * emission;
}

Expand Down Expand Up @@ -848,7 +806,7 @@ protected virtual RgbColor OnBackgroundHit(Ray ray, in CameraPath path) {
var emission = Scene.Background.EmittedRadiance(ray.Direction);
RegisterSample(emission * path.Throughput, misWeight, path.Pixel,
path.Vertices.Count, 0, path.Vertices.Count);
OnEmitterHitSample(emission * path.Throughput, misWeight, path, pdfEmit, pdfNextEvent, null,
OnEmitterHitSample(emission * path.Throughput, misWeight, path, pdfNextEvent, pathPdfs, null,
-ray.Direction, new() { Position = ray.Origin });
return misWeight * emission * path.Throughput;
}
Expand Down

0 comments on commit ba9b4bd

Please sign in to comment.