Multiply color/Screen color (UE)

Updated: 09/05/2024

This page contains statements regarding the alpha version.

Summary

By applying Multiply Color and Screen Color to the model, tints can be changed in real time.

Use the Cubism SDK for Unreal Engine to apply Multiply Color and Screen Color set in Cubism Editor without any additional coding.
See the “Multiply Color/Screen Color” page in the Editor manual for details on setting the Multiply Color and Screen Color in the Cubism Editor.

In addition, by coding as needed, it is possible to manipulate Multiply Color and Screen Color from the SDK and perform the following operations.

  • Apply Multiply Color and Screen Color interactively.
  • Apply Multiply Color and Screen Color settings that have not been set in the Cubism Editor.
  • Disable Multiply Color and Screen Color set in the Cubism Editor.

The following is an explanation of the procedure.

Multiply color and screen color operation procedure

Multiply Color and Screen Color can be manipulated in three units: model, part, and ArtMesh.
Multiply Color and Screen Color properties are provided for each level.

The properties corresponding to the target you want to manipulate are as follows:

  • To operate on a per-model basis: Properties of CubismModelComponent
  • To operate on a per-part basis: Properties of CubismPartComponent
  • To operate on a per-ArtMesh basis: Properties of CubismDrawableComponent

The relevant properties in CubismModelComponent are as follows.

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

By default, the Multiply Color is set to white and the Screen Color to black.

Selecting the overwrite flag

In order to manipulate Multiply Color and Screen Color via the SDK, the overwrite flags for the multiply and screen colors provided for each model, part, and ArtMesh must be set to true.
Note that the default is false.

The overwrite flags corresponding to each level are as follows:

  • Model (CubismModelComponent)
    • OverwriteFlagForModelMultiplyColors
    • OverwriteFlagForModelScreenColors
  • Part (CubismPartComponent)
    • OverwriteFlagForPartMultiplyColors
    • OverwriteFlagForPartScreenColors
  • ArtMesh (CubismDrawableComponent)
    • OverwriteFlagForDrawableMultiplyColors
    • OverwriteFlagForDrawableScreenColors

These flags can be accessed as the same properties both in the editor and in code.

Manipulating values

When the overwrite flags are checked, the MultiplyColor and ScreenColor values provided for each model, part, and ArtMesh can be changed to manipulate the multiply and screen colors in each unit.
To disable the Multiply Color, set MultiplyColor to white; to disable the Screen Color, set ScreenColor to black.

The changed values are applied in the drawing in the following form by the internal processing of CubismRendererComponent.

MultiplyColor and ScreenColor only reference RGB values; alpha values are not used for drawing.

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);
}

Was this article helpful?
YesNo
Please let us know what you think about this article.