I've decided to ditch the the lightmapping library I was using previously, since it ran unbelievably slowly and it had some strange artifacts that I didn't want to deal with. In it's place, I've just gone with integrating embree and doing ray-tracing on the CPU. The basic procedure for what I'm doing so far is this:
direct_buff is a black image
for each texel in the lightmap:
Cast a ray originating from the texel, in the direction of the directional light source
if the ray was not occluded:
influence = max(dot(light_dir, texel_norm), 0)
direct_buff[texel] = influence * light_color
endif
endfor
indirect_buff = copy(direct_buff)
for each texel in the lightmap:
Compute a TBN matrix for this texel
Create 128 random unit vectors on the hemisphere represented by the TBN matrix
Cast a ray originating from the texel, in the direction of each vector
for each ray that hit something:
Sample albedo value stored at the hit coordinate
Sample direct lighting value stored at the hit coordinate
influence = dot(ray_dir, texel_norm) / (distance * distance)
indirect_buff[texel] += influence * albedo * direct
endfor
endfor
return indirect_buff
It's not ideal, since I'm using a physically based rendering pipeline but this has no consideration for any of the usual PBR stuff, other than albedo. However, as long as it looks decent I'm fine with it.
So I whipped up a simple scene similar to the Cornell Box, when unlit it looks like this:
Computing just the direct lighting value (with the light source outside the box) and multiplying with albedo, I get this:
Ok, looks pretty good. Then as a test, I output just the indirect influence (not multiplying by albedo, also greatly reducing brightness):
Makes sense, I think. Surfaces that are close to other surfaces get more indirect ray hits and influence than those that aren't. Should it be that bright around the corners though? I'm not sure...
Anyway, here's what it looks like with the final output terms (and multiplying by albedo):
Ehh, yeah that doesn't look quite right. Why is there such an insane amount of light in the corners, even where there's no direct lighting? I'm getting some nice color bleeding from the red wall onto the left cube, but that doesn't distract from the rest of it. Here's another shot, taken from behind the right box:
Yeah, there definitely shouldn't be that much light there. I'll check my math, but if anyone could give me any tips for where I might be going wrong, I'd appreciate it. I can post the code, but it's pretty gross at the moment.
Thanks!