Point Light Range is very low

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.

2 Likes

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):

// Matches Unity Vanila attenuation
// Attenuation smoothly decreases to light range.
float DistanceAttenuation(float distanceSqr, half2 distanceAttenuation)
{
    // We use a shared distance attenuation for additional directional and puctual lights
    // for directional lights attenuation will be 1
    float lightAtten = rcp(1);//was -> float lightAtten = rcp(distanceSqr;

#if SHADER_HINT_NICE_QUALITY
    // Use the smoothing factor also used in the Unity lightmapper.
    half factor = distanceSqr * distanceAttenuation.x;
    half smoothFactor = saturate(1.0h - factor * factor);
    smoothFactor = smoothFactor * smoothFactor;
#else
    // We need to smoothly fade attenuation to light range. We start fading linearly at 80% of light range
    // Therefore:
    // fadeDistance = (0.8 * 0.8 * lightRangeSq)
    // smoothFactor = (lightRangeSqr - distanceSqr) / (lightRangeSqr - fadeDistance)
    // We can rewrite that to fit a MAD by doing
    // distanceSqr * (1.0 / (fadeDistanceSqr - lightRangeSqr)) + (-lightRangeSqr / (fadeDistanceSqr - lightRangeSqr)
    // distanceSqr *        distanceAttenuation.y            +             distanceAttenuation.z
    half smoothFactor = saturate(distanceSqr * distanceAttenuation.x + distanceAttenuation.y);
#endif

    return lightAtten * smoothFactor;
}

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.

1 Like

You’re right.:slight_smile:

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.

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?

Use an embedded copy of the urp package to make this kind of change to it without letting unity overwrite it.