Hi, I'm trying to know if a mesh is currently in the light or in the dark. Besides casting a ray to the light (to check if it's occluded by geometry), I need to know if the mesh is in the light radius. How do I check this? I have been using this formula : var Lightp = light.range * (light.intensity / 10.0f); But results are inconsistent. Any tips? Thanks!
Being inside the light's radius is just checking distance against the range. The catch is that at "range" the brightness is 0, and the effective brightness changes based on a few different things. - How bright the light is - Light falloff curve (determined by render pipeline, I believe) - Material of the object being lit I would guess that the inconsistency of results stems from those things. The first two are perhaps the more likely culprits, and are solvable with math.
Thanks angrypenguin, You don't happen to know the light falloff curve on the Build In Render pipeline?
Well, this one is fun. In "legacy" renderer In internal renderer light brightness is determined by a ... texture lookup based on distance squared from light center. Code (csharp): float getLightAttenuation(float3 worldPos){ #if defined(POINT) { unityShadowCoord3 lightCoord = mul(_LightMatrix0, float4(worldPos, 1.0)).xyz; float result = tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).UNITY_ATTEN_CHANNEL; return result; } No mention anywhere what's written into that texture, but various sources claim that the attenuation is linear. Meaning 1.0/distance . where distance is distance to light center. However in URP(and likely HDRP) the falloff is 1.0/distanceSquared. I.e. 1.0/(distance*distance) This is mentioned here: https://docs.unity3d.com/Packages/c...l/universalrp-builtin-feature-comparison.html In both cases the falloff is technically infinite. In practice anything beyond light radius likely won't be lit.
I used this asset for a hobby project and to learn it myself. It works well, also for point lights! Solution actually is easy when you know how to do it but i feel it's not fair sharing it cause i didn't come up with it myself. But you can consider getting the asset and study the script! https://assetstore.unity.com/packages/tools/ai/shadow-detection-stealth-mode-50388#content