From ba9b4bd5ecaf53972f89f83fc26af06c83a5397c Mon Sep 17 00:00:00 2001 From: Pascal Grittmann Date: Thu, 25 Jan 2024 19:48:46 +0100 Subject: [PATCH] clean callbacks --- .../BidirZeroLightPaths.cs | 13 ++-- SeeSharp/Integrators/Bidir/BidirBase.cs | 74 ++++--------------- 2 files changed, 23 insertions(+), 64 deletions(-) diff --git a/SeeSharp.IntegrationTests/BidirZeroLightPaths.cs b/SeeSharp.IntegrationTests/BidirZeroLightPaths.cs index 4b28935..6ab2c9f 100644 --- a/SeeSharp.IntegrationTests/BidirZeroLightPaths.cs +++ b/SeeSharp.IntegrationTests/BidirZeroLightPaths.cs @@ -1,4 +1,5 @@ using SeeSharp.Geometry; +using SeeSharp.Integrators; using SeeSharp.Integrators.Bidir; using SeeSharp.Shading.Emitters; using SimpleImageIO; @@ -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() { @@ -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); } } diff --git a/SeeSharp/Integrators/Bidir/BidirBase.cs b/SeeSharp/Integrators/Bidir/BidirBase.cs index 8a13c00..d693684 100644 --- a/SeeSharp/Integrators/Bidir/BidirBase.cs +++ b/SeeSharp/Integrators/Bidir/BidirBase.cs @@ -286,21 +286,10 @@ protected virtual void RegisterSample(RgbColor weight, float misWeight, Pixel pi /// The MIS weight that will be multiplied on the sample weight /// The pixel to which this sample contributes /// The last vertex on the light path - /// - /// Surface area pdf of sampling the last light path vertex when starting from the camera - /// - /// - /// Surface area pdf of sampling the ancestor of the last light path vertex, when starting from the - /// camera. - /// - /// - /// 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. - /// + /// Surface area pdfs of all sampling techniques. /// Distance of the last vertex to the camera 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) { } /// /// Called for each full path sample generated via next event estimation on a camera path. @@ -308,25 +297,18 @@ protected virtual void OnLightTracerSample(RgbColor weight, float misWeight, Pix /// The sample contribution not yet weighted by MIS /// The MIS weight that will be multiplied on the sample weight /// The camera path until the point where NEE was performed - /// - /// 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. - /// /// Surface area pdf used for next event estimation /// /// Surface area pdf of sampling the same light source point by continuing the path /// - /// - /// Surface area pdf of sampling the ancestor of the last camera vertex, when starting at the light - /// source. - /// + /// Surface area pdfs of all sampling techniques. /// The emitter that was connected to /// /// Direction from the point on the light to the last camera vertex. /// /// The point on the light 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) { } /// @@ -336,10 +318,7 @@ protected virtual void OnNextEventSample(RgbColor weight, float misWeight, Camer /// The sample contribution not yet weighted by MIS /// The MIS weight that will be multiplied on the sample weight /// The camera path until the point where NEE was performed - /// - /// 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. - /// + /// Surface area pdfs of all sampling techniques. /// /// Surface area pdf of sampling the same light source point via next event estimation instead. /// @@ -349,7 +328,7 @@ protected virtual void OnNextEventSample(RgbColor weight, float misWeight, Camer /// /// The point on the light 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) { } /// @@ -360,28 +339,9 @@ protected virtual void OnEmitterHitSample(RgbColor weight, float misWeight, Came /// The MIS weight that will be multiplied on the sample weight /// The camera path until the point where NEE was performed /// Last vertex of the camera sub-path that was connected to - /// - /// Surface area pdf of sampling the ancestor of the last camera vertex when continuing the light - /// sub-path instead - /// - /// - /// Surface area pdf of sampling the connecting edge by continuing the camera path instead - /// - /// - /// Surface area pdf of sampling the ancestor of the last light vertex when continuing the camera - /// sub-path instead - /// - /// - /// Surface area pdf of sampling the connecting edge by continuing the light path instead - /// - /// - /// 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 - /// + /// Surface area pdfs of all sampling techniques. 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) { } /// /// Computes the MIS weight of a light tracer sample, for example via the balance heuristic. @@ -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); } /// @@ -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; } @@ -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; } @@ -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; } } @@ -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; } @@ -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; }