콘텐츠로 이동

UE5 Material Parameter Collection

Material Parameter Collection(MPC)은 하나의 에셋에 스칼라·벡터 파라미터를 모아두고, 씬의 모든 머티리얼이 공유해서 읽을 수 있게 해주는 시스템입니다. 전역 날씨 강도, 시간대 색상, 플레이어 위치 기반 효과처럼 “씬 전체에 영향을 주는 파라미터”를 다룰 때 필수적입니다.


Content Browser → 우클릭 → Materials → Material Parameter Collection

MPC 에셋 내부 구조:

MPC_Weather
Scalar Parameters:
RainIntensity (0.0 ~ 1.0)
FogDensity (0.0 ~ 0.5)
TimeOfDay (0.0 = 자정, 0.5 = 정오, 1.0 = 자정)
Vector Parameters:
SunColor (RGB + A)
AmbientColor

머티리얼 에디터에서 CollectionParameter 노드를 추가하고 MPC 에셋과 파라미터 이름을 선택합니다. 이 값은 런타임에 동적으로 변경됩니다.

HLSL 커스텀 노드에서 직접 접근하는 것은 불가능하지만, CollectionParameter 노드의 출력을 커스텀 노드의 입력으로 연결할 수 있습니다.


WeatherSystem.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "WeatherSystem.generated.h"
class UMaterialParameterCollection;
class UMaterialParameterCollectionInstance;
UCLASS()
class MYGAME_API AWeatherSystem : public AActor
{
GENERATED_BODY()
public:
AWeatherSystem();
UPROPERTY(EditAnywhere, Category="Weather")
UMaterialParameterCollection* WeatherMPC;
UFUNCTION(BlueprintCallable, Category="Weather")
void SetRainIntensity(float Intensity);
UFUNCTION(BlueprintCallable, Category="Weather")
void SetTimeOfDay(float NormalizedTime);
private:
UMaterialParameterCollectionInstance* _mpcInstance;
};
WeatherSystem.cpp
#include "WeatherSystem.h"
#include "Materials/MaterialParameterCollection.h"
#include "Materials/MaterialParameterCollectionInstance.h"
#include "Engine/World.h"
AWeatherSystem::AWeatherSystem()
{
PrimaryActorTick.bCanEverTick = true;
}
void AWeatherSystem::BeginPlay()
{
Super::BeginPlay();
if (WeatherMPC)
{
// 월드에 MPC 인스턴스를 가져옴 (없으면 자동 생성)
_mpcInstance = GetWorld()->GetParameterCollectionInstance(WeatherMPC);
}
}
void AWeatherSystem::SetRainIntensity(float Intensity)
{
if (!_mpcInstance) return;
_mpcInstance->SetScalarParameterValue(
FName("RainIntensity"),
FMath::Clamp(Intensity, 0.f, 1.f)
);
}
void AWeatherSystem::SetTimeOfDay(float NormalizedTime)
{
if (!_mpcInstance) return;
_mpcInstance->SetScalarParameterValue(
FName("TimeOfDay"),
FMath::Frac(NormalizedTime) // 0~1 사이로 정규화
);
// 시간대에 따른 태양 색상도 함께 변경
FLinearColor SunColor = FLinearColor::LerpUsingHSV(
FLinearColor(1.f, 0.5f, 0.2f), // 노을 색
FLinearColor(1.f, 0.95f, 0.8f), // 낮 색
FMath::Sin(NormalizedTime * PI)
);
_mpcInstance->SetVectorParameterValue(FName("SunColor"), SunColor);
}

// Tick에서 부드럽게 전환
void AWeatherSystem::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
static float CurrentTime = 0.f;
CurrentTime += DeltaTime / (60.f * 24.f); // 하루를 24분으로 압축
if (CurrentTime > 1.f) CurrentTime -= 1.f;
SetTimeOfDay(CurrentTime);
}

5. MPC와 Dynamic Material Instance 비교

섹션 제목: “5. MPC와 Dynamic Material Instance 비교”
항목MPCDynamic Material Instance
적용 범위전역 (참조하는 모든 머티리얼)해당 인스턴스만
성능 비용매우 낮음 (GPU 상수 버퍼)인스턴스 수에 비례
사용 사례날씨, 시간대, 글로벌 효과개별 오브젝트 색상·강도
머티리얼 수정불필요 (공유)머티리얼 인스턴스 생성 필요

MPC 파라미터를 포스트프로세스 머티리얼에서도 동일하게 참조할 수 있습니다. 예를 들어 RainIntensity 값에 따라 화면 왜곡 강도를 변경하거나 비네팅을 적용하는 포스트프로세스 머티리얼을 만들어 Post Process Volume에 할당합니다.

// 포스트프로세스 머티리얼 노드 구성 (개념)
CollectionParameter(MPC_Weather, RainIntensity)
→ Multiply(ScreenDistortionStrength)
→ SceneTexture 왜곡 적용

  • MPC는 씬 전역에 영향을 주는 파라미터에 최적화된 도구이며, GPU 상수 버퍼를 활용해 오버헤드가 거의 없다.
  • GetWorld()->GetParameterCollectionInstance(MPC)로 인스턴스를 가져와 SetScalarParameterValue/SetVectorParameterValue로 값을 바꾼다.
  • 개별 오브젝트 파라미터는 Dynamic Material Instance가 적합하고, 전역 환경 효과는 MPC가 더 효율적이다.