Skip to content

Commit

Permalink
firefly reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
fogleman committed Sep 6, 2016
1 parent c57edd9 commit e8db9ef
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pt/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func render(scene *Scene, camera *Camera, sampler Sampler, samplesPerPixel int,
}
}
}
// adaptive sampling
v := Clamp(buf.StandardDeviation(x, y).MaxComponent(), 0, 1)
v = math.Pow(v, 2)
extraSamples := int(32 * v)
Expand All @@ -73,6 +74,16 @@ func render(scene *Scene, camera *Camera, sampler Sampler, samplesPerPixel int,
sample := sampler.Sample(scene, ray, rnd)
buf.AddSample(x, y, sample)
}
// firefly reduction
if buf.StandardDeviation(x, y).MaxComponent() > 1 {
for i := 0; i < 256; i++ {
fu := rnd.Float64()
fv := rnd.Float64()
ray := camera.CastRay(x, y, w, h, fu, fv, rnd)
sample := sampler.Sample(scene, ray, rnd)
buf.AddSample(x, y, sample)
}
}
}
ch <- 1
}
Expand Down

0 comments on commit e8db9ef

Please sign in to comment.