現実の世界では、ライトは距離が離れるにしたがってフェードし、薄暗いライトは明るいライトよりも光域が狭くなります。「減衰」とは、光が弱まっていく割合を指します。Unity のデフォルトのライトの減衰の動作とともに、カスタムの減衰設定を使用することもできます。
プログレッシブライトマッパーはカスタムの減衰プリセットを提供し、スクリプトを通して実装することができます。これらがどのように動作するかを表す例は、表の下にある図を参照してください。また、図の下のコードサンプルは、機能の使用例です。
プロパティ | 機能 |
---|---|
InverseSquared |
逆 2 乗距離減衰モデルを適用します。これは、ライトの強度が、光源の位置からの距離の 2 乗に反比例して減少することを意味します。詳細は、Wikipedia の逆 2 乗の法則 を参照してください。このオプションは物理的に最も正確です。 |
InverseSquaredNoRangeAttenuation |
逆平方距離減衰モデルを適用します。滑らかな光域減衰はありません。これは InverseSquared と同じように動作しますが、ライティングシステムはパンクチュアルライト (つまり、ポイントライトとスポットライト) の range パラメーターの減衰を考慮しません。 |
Legacy |
2 次方程式の減衰モデルを適用します。このモデルは、光源の光域のライトの減衰に基づいています。強度は、ライトが光源から遠ざかるにつれて減衰しますが、減衰が非常に鋭く不自然に低下し、視覚効果は現実的ではありません。 |
Linear |
リニアの減衰モデルを適用します。このモデルでは、減衰はライトからの距離に反比例し、減衰は光源から一定の割合で減少します。 |
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();
Cookie cookie = new Cookie();
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();
}
}
プログレッシブライトマッパーは 2018.1 で追加 NewIn20181
2018–03–28 公開ページ
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.