## Fireflies in pathtracer

Practical and theoretical implementation discussion.
KaRaMBa
Posts: 2
Joined: Tue Apr 17, 2012 1:03 pm
Location: Netherlands

### Fireflies in pathtracer

Hi!

I'm currently working on a basic path tracer. Recently I added next event estimation for emissive surfaces (ie. direct sampling of lights). Now, if a small but powerful light source is near a diffuse surface, I get 'fireflies' all through my rendering. This effect can be seen in this image (rendered with 64 samples per pixel):

What can I do to reduce this noise? MIS reduces high variance noise in scenes with shiny surfaces, but would it also help in a completely diffuse scene like this?

Posts: 206
Joined: Fri Dec 02, 2011 8:00 am

### Re: Fireflies in pathtracer

KaRaMBa wrote: MIS reduces high variance noise in scenes with shiny surfaces, but would it also help in a completely diffuse scene like this?
Yup, it does, your fireflies are likely to be caused by paths directly hitting a very near light source. If you lower the light sources in your scene, you will see how the fireflies will disappear.

ingenious
Posts: 282
Joined: Mon Nov 28, 2011 11:11 pm
Location: London, UK
Contact:

### Re: Fireflies in pathtracer

Unfortunately, in a basic path tracer there's little you can to about this problem. Bidirectional methods, e.g. bidirectional path tracing or VPL methods, perform better in such conditions, as they sample these firefly-causing paths with higher probability.

KaRaMBa
Posts: 2
Joined: Tue Apr 17, 2012 1:03 pm
Location: Netherlands

### Re: Fireflies in pathtracer

KaRaMBa wrote: MIS reduces high variance noise in scenes with shiny surfaces, but would it also help in a completely diffuse scene like this?
Yup, it does, your fireflies are likely to be caused by paths directly hitting a very near light source. If you lower the light sources in your scene, you will see how the fireflies will disappear.
My path tracer takes a similar aproach for direct sampling of lights as the (extended) smallpt pathtracer:
- If a ray hits a diffuse surface, a random point on a random light is picked and a shadow ray is send. If the lightsource is visible, the appropriate amount of light is added
- Next, a random diffuse ray is send into the scene to add indirect lighting, and directly hitting lightsources is disabled

This gives nice noise-free results within very little samples, if the lightlevel is below 1.0. However, more intense lights are required to sufficently light the scene.

If I move the lightsource down, such that the bright area on te ceiling is less bright, my fireflies also reduce drasticly. I susspect a random diffuce ray hitting the very bright diffuse area above the lightsource, is the cause of my fireflies... (N.B. this is similar to the discussion on the second page of this topic: viewtopic.php?f=3&t=5)

Since i disable the hitting of lightsources after a diffuse bounce, how would MIS solve this issue? As I understand, MIS only solves variance introduced by hitting lightsources with the an unlikely chance (which isn't possible in my case)? And if I didn't understand MIS correct, how would I implement MIS in my case (what probablilites should I mix)?

I've added a snipset (pseudocode) of my tracer:

Code: Select all

COLOR pathTracer(const KDTREE *world, POINT *pt, POINT *dir)
{
COLOR colscale = {1.0f, 1.0f, 1.0f};
COLOR ret = {0.0f, 0.0f, 0.0f};

int depth = 0, allowlight = 1;

while(1)
{
if(depth>15) break;

IXPT *ixpt = findIntersectPt(world, pt, dir);		// Intersection point ixpt contains information about hit: face, hitpoint, etc

if(!ixpt)	// nothing hit, add sky-light
{
ret += skyColor(dir) * colscale;

return ret;
}

POINT norm = getFaceNormalAtPoint(ixpt);

if(ixpt->face.emit)
{
if(allowlight)
ret += ixpt->face.color * colscale * ixpt->face.emit;

return ret;
}
else // diffuse hit
{
// Directly sample light
POINT newdir;
COLOR lightColor;

const tReal pdf = sampleLight(dir, ixpt->pt, &norm, &newdir, &lightColor);
const tReal brdf = brdf_Lambert(dir, ixpt->pt, &norm, &newdir);
const tReal scale = brdf / pdf;

if(!findObscured(world, &ixpt->pt, &newdir))
ret += ixpt->face.color * lightColor * colscale * scale;

allowlight = 0;	// directly sampled lights, so exclude them from being hit accidentally

// Now do a diffuce bounce for indirect lightning
static const tReal Prr = 0.9;

if(sample()<Prr)
{
const tReal pdf = sampleVectorCosweighted(dir, ixpt->pt, &norm, &newdir);
const tReal brdf = brdf_Lambert(dir, ixpt->pt, &norm, &newdir);
const tReal scale = brdf / (pdf * Prr);

if(scale > REL_EPSYLON)
{
colscale *= matcol * scale;

*pt = ixpt->pt;
*dir = newdir;
depth++;

continue;
}
}

return ret;
}
}
}


igneus
Posts: 5
Joined: Wed Mar 28, 2012 3:16 pm
Location: United Kingdom
Contact:

### Re: Fireflies in pathtracer

This isn't a perfect fix, but you might be interested in this paper which uses outlier rejection to remove fireflies. It's a sample space filtering technique so you don't get the same smudgy artefacts as with some methods. Also, the energy that's removed by the filtering can be cached and added back in later when more samples are taken.

beason
Posts: 52
Joined: Sat Dec 10, 2011 1:58 am
Location: Los Angeles, CA

### Re: Fireflies in pathtracer

I don't think MIS will help you. I second the bidirectional approach, but metropolis sampling may help also. The problem is how to send more rays to those secondary bright spots.

apaffy
Posts: 46
Joined: Thu Dec 01, 2011 11:00 pm
Location: UK
Contact:

### Re: Fireflies in pathtracer

Yep the fireflies will be from BSDF sampling to extend the path hitting one of these areas that are very brightly directly lit.

The only way to reduce the fireflies is to find paths through these bright areas with higher probability, which is exactly what light subpaths (in a bidirectional path tracer) will do for you.