Direct/Indirect Irradiance Sampling

Started by
4 comments, last by Max_Payne 18 years ago
Still working on my path tracer... I'm wondering, for correctness... How are the samples usually weighed. I used to have direct and indirect samples quadratically attenuated (using the distance from the source). But apparently, that's not so accurate, it resulted in some strange artifacts... So I completely removed quadratic attenuation, but then, in my cornell box test, the floor looks too bright. So I'm wondering, what's the "proper" way to do it? Since I give any light source the same number of samples by default (no matter its size), would it be fair to say that direct lighting should be quadratically attenuated (father light sources should be "smaller"), but that indirect lighting should not be quadratically attenuated (naturally receive less samples since they naturally appear smaller in the unit hemisphere as they are farther).

Looking for a serious game project?
www.xgameproject.com
Advertisement
You don't want to use a pure quadratic attenuation factor such as 1/x2, because objects less than 1 unit away from the light source will receive more light than the source emits, and if you're 0 units away from the source than you'll receive an infinite amount of light! OpenGL solves this by allowing you to provide quadratic, linear, and constant attenuation for each light. For instance, an object that's 0 units away from the light should have no attenuation, and it should fall off quadratically from there. This can be modeled as a function of distance using 1/((x+1)2) as the attenuation factor. This expands to 1/(x2 + 2x + 1). In OpenGL, the quadratic attenuation would be 1, the linear attenuation would be 2, and the constant attenuation would be 1.

I'm not really clear on your size analogy, but you should treat each sample as an independent light source and perform attenuation on all of them.
Quote:Original post by Zipster
This can be modeled as a function of distance using 1/((x+1)2) as the attenuation factor. This expands to 1/(x2 + 2x + 1). In OpenGL, the quadratic attenuation would be 1, the linear attenuation would be 2, and the constant attenuation would be 1.

I might take a look into that, seems like it would make sense to actually have 1/(x+1)^2.

I'm not really clear on your size analogy, but you should treat each sample as an independent light source and perform attenuation on all of them.


Well, you have to understand the meaning of attenuation. Quadratic attenuation comes from the fact that light spreads from a point light in a spherical manner, so there is less light per unit area as distance increases (the area of a sphere augments proportionally to the square of its radius).

In my case, when sampling for indirect lighting, I naturally gather less light for far away objects because the projection of those objects on the unit hemisphere is smaller, but when sampling for direct lighting, I basically ignore the unit hemisphere, and send N samples (constant number) to each light source.

So I'm thinking of only attenuating for direct lighting. That will probably "look right"... Anyhow, I will be trying this tonight and I will see what the result is.

Looking for a serious game project?
www.xgameproject.com
I see, I didn't know you were using a hemispherical projection for the indirect lighting. You mentioned it but I thought that was just an analogy. In that case then no, you don't need explicit attenuation because the physical projection handles it.
Wether you need quadratic attenuation or not depends on how you get your 'samples'. Basicly it is like this:

If you sample from a 'surface' (i.e. an arealight, pointlight, a random triangle) you need quadratic attenuation.

If you take samples over the (hemi)sphere and just look for the first intersection, you do NOT need quadratic attenuation.

More precisely for pathtracing:
- for integrating over surfaces: L * cos(theta_i) * cos(theta_o) / r²
- for integrating over (hemi)sphere: L * cos(theta_i)
(L = radiance, theta_i = angle of sampled ray with original surface, theta_o = angle of sampled ray with other surface (i.e. the light sampled,...)
Yup, I also figured on my own that cosine attenuation based on the angle at the other surface wasn't needed when sampling over the hemisphere... It made my cornell box look quite strange. The corners near the ceiling seemed overly dark.

Looking for a serious game project?
www.xgameproject.com

This topic is closed to new replies.

Advertisement