Search Unity

Point light fall off - change to more linear

Discussion in 'General Discussion' started by Vanz, May 4, 2021.

  1. Vanz

    Vanz

    Joined:
    Nov 19, 2013
    Posts:
    374
    Is there a way to change point light fall off, I find it too bright at the center and too dim at points away from the center?

    It seems that the point light has an exponential fall off, I would like it to be more linear. It may not look as realistic but for my application I think it would look better.

    If this can be done with script or shader, please share code if you have it.
     
    PutridEx likes this.
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,563
    For "standard" unity renderer (non scripted pipeline) It certainly can be done but you'd probably need to dig through piles of barely documented and undocumented unity shader code.

    For example, here's my old attempt to implement raytraced primitives that seamlessly integrate into unity lighting.
    https://neginfinity.bitbucket.io/2016/04/raytraced-primitives-in-unity3d-part-41-code-cleanup.html

    Basically, somewhere within AutoLight.cginc there's a light attentuation function, your idea would be to pull it out from there and replace with your own, while keeping everything else functional.

    I'm unaware if it is possible to do this easier through scripted render pipleine or shadergraphs.

    Hoever, here's this tutorial on LWRP:
    https://blogs.unity3d.com/2019/07/31/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019/

    which discusses lighting attenuation. Looks like you should be able to override it.
     
  3. Vanz

    Vanz

    Joined:
    Nov 19, 2013
    Posts:
    374
    Hmm, I need to use URP (Quest 2), damn didn't realize this was going to be so involved...
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,563
    Given you're dealing with the URP, you'll likely need to check the final link I posted and corresponding docs.
    https://blogs.unity3d.com/2019/07/31/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019/
    https://docs.unity3d.com/Packages/c....universal@11.0/manual/urp-lighting-mode.html

    If it is supported at all, it should be MUCH easier than rewriting original shader system.

    Actually, this seems to be related:
    https://forum.unity.com/threads/implementing-linear-falloff-lights-in-urp-shaders.858061/
     
    andywatts and Vanz like this.
  5. Vanz

    Vanz

    Joined:
    Nov 19, 2013
    Posts:
    374
    thanks
     
  6. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,628
    If you're using built-in, isn't it also possible to just use some mathematical formula to re-grade the built-in light attenuation value before using it?