Multiply Color/Screen Color

Updated: 05/19/2022

This section explains how to blend and draw colors on a model using Multiply Color and Screen Color.
The features introduced here are those of the SDK for Unity 4 R5 beta1 or later.

Models created before Cubism Editor 4.2, for example, can be used without any additional coding, even if the Multiply Color and Screen Color are not set for the model.
See the “Multiply Color/Screen Color” page in the SDK Manual for detailed specifications and usage in the SDK for Unity.

As a preliminary preparation, please refer to the “Import SDK” page to import model data and place the prefab.

By default, it is set to always refer to the Multiply Color and Screen Color previously set for the model. If the Multiply Color and Screen Color are not set for the model, the following values are used.

  • In Multiply Color (1.0, 1.0, 1.0, 1.0)
  • In Screen Color (0.0, 0.0, 0.0, 1.0)

Use in Inspector

To enable manipulation of Multiply Color and Screen Color from the SDK side, enable the following flags.

Multiply Color:

OverwriteFlagForModelMultiplyColors or OverwriteFlagForMultiplyColors

Screen Color:

OverwriteFlagForModelScreenColors or OverwriteFlagForScreenColors

OverwriteFlagForModelMultiplyColors and OverwriteFlagForModelScreenColors are flags that determine whether the SDK can manipulate Multiply Color and Screen Color for all Drawables.
These flags can also be manipulated in the Inspector of the [CubismRenderController], which is attached to the model prefab root object in the Unity Editor.

OverwriteFlagForMultiplyColors and OverwriteFlagForScreenColors are flags that determine whether each individual Drawable can manipulate Multiply Color and Screen Color from the SDK side.
It can also be manipulated in the Inspector of the [CubismRenderer] attached to each Drawable object in the model.

If the Multiply Color and Screen Color flags that [CubismRenderController] has as described above are enabled, they will take precedence.

Multiply Color and Screen Color settings can be controlled not only from scripts, but also from Inspector in the [CubismRenderer].

Use in Scripts

The following code is useful in applications and other cases where control is needed in scripts.

The following code is designed to change the Screen Color of all Drawable objects at the same time in a certain period of time.

You can create a C# script that rewrites the contents as follows and attach it to the root object of the model prefab.

using UnityEngine;
using Live2D.Cubism.Rendering;

public class BlendColorChange : MonoBehaviour
{
    CubismRenderController RenderController { get; set; }
    float[] _colorValues;
    float _time;

    void Start()
    {
        _colorValues = new float[3];
        _time = 0.0f;
        RenderController = GetComponent<CubismRenderController>();
        RenderController.OverwriteFlagForModelScreenColors = true;
    }

    void Update()
    {
        if (_time < 1.0f)
        {
            _time += Time.deltaTime;
            return;
        }

        for (int i = 0; i < _colorValues.Length; i++)
        {
           _colorValues[i] = Random.Range(0.0f, 1.0f);
        }
        
        var color = new Color(_colorValues[0], _colorValues[1], _colorValues[2], 1.0f);
    

        for (var i = 0; i < RenderController.Renderers.Length; i++)
        {
            RenderController.Renderers[i].ScreenColor = color;
        }

        _time = 0.0f;
    }
}

Receive notification of Multiply Color and Screen Color updates from the model side

If a model parameter is associated with a change in Multiply Color/Screen Color, the model may change the Multiply Color/Screen Color when the model is animated, rather than from the SDK side.

The property IsBlendColorDirty is implemented in [CubismDynamicDrawableData] to indicate that the Multiply Color and/or Screen Color have been changed.

This property is true when either the Multiply Color or Screen Color is changed on the model side, and does not determine whether the Multiply Color or Screen Color is changed.

See the “Multiply Color/Screen Color” page in the SDK Manual for details.

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