Page 1 of 1

Recursive indirect lighting

Posted: Wed Apr 14, 2021 7:58 pm
by olliej
So I was playing around with global illumination by having my lighting function accumulate ambient light by selecting a random ray from the point of collision, and sampling the collision, then repeating that "recursively" (in a accumulating loop), and to me intuitively this should handle caustics, but it isn't and then to make matters more confusing I'm getting a halo around the reflective sphere:

[img]https://i.imgur.com/Mdzg2wJ.png[/img]

The basic loop is:
[code]
var ambient = Vector(1,1,1)
var throughput : Float = 1
var frag = fragment
while throughput > unsafeRandom(min: 0, max: 1) {
let origin = frag.position
let testDir = cosineSample(about: frag.normal)
guard let (colour, _, fr) = scene.intersect(ray: Ray(origin: origin + frag.normal * 0.001, direction: testDir, near: 0.001, far: Float.infinity), depth: 0, configuration: config, ignoreLights: true) else {
break
}
guard let f = fr else {
break
}
frag = f
let max = colour.maxElement()
if max == 0 {
break
}
throughput *= max * 0.999
ambient = ambient * colour / max
}
return (Colour(vector:ambient), nil)
[/code]


Which is essentially a bastardization of what I previously did in a photon map implementation

Re: Recursive indirect lighting

Posted: Sat Apr 17, 2021 10:57 pm
by olliej
I realized that I needed to actually account for the fall off, due to accumulation through the process, vs. photon mapping where you only record the final location.