乗算色・スクリーン色 (UE)

最終更新: 2024年9月5日

このページにはアルファ版に関する記述が含まれます。

概要

モデルに乗算色・スクリーン色を適用することで、色合いをリアルタイムに変化させることが出来ます。

Cubism Editor上で設定した乗算色・スクリーン色は Cubism SDK for Unreal Engineを利用することで、特に追加のコーディングをすることなく適用されます。
Cubism Editor上での乗算色・スクリーン色の設定はEditorマニュアルの 「乗算色・スクリーン色」 を参照してください。

また、必要に応じたコーディングを行うことでSDKから乗算色・スクリーン色を操作し、以下のような動作も可能になります。

  • インタラクティブに乗算色・スクリーン色を適用する
  • Cubism Editor上で設定していない乗算色・スクリーン色を適用する
  • Cubism Editor上で設定した乗算色・スクリーン色を無効にする

以降はその手順の説明になります。

乗算色・スクリーン色の操作手順

モデル、パーツ、アートメッシュの3つの単位で乗算色・スクリーン色を操作することができます。
それぞれの階層ごとに乗算色・スクリーン色のプロパティが用意されています。

操作したい対象に対応するプロパティは以下のようになります。

  • モデル単位で操作したい場合:CubismModelComponent のプロパティ
  • パーツ単位で操作したい場合: CubismPartComponent のプロパティ
  • アートメッシュ単位で操作したい場合: CubismDrawableComponent のプロパティ

以下は CubismModelComponent における関連するプロパティを示しています。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
UCLASS(Blueprintable)
class LIVE2DCUBISM_API UCubismModelComponent : public USceneComponent
{
GENERATED_BODY()
public:
...
UPROPERTY(EditAnywhere, Category = "Live2D Cubism")
bool OverwriteFlagForModelMultiplyColors;
UPROPERTY(EditAnywhere, Category = "Live2D Cubism")
FLinearColor MultiplyColor = FLinearColor::White;
UPROPERTY(EditAnywhere, Category = "Live2D Cubism")
bool OverwriteFlagForModelScreenColors;
UPROPERTY(EditAnywhere, Category = "Live2D Cubism")
FLinearColor ScreenColor = FLinearColor::Black;
...
}
UCLASS(Blueprintable) class LIVE2DCUBISM_API UCubismModelComponent : public USceneComponent { GENERATED_BODY() public: ... UPROPERTY(EditAnywhere, Category = "Live2D Cubism") bool OverwriteFlagForModelMultiplyColors; UPROPERTY(EditAnywhere, Category = "Live2D Cubism") FLinearColor MultiplyColor = FLinearColor::White; UPROPERTY(EditAnywhere, Category = "Live2D Cubism") bool OverwriteFlagForModelScreenColors; UPROPERTY(EditAnywhere, Category = "Live2D Cubism") FLinearColor ScreenColor = FLinearColor::Black; ... }
UCLASS(Blueprintable)
class LIVE2DCUBISM_API UCubismModelComponent : public USceneComponent
{
	GENERATED_BODY()

public:

...

	UPROPERTY(EditAnywhere, Category = "Live2D Cubism")
	bool OverwriteFlagForModelMultiplyColors;

	UPROPERTY(EditAnywhere, Category = "Live2D Cubism")
	FLinearColor MultiplyColor = FLinearColor::White;

	UPROPERTY(EditAnywhere, Category = "Live2D Cubism")
	bool OverwriteFlagForModelScreenColors;

	UPROPERTY(EditAnywhere, Category = "Live2D Cubism")
	FLinearColor ScreenColor = FLinearColor::Black;

...

}
TIPS

デフォルトでは乗算色は白、スクリーン色は黒に設定されています。

上書きフラグにチェックを入れる

SDKを通じて乗算色・スクリーン色を操作するためには、各モデル・パーツ・アートメッシュに用意されている乗算色・スクリーン色の上書きフラグが true に設定されている必要があります。
デフォルトでは false になっていることに注意してください。

それぞれの階層に対応する上書きフラグは以下の通りです。

  • モデル(CubismModelComponent)
    • OverwriteFlagForModelMultiplyColors
    • OverwriteFlagForModelScreenColors
  • パーツ(CubismPartComponent)
    • OverwriteFlagForPartMultiplyColors
    • OverwriteFlagForPartScreenColors
  • アートメッシュ(CubismDrawableComponent)
    • OverwriteFlagForDrawableMultiplyColors
    • OverwriteFlagForDrawableScreenColors

エディタ上からもコード上からも、同じプロパティとしてアクセスすることができます。

値を操作する

上書きフラグにチェックが入っている場合は、各モデル・パーツ・アートメッシュに用意されている MultiplyColor および ScreenColor の値を変更することで、各単位で乗算色・スクリーン色を操作することができます。
乗算色を無効にしたい場合は MultiplyColor に白色を設定し、スクリーン色を無効にしたい場合は ScreenColor に黒色を設定してください。

変更した値は CubismRendererComponent の内部処理によって、以下の形で描画に反映されます。

MultiplyColor ScreenColor はRGB値のみが参照され、アルファ値は描画に使用されません。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
for (auto Drawable : Drawables)
{
UMaterialInstanceDynamic* MaterialInstance = static_cast<UMaterialInstanceDynamic*>(Drawable->GetMaterial(0));
UTexture2D* MainTexture = Drawable->TextureIndex < Model->Textures.Num()? Model->Textures[Drawable->TextureIndex] : nullptr;
FLinearColor BaseColor = Drawable->BaseColor;
FLinearColor MultiplyColor = Drawable->MultiplyColor;
FLinearColor ScreenColor = Drawable->ScreenColor;
{
if (Model->OverwriteFlagForModelMultiplyColors)
{
MultiplyColor = Model->MultiplyColor;
}
if (Model->OverwriteFlagForModelScreenColors)
{
ScreenColor = Model->ScreenColor;
}
}
if (UCubismPartComponent* ParentPart = Model->GetPart(Drawable->ParentPartIndex))
{
if (ParentPart->OverwriteFlagForPartMultiplyColors)
{
MultiplyColor = ParentPart->MultiplyColor;
}
if (ParentPart->OverwriteFlagForPartScreenColors)
{
ScreenColor = ParentPart->ScreenColor;
}
}
BaseColor.A *= Model->Opacity * Drawable->Opacity;
MaterialInstance->SetTextureParameterValue("MainTexture", MainTexture);
MaterialInstance->SetVectorParameterValue("BaseColor", BaseColor);
MaterialInstance->SetVectorParameterValue("MultiplyColor", MultiplyColor);
MaterialInstance->SetVectorParameterValue("ScreenColor", ScreenColor);
}
for (auto Drawable : Drawables) { UMaterialInstanceDynamic* MaterialInstance = static_cast<UMaterialInstanceDynamic*>(Drawable->GetMaterial(0)); UTexture2D* MainTexture = Drawable->TextureIndex < Model->Textures.Num()? Model->Textures[Drawable->TextureIndex] : nullptr; FLinearColor BaseColor = Drawable->BaseColor; FLinearColor MultiplyColor = Drawable->MultiplyColor; FLinearColor ScreenColor = Drawable->ScreenColor; { if (Model->OverwriteFlagForModelMultiplyColors) { MultiplyColor = Model->MultiplyColor; } if (Model->OverwriteFlagForModelScreenColors) { ScreenColor = Model->ScreenColor; } } if (UCubismPartComponent* ParentPart = Model->GetPart(Drawable->ParentPartIndex)) { if (ParentPart->OverwriteFlagForPartMultiplyColors) { MultiplyColor = ParentPart->MultiplyColor; } if (ParentPart->OverwriteFlagForPartScreenColors) { ScreenColor = ParentPart->ScreenColor; } } BaseColor.A *= Model->Opacity * Drawable->Opacity; MaterialInstance->SetTextureParameterValue("MainTexture", MainTexture); MaterialInstance->SetVectorParameterValue("BaseColor", BaseColor); MaterialInstance->SetVectorParameterValue("MultiplyColor", MultiplyColor); MaterialInstance->SetVectorParameterValue("ScreenColor", ScreenColor); }
for (auto Drawable : Drawables)
{
	UMaterialInstanceDynamic* MaterialInstance = static_cast<UMaterialInstanceDynamic*>(Drawable->GetMaterial(0));

	UTexture2D*  MainTexture   = Drawable->TextureIndex < Model->Textures.Num()? Model->Textures[Drawable->TextureIndex] : nullptr;
	FLinearColor BaseColor     = Drawable->BaseColor;
	FLinearColor MultiplyColor = Drawable->MultiplyColor;
	FLinearColor ScreenColor   = Drawable->ScreenColor;

	{
		if (Model->OverwriteFlagForModelMultiplyColors)
		{
			MultiplyColor = Model->MultiplyColor;
		}

		if (Model->OverwriteFlagForModelScreenColors)
		{
			ScreenColor = Model->ScreenColor;
		}
	}

	if (UCubismPartComponent* ParentPart = Model->GetPart(Drawable->ParentPartIndex))
	{
		if (ParentPart->OverwriteFlagForPartMultiplyColors)
		{
			MultiplyColor = ParentPart->MultiplyColor;
		}
		
		if (ParentPart->OverwriteFlagForPartScreenColors)
		{
			ScreenColor = ParentPart->ScreenColor;
		}
	}

	BaseColor.A *= Model->Opacity * Drawable->Opacity;

	MaterialInstance->SetTextureParameterValue("MainTexture", MainTexture);
	MaterialInstance->SetVectorParameterValue("BaseColor", BaseColor);
	MaterialInstance->SetVectorParameterValue("MultiplyColor", MultiplyColor);
	MaterialInstance->SetVectorParameterValue("ScreenColor", ScreenColor);
}

この記事はお役に立ちましたか?
はいいいえ
この記事に関するご意見・
ご要望をお聞かせください。