Version: 2022.3

Realtime Global Illumination using Enlighten

# 自定义衰减

InverseSquared 应用距离平方倒数法衰减模型。意味着，光照强度与位置到光源的距离的平方成反比减小。有关更多信息，请参阅 Wikipedia：平方反比定律 (Inverse-square law)。此选项在物理上是最准确的。
InverseSquaredNoRangeAttenuation 应用距离平方倒数法衰减模型，但没有平滑范围衰减。此选项的原理与 InverseSquared 此相同，但光照系统不考虑准时光源（即点光源和聚光灯）的范围参数的衰减。
Legacy 应用二次衰减模型。该模型将光衰减基于光源的范围。随着光线远离光源，强度会减弱，但衰减会有非常明显且不自然的下降，视觉效果也不太现实。
Linear 应用线性衰减模型。在此模型中，衰减与距光源的距离成反比，且衰减以固定的速率从光源开始减弱。

Note: The code example below only works with the Progressive Lightmapper when you use Baked or Mixed lights. To use the code example with realtime lights, use Enlighten Realtime Global Illumination.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.GlobalIllumination;
using UnityEngine.SceneManagement;
[ExecuteInEditMode]
public class ExtractFalloff : MonoBehaviour
{
public void OnEnable()
{
Lightmapping.RequestLightsDelegate testDel = (Light[] requests, Unity.Collections.NativeArray<LightDataGI> lightsOutput) =>
{
DirectionalLight dLight = new DirectionalLight();
PointLight point = new PointLight();
SpotLight spot = new SpotLight();
RectangleLight rect = new RectangleLight();
DiscLight disc = new DiscLight();
LightDataGI ld = new LightDataGI();

for (int i = 0; i < requests.Length; i++)
{
Light l = requests[i];
switch (l.type)
{
case UnityEngine.LightType.Directional: LightmapperUtils.Extract(l, ref dLight); LightmapperUtils.Extract(l, out cookie); ld.Init(ref dLight, ref cookie); break;
case UnityEngine.LightType.Point: LightmapperUtils.Extract(l, ref point); LightmapperUtils.Extract(l, out cookie); ld.Init(ref point, ref cookie); break;
case UnityEngine.LightType.Spot: LightmapperUtils.Extract(l, ref spot); LightmapperUtils.Extract(l, out cookie); ld.Init(ref spot, ref cookie); break;
case UnityEngine.LightType.Area: LightmapperUtils.Extract(l, ref rect); LightmapperUtils.Extract(l, out cookie); ld.Init(ref rect, ref cookie); break;
case UnityEngine.LightType.Disc: LightmapperUtils.Extract(l, ref disc); LightmapperUtils.Extract(l, out cookie); ld.Init(ref disc, ref cookie); break;
default: ld.InitNoBake(l.GetInstanceID()); break;
}
ld.falloff = FalloffType.InverseSquared;
lightsOutput[i] = ld;
}
};
Lightmapping.SetDelegate(testDel);
}
void OnDisable()
{
Lightmapping.ResetDelegate();
}
}

Note: All code in the example above is necessary for the custom falloff to work; however, you can change InverseSquared in the line ld.falloff = FalloffType.InverseSquared; to use any of the presets described above.

2018.1 版中添加了渐进光照贴图 NewIn20181

2018–03–28 页面已发布

Realtime Global Illumination using Enlighten