Skip to content

Commit

Permalink
fix bidir seed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrit committed Aug 28, 2024
1 parent b5a49e0 commit 19d301f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
3 changes: 1 addition & 2 deletions SeeSharp/Integrators/Bidir/BidirBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public override void Render(Scene scene) {

ProgressBar progressBar = new(prefix: "Rendering...");
progressBar.Start(NumIterations);
RNG camSeedGen = new(BaseSeedCamera);
RenderTimer timer = new();
Stopwatch lightTracerTimer = new();
Stopwatch pathTracerTimer = new();
Expand All @@ -211,7 +210,7 @@ public override void Render(Scene scene) {
LightPaths.NumPaths = NumLightPaths.Value;

lightTracerTimer.Start();
LightPaths.TraceAllPaths(iter,
LightPaths.TraceAllPaths(BaseSeedLight, iter,
(origin, primary, nextDirection) => NextEventPdf(primary, origin));
ProcessPathCache();
lightTracerTimer.Stop();
Expand Down
11 changes: 3 additions & 8 deletions SeeSharp/Integrators/Bidir/LightPathCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ public class LightPathCache {
/// </summary>
public int MaxDepth;

/// <summary>
/// Seed that is hashed with the iteration and path index to generate a random number sequence
/// for each light path.
/// </summary>
public uint BaseSeed = 0xC030114u;

/// <summary>
/// The scene that is being rendered
/// </summary>
Expand Down Expand Up @@ -124,11 +118,12 @@ public virtual (Ray, RgbColor, float) SampleBackground(ref RNG rng) {
/// <summary>
/// Resets the path cache and populates it with a new set of light paths.
/// </summary>
/// <param name="seed">Base seed for the random number generator, hashed with the iteration to obtain the actual seed.</param>
/// <param name="iter">Index of the current iteration, used to seed the random number generator.</param>
/// <param name="nextEventPdfCallback">
/// Delegate that is invoked to compute the next event sampling density
/// </param>
public virtual void TraceAllPaths(uint iter, LightPathWalk.NextEventPdfCallback nextEventPdfCallback) {
public virtual void TraceAllPaths(uint seed, uint iter, LightPathWalk.NextEventPdfCallback nextEventPdfCallback) {
if (PathCache == null)
PathCache = new PathCache(NumPaths, Math.Min(MaxDepth + 1, 10));
else if (NumPaths != PathCache.NumPaths) {
Expand All @@ -141,7 +136,7 @@ public virtual void TraceAllPaths(uint iter, LightPathWalk.NextEventPdfCallback
LightPathWalk walkModifier = new(PathCache, nextEventPdfCallback);

Parallel.For(0, NumPaths, idx => {
var rng = new RNG(BaseSeed, (uint)idx, iter);
var rng = new RNG(seed, (uint)idx, iter);
TraceLightPath(ref rng, idx, walkModifier);
});

Expand Down
3 changes: 1 addition & 2 deletions SeeSharp/Integrators/Bidir/PhotonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ public override void Render(Scene scene) {
MaxDepth = MaxDepth,
NumPaths = NumLightPaths,
Scene = scene,
BaseSeed = BaseSeedLight
};

if (photonMap == null) photonMap = new();

for (uint iter = 0; iter < NumIterations; ++iter) {
scene.FrameBuffer.StartIteration();
lightPaths.TraceAllPaths(iter, null);
lightPaths.TraceAllPaths(BaseSeedLight, iter, null);
ProcessPathCache();
TraceAllCameraPaths(iter);
scene.FrameBuffer.EndIteration();
Expand Down

0 comments on commit 19d301f

Please sign in to comment.