UnityShaderVariables.cginc has the built-in variable `float4 _LightPositionRange`, where xyz = pos and w = (1/range). From this you get
`float attenuation = 1-(distanceToLight / (1 / _LightPositionRange.w)) ;`
Which gives a smooth transition and also works for ForwardAdd passes.
You can find the distance by
`_WorldSpaceLightPos0.xyz-posWorld.xyz;`
You only need to include "AutoLight.cginc" for both _LightPositionRange and _WorldSpaceLightPos0.
Found little info on this elsewhere so hope this helps someone.
↧