# URP Linear and custom lighting calculations

All the flexibility of the past seems to have been lost in URP. OK you can write a custom render pipeline in theory but not got the time!

Not being able to have linear falloff lights from builtin is a real issue for lighting procedural geometry that is not lightmapped. We should get some control of the falloff.

And before you could replace the whole lighting pipeline which I guess is only possible now by customizing the package - has anyone done?

URP is not just for realistic games with realistic lighting - so we need the flexibility!

So the current solution to change all lighting is to modify one lighting file in the URP package: RealtimeLights.hlsl in ShaderLibrary\RealtimeLights
Find the function DistanceAttenuation
To use linear lighting I think you can just sqrt the distanceSqr that comes into that function to go back to linear!!

Here is the function with some comments:

``````float DistanceAttenuation(float distanceSqr, half2 distanceAttenuation)
{
//Note: Add this line for linear lighting! Dumb but works?!
distanceSqr = sqrt(distanceSqr);//back to linear from squared

// We use a shared distance attenuation... this is as provided
float lightAtten = rcp(distanceSqr);
//Note: what is this?! I mean is half2 not adjusted to be a float in most cases anyway - never seen this!
float2 distanceAttenuationFloat = float2(distanceAttenuation);

// XX Use the smoothing factor also used in the Unity lightmapper.
// Note: What exactly does this smoothing factor do?! Not easy to see visually!
half factor = half(distanceSqr * distanceAttenuationFloat.x);
half smoothFactor = saturate(half(1.0) - factor * factor);
smoothFactor = smoothFactor * smoothFactor;

return lightAtten * smoothFactor;
}
``````

Updated post to show currently known solution - thanks to Custom Dynamic Lighting Attenuation - Community Showcases - Unity Discussions

Here is the effect of adding one line to hlsl to get linear lighting: