// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Materials/MaterialParameters.h" #include "Misc/TVariant.h" #include "Misc/NotNull.h" #include "MetaHumanMaterialPipelineCommon.generated.h" // Material parameters that can be changed at runtime // // A subset of EMaterialParameterType UENUM() enum class EMetaHumanRuntimeMaterialParameterType { Toggle, Scalar, Vector, DoubleVector, Texture, TextureCollection, Font, RuntimeVirtualTexture, SparseVolumeTexture }; /** * Used to determine how to obtain material interface for the given parameter. */ UENUM() enum class EMetaHumanRuntimeMaterialParameterSlotTarget { SlotNames, SlotIndices, }; /** * Used to describe material parameter that we can modify on the material * obtained from the slot name or index. */ USTRUCT() struct FMetaHumanMaterialParameter { GENERATED_BODY() public: UPROPERTY(EditAnywhere, Category = "Material") FName InstanceParameterName; UPROPERTY(EditAnywhere, Category = "Material") EMetaHumanRuntimeMaterialParameterSlotTarget SlotTarget = EMetaHumanRuntimeMaterialParameterSlotTarget::SlotNames; UPROPERTY(EditAnywhere, Category = "Material", meta = (EditCondition = "SlotTarget == EMetaHumanRuntimeMaterialParameterSlotTarget::SlotNames")) TArray SlotNames; UPROPERTY(EditAnywhere, Category = "Material", meta = (EditCondition = "SlotTarget == EMetaHumanRuntimeMaterialParameterSlotTarget::SlotIndices")) TArray SlotIndices; UPROPERTY(EditAnywhere, Category = "Material") FMaterialParameterInfo MaterialParameter; UPROPERTY(EditAnywhere, Category = "Material") EMetaHumanRuntimeMaterialParameterType ParameterType = EMetaHumanRuntimeMaterialParameterType::Scalar; UPROPERTY(EditAnywhere, Category = "Material") TMap PropertyMetadata; }; class UMaterialInstanceDynamic; struct FInstancedPropertyBag; namespace UE::MetaHuman::MaterialUtils { /** * Updates materials from the given material parameters. * * @param InMaterialParameters Parameters that will be applied onto the material (doesn't contain the actual data) * @param InMaterialInstanceMapping Materials to updated * @param InAvailableSlots Necessary when parameter specifies the slot index instead of the slot name. * @param InPropertyBag Values for the material parameters. */ void SetInstanceParameters( const TArray& InMaterialParameters, const TMap>& InMaterialInstanceMapping, const TArray& InAvailableSlots, const struct FInstancedPropertyBag& InPropertyBag); /** * Outputs the property bag with parameters that are present on the given material. * * @param InMaterial Material to get values from * @param InMaterialParameters Parameters to look for * @param InOutPropertyBag Output result containing property name and the material parameter value * @return true if any of the parameters were adeded or already in the bag. */ bool ParametersToPropertyBag( TNotNull InMaterial, const TArray& InMaterialParameters, FInstancedPropertyBag& InOutPropertyBag); /** * Converts the given property name to the parameter type. */ EMetaHumanRuntimeMaterialParameterType PropertyToParameterType(TNotNull InProperty); #if WITH_EDITOR /** * Reads metadata from the given property. */ TMap CopyMetadataFromProperty(TNotNull InProperty); #endif }