Jump to content
  • Advertisement
Sign in to follow this  
matt77hias

Distance attentuation of omi and spotlights

Recommended Posts

If we apply the rendering equation to a single omni light, we obtain

$$L\!\left(p, \hat{\omega_{o}}\right) = f_{r}\!\left(p, \hat{\omega_{i}}, \hat{\omega_{o}}\right) E\!\left(p, \hat{\omega_{l}}\right).$$

Since irradiance is defined as

$$E\!\left(p, \hat{\omega_{l}}\right) := \frac{\mathrm{d}\Phi}{\mathrm{d}A},$$

we can substitute the power/flux received at a surface $A$, positioned at $p$ and oriented by $\hat{n}$:

$$\Phi_{A} = \frac{\Phi A \left(\hat{n} \cdot \hat{\omega_{l}}\right)}{4 \pi \lVert p - p_{l} \rVert_{2}^{2} }$$

in the above equation:

$$L\!\left(p, \hat{\omega_{o}}\right) = f_{r}\!\left(p, \hat{\omega_{i}}, \hat{\omega_{o}}\right) \frac{\Phi \left(\hat{n} \cdot \hat{\omega_{l}}\right)}{4 \pi \lVert p - p_{l} \rVert_{2}^{2} } \mathcal{V}\!\left(p, p_{l}\right).$$

Here, 

$$I_{l} := \frac{\Phi}{4 \pi} $$

is the mysterious "intensity" factor appearing in some code, still having units [W] (unless we really should interpret the denominator as the solid angle of the full sphere?). Though actual (radial) intensity is equal to 

$$I := \frac{\mathrm{d}\Phi}{\mathrm{d}\omega} $$

and has units [W/sr].

The distance attunatuation is equal to

$$\frac{1}{\lVert p - p_{l} \rVert_{2}^{2}} = \frac{1}{r^{2}}.$$

Unfortunately, this is not very practical for light culling due to the infinite decay. So lets make the decay finite:

$$\frac{1}{r^{2}}-\frac{1}{r_{\mathrm{range}}^{2}}.$$

Is this a common PBR distance attenuation used in game engines?  The function reaches infinity at zero meter, which is actually correct. A ray tracer would do the same. (Note that omni lights do not exist in reality.) The following could remedy this:

$$\frac{1}{r^{2}+a^2}-\frac{1}{r_{\mathrm{range}}^{2}+a^2}.$$

Here, we will approximately have 

$$\frac{1}{a^2}$$

at a distance of zero meter. (Note that we need to clamp at zero. I omitted this for simplicity of notation.)

My concern was actually with the following distance attenuation, I found in the Real-time Rendering book:

$$\mathrm{saturate}\!\left(\frac{r_\mathrm{end}-r}{r_{range}}\right).$$

This really compensates the absence of indirect lighting, but results in images far from (real-time) physically accurate.

 

Furthermore, what is normally stored for expressing the "light intensity" of omni and spotlights? For directional lights, this is radiance. For omni lights my guess is

$$\frac{\Phi}{4 \pi}$$

and for spotlights my guess is

$$\frac{\Phi}{2 \pi}$$

(assuming you do not include the angular falloff into the power)?

 

Edited by matt77hias

Share this post


Link to post
Share on other sites
Advertisement

The last few games that I've shipped use the attenuation equation that you suggest (subtracting 1/range^2), and it works okay. One issue with it is that the combination of the offset + clamping at 0 means that the resulting function isn't continuous in the first derivative, which can give you a visible seam in some cases. Brian Karis suggested an alternate attenuation function here that doesn't have this particular issue.

Share this post


Link to post
Share on other sites
6 hours ago, MJP said:

Brian Karis suggested an alternate attenuation function here that doesn't have this particular issue.

He uses the following distance falloff:

$$\frac{\mathrm{saturate}\left(1-\left(r/r_{\mathrm{range}}\right)^4\right)^2}{r^2+1}$$

What is the idea behind the power of 4 and the power of 2 in the nominator? I think that the power of 2 is for ease of use; we keep working with squared distances, but the nominator does not contain an absolute squared distance? Only some relative coefficient.

I played around with this function, but it looks very unrealistic due to the +1 in the denominator. You should expect some attenuation factor larger than 1 for distances less than 1m. But with +1 you will never have an attenuation higher than 1. So if you put a spotlight at your camera eye, it looks much too dark close to some objects.

+0.1 instead of +1 looks already much better

Edited by matt77hias

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!