Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Light attentuation equation?

Discussion in 'Editor & General Support' started by kiwilandicMark, Dec 19, 2008.

  1. kiwilandicMark

    kiwilandicMark

    Joined:
    Nov 21, 2005
    Posts:
    8
    Hi all,

    Does anyone know (or is there anybody from Unity hiding there in the background) the formula used for Light attentuation for Spotlights and Point Lights? I can't find any documentation for PHSYX online (one apparently has to download the SDK on a windows machine to get at the docs?!), so I'm struggling to figure it out. I also notice there's a difference between Spotlights and Point Lights.

    That would be much appreciated!

    Thanks,
    Mark

    PS. Should somebody all-knowing happen to take a glance in here, I'm also on the hunt for the equation used with the Rolloff Factor to calculate the attentuation of sound in Unity, too! Thanks. :)
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Spot lights attenuate linearly over their range. At the point of light, intensity is at max, at the end of light's range, it is zero. Linear dropoff in between.

    Point lights attenuate with something that pretty much matches quadratic attenuation in fixed function D3D/OpenGL: if r goes from 0 at light's position to 1 at it's range, then intensity is
    Code (csharp):
    1. 1.0 / (1.0 + 25.0*r*r)
    Near the light's range it fades to zero (because classic OpenGL attenuation model for point lights never falls to zero).

    Oh, but this does not have anything to do with PhysX. It's rendering, not physics.
     
    NeatWolf and Anisoropos like this.
  3. kiwilandicMark

    kiwilandicMark

    Joined:
    Nov 21, 2005
    Posts:
    8
    Okay, thanks very, very much for all of that, especially for the quick reply!

    Mark
     
  4. Simod

    Simod

    Joined:
    Jan 29, 2014
    Posts:
    176
    Hi there,

    I know this topic is old, but I am trying to reproduce Unity's light attenuation in native code. It seems Spot and Point lights are now following same equation:
    Code (CSharp):
    1. 1.0 / (1.0 + 25.0*r*r)
    It's showing correct results. Yet "end of light" needs extra equation in order to zero it's attenuation. I thought it should be linear starting at some point. But result is not correct...

    Could you enlighten me with that missing piece of puzzle?:confused:
     
  5. arichter_rs360

    arichter_rs360

    Joined:
    Jan 15, 2018
    Posts:
    1
    BrightBit likes this.
  6. Spaniel

    Spaniel

    Joined:
    Dec 23, 2012
    Posts:
    52
    Would it be possible to calculate the range of the light based on attenuation? In other words, if I said that the attenuation is 200, would it be possible using the formula above to calculate the range? I am sort of at a loss for how to do so :)

    Any help would be fantastic.