Version: 2023.2
言語: 日本語
ライトマップの継ぎ目の縫合
Enlighten を使用したリアルタイムのグローバルイルミネーション

カスタムの減衰

現実の世界では、ライトは距離が離れるにしたがってフェードし、薄暗いライトは明るいライトよりも光域が狭くなります。“減衰” とは、光が弱くなる割合を指します。Unity のデフォルトのライトの減衰の動作とともに、カスタムの減衰設定を使用することもできます。

プログレッシブライトマッパーはカスタムの減衰プリセットを提供し、スクリプトを通して実装することができます。これらがどのように動作するかを表す例は、表の下にある図を参照してください。また、図の下のコードサンプルは、機能の使用例です。

プロパティ 機能
InverseSquared 逆 2 乗距離減衰モデルを適用します。これは、ライトの強度が、光源の位置からの距離の 2 乗に反比例して減少することを意味します。詳細は、Wikipedia の逆 2 乗の法則 を参照してください。このオプションは物理的に最も正確です。
InverseSquaredNoRangeAttenuation Apply an inverse-squared distance fall-off model with no smooth range attenuation. This works in the same way as InverseSquared, but the lighting system does not take into account the attenuation for the range parameter of punctual lights (that is, point lights and spot lights).
Legacy 2 次方程式の減衰モデルを適用します。このモデルは、光源の光域のライトの減衰に基づいています。強度は、ライトが光源から遠ざかるにつれて減衰しますが、減衰が非常に鋭く不自然に低下し、視覚効果は現実的ではありません。
Linear リニアの減衰モデルを適用します。このモデルでは、減衰はライトからの距離に反比例し、減衰は光源から一定の割合で減少します。
各カスタム減衰プリセットの視覚効果の例
各カスタム減衰プリセットの視覚効果の例

ノート: 下のコード例は、Baked または Mixed ライトを使用する場合にのみ、プログレッシブライトマッパーで動作します。このコード例をリアルタイムライトで使用するには、Enlighten リアルタイムグローバルイルミネーション を使用します。

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.Rectangle: 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.cookieID = l.cookie?.GetInstanceID() ?? 0;
                ld.falloff = FalloffType.InverseSquared;
                lightsOutput[i] = ld;
            }
        };
        Lightmapping.SetDelegate(testDel);
    }
    void OnDisable()
    {
        Lightmapping.ResetDelegate();
    }
}

ノート: 上の例のすべてのコードは、カスタムフォールオフを動作させるために必要です。ただし、ld.falloff = FalloffType.InverseSquared;InverseSquared を変更して、前述のプリセット のいずれかを使用できます。


プログレッシブライトマッパーは 2018.1 で追加 NewIn20181

2018–03–28 公開ページ

ライトマップの継ぎ目の縫合
Enlighten を使用したリアルタイムのグローバルイルミネーション