Quantcast
Channel: Answers for "CG Programming, Points Lights attenuation and light range"
Viewing all articles
Browse latest Browse all 5

Answer by FluFFey

$
0
0
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.

Viewing all articles
Browse latest Browse all 5


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>