Unity 커스텀 폴오프 설정 가이드
Unity의 조명 시스템에서 폴오프(fall-off)는 광원이 거리에 따라 희미해지는 속도를 조절합니다. 이 문서는 Unity의 기본 폴오프 동작뿐만 아니라 커스텀 폴오프 프리셋의 적용 방법을 설명합니다.
폴오프란?
폴오프는 광원이 사용되는 거리와 관련하여 밝기가 감소하는 방식을 의마합니다. Unity에서는 여러 모델을 통해 폴오프를 설정할 수 있습니다. 각 모델은 빛의 강도가 감소하는 방식이 다릅니다.
폴오프 모델 | 설명 |
---|---|
InverseSquared | 거리에 제곱에 반비례하여 빛의 강도가 약해지는 모델입니다. 물리적으로 가장 정확합니다. |
InverseSquaredNoRangeAttenuation | 점광원 및 스폿 광원의 범위를 고려하지 않고 약해지는 모델입니다. |
Legacy | 2차 폴오프 모델로, 광원 범위를 기반으로 강도가 감소하지만 불규칙적인 하락이 발생합니다. |
Linear | linear 폴오프 모델로, 거리에 비례하여 일정 비율로 폴오프가 감소합니다. |
커스텀 폴오프 설정하기
커스텀 폴오프 설정을 활용하여 Unity의 프로그레시브 라이트매퍼를 통해 조명 각 모델을 조정할 수 있습니다. 아래의 코드를 활용하여 폴오프 모델을 설정할 수 있습니다.
코드 예시
다음은 Unity에서 커스텀 폴오프 설정을 적용하는 예시입니다. 이 코드 예시는 프로그레시브 라이트매퍼를 사용할 때 작동합니다.
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.cookieID = l.cookie?.GetInstanceID() ?? 0;
ld.falloff = FalloffType.InverseSquared;
lightsOutput[i] = ld;
}
};
Lightmapping.SetDelegate(testDel);
}
void OnDisable()
{
Lightmapping.ResetDelegate();
}
}
위의 코드에서 ld.falloff = FalloffType.InverseSquared;
부분을 수정하여 원하는 폴오프 모델로 변경할 수 있습니다.
마무리
이 가이드는 Unity에서 커스텀 폴오프 설정을 통한 조명 효과를 조정하는 방법에 대해 설명하였습니다. 다양한 모델을 활용하여 장면에서 더 현실감 있는 조명 효과를 구현할 수 있습니다. Unity의 조명 시스템을 최대한 활용하여 자신만의 독창적인 게임 환경을 만들기 바랍니다.