Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Point Light Range is very low

Discussion in 'Universal Render Pipeline' started by Enoch, Oct 21, 2019.

  1. Enoch

    Enoch

    Joined:
    Mar 19, 2013
    Posts:
    198
    I am not sure this a bug or if this is the way point lights behave in URP, but the range on point lights seems to be completely unaffected by ranges above a certain threshold. I am using 2019.3b6 and URP 7.12.

    I can't get a 1 intensity light to have any effect on an object 5m away no matter what I set the range to. It simply seems to not matter at all after 4m. However I can raise intensity to get it to effect things at a distance but this is pretty unusable in most situations.
     
    Rich_A likes this.
  2. Enoch

    Enoch

    Joined:
    Mar 19, 2013
    Posts:
    198
    Since you gave us source code I felt confident enough to take a look myself. After looking and even step debugging the URP ForwardLightI was pretty confident that the issue wasn't there. After some messing around I was able to get what looks to be a much much better result in my lights by changing this in the shader:
    Lighting.hlsl line 58 (line 7 here):
    Code (CSharp):
    1. // Matches Unity Vanila attenuation
    2. // Attenuation smoothly decreases to light range.
    3. float DistanceAttenuation(float distanceSqr, half2 distanceAttenuation)
    4. {
    5.     // We use a shared distance attenuation for additional directional and puctual lights
    6.     // for directional lights attenuation will be 1
    7.     float lightAtten = rcp(1);//was -> float lightAtten = rcp(distanceSqr;
    8.  
    9. #if SHADER_HINT_NICE_QUALITY
    10.     // Use the smoothing factor also used in the Unity lightmapper.
    11.     half factor = distanceSqr * distanceAttenuation.x;
    12.     half smoothFactor = saturate(1.0h - factor * factor);
    13.     smoothFactor = smoothFactor * smoothFactor;
    14. #else
    15.     // We need to smoothly fade attenuation to light range. We start fading linearly at 80% of light range
    16.     // Therefore:
    17.     // fadeDistance = (0.8 * 0.8 * lightRangeSq)
    18.     // smoothFactor = (lightRangeSqr - distanceSqr) / (lightRangeSqr - fadeDistance)
    19.     // We can rewrite that to fit a MAD by doing
    20.     // distanceSqr * (1.0 / (fadeDistanceSqr - lightRangeSqr)) + (-lightRangeSqr / (fadeDistanceSqr - lightRangeSqr)
    21.     // distanceSqr *        distanceAttenuation.y            +             distanceAttenuation.z
    22.     half smoothFactor = saturate(distanceSqr * distanceAttenuation.x + distanceAttenuation.y);
    23. #endif
    24.  
    25.     return lightAtten * smoothFactor;
    26. }
    Line 58 (line 7 here), from looking at what you were doing in ForwardLight.cs, it looks like all of the smooth falloff was calculated there and you never needed the initial lightAtten to be distanceSqr. I tried 1 and it pretty much works like it did in Standard now.

    Hope this helps someone who was having the same issue.
     
  3. dongdong007

    dongdong007

    Joined:
    Jul 17, 2018
    Posts:
    10
    You're right.:)
     
  4. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    338
    Changing the value to 1 works for realtime lights, but for lightmapped you need to do this also:

    https://docs.unity3d.com/2020.1/Documentation/Manual/ProgressiveLightmapper-CustomFallOff.html

    I havn't been able to figure out how to implement that.
     
    Last edited: Jun 15, 2020
  5. javier_morawski

    javier_morawski

    Joined:
    Jan 5, 2016
    Posts:
    1
    I know this is an old post. But I'm running in to the same issue, and editing the Lighting.hlsl file doesn't seem like a good option, or even to address the issue since whenever I do, Unity rebuilds the package for me overwrites my changes.

    Is there an actual solution to this issue?
     
  6. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    881