[Java] Multiply Color/Screen Color

Updated: 12/08/2022

This page is for Cubism version 4.2 or earlier. Click here for the latest version.

By applying Multiply Color and Screen Color to the model, tints can be changed in real time.
Multiply Color and Screen Color set in Cubism Editor are applied by using Cubism Java Framework after Cubism 4.2 or later 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.
Also, 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.

Procedures

The process is as follows.

  • Overwrite flag settings for Multiply Color and Screen Color
  • Multiply Color and Screen Color settings
  • Model drawing

Overwrite flag settings for Multiply Color and Screen Color

First, set the overwrite flag for Multiply Color and Screen Color to true. The default is false.

model.getModel().setOverrideFlagForModelMultiplyColors(true); // Multiply color overwrite flag
model.getModel().setOverrideFlagForModelScreenColors(true); // Screen color overwrite flag

public void setOverwriteFlagForModelMultiplyColors(boolean value) and public voidsetOverwriteFlagForModelScreenColors(boolean value) are defined in the Framework’s CubismModel class.
The Cubism SDK for Java  sample project defines the LAppModel class with CubismModel as the base class to manipulate models, and the model in the above code is the instance of LAppModel class.
getModel() is used as an intermediary to call functions of the CubismModel class method from the LAppModel class.

Multiply Color and Screen Color settings

Define Multiply Color and Screen Color and set them to the model.
The code below shows the set values for setting the Multiply Color to red and the Screen Color to green for all Drawables.
RGBA can be used for the setting color.

for (int i = 0; i < model.getModel().getDrawableCount(); i++) {
    CubismRenderer.CubismTextureColor multiplyColor = new CubismRenderer.CubismTextureColor(); // Multiply color
    multiplyColor.r = 1.0f;
    multiplyColor.g = 0.5f;
    multiplyColor.b = 0.5f;
    multiplyColor.a = 1.0f;

    CubismRenderer.CubismTextureColor screenColor = new CubismRenderer.CubismTextureColor(); // Screen color
    screenColor.r = 0.0f;
    screenColor.g = 0.5f;
    screenColor.b = 0.0f;
    screenColor.a = 1.0f;

    model.getModel().setMultiplyColor(i, multiplyColor);
    model.getModel().setScreenColor(i, screenColor);
}

Before applying Multiply Color and Screen Color

After applying red to Multiply Color and green to Screen Color

By looping through the model’s DrawableCount, the multiply and screen colors are processed for all Drawables in every frame.

Tips

In this case, the same Multiply Color and Screen Color are set for all Drawables, but it is possible to set different Multiply Color and Screen Color for each Drawable index. The argument i is the index of the Drawable.

To disable the Multiply Color and Screen Color set in the Cubism Editor, set 0 for the Multiply Color and 1 for the Screen Color. If set, the respective default value will be used.

CubismRenderer.CubismTextureColor multiplyColor = new CubismRenderer.CubismTextureColor(); // Multiply color
multiplyColor.r = 1.0f;
multiplyColor.g = 1.0f;
multiplyColor.b = 1.0f;
multiplyColor.a = 1.0f;

CubismRenderer.CubismTextureColor screenColor = new CubismRenderer.CubismTextureColor(); // Screen color
screenColor.r = 0.0f;
screenColor.g = 0.0f;
screenColor.b = 0.0f;
screenColor.a = 1.0f;

Model drawing

model.draw(projection);

By calling the draw() function of the model originally performed in the Cubism SDK for Java sample project, the model including Multiply Color and Screen Color will be drawn by the rendering process inside Cubism Java Framework.

Other Related Functions

Obtain overwrite flag for Multiply Color and Screen Color

If set to true, the color information set in the SDK is given priority; if set to false, the color information of the model is given priority.

public boolean getOverwriteFlagForModelMultiplyColors(){...}   // Get the multiply color overwrite flag for the entire model
public boolean getOverwriteFlagForScreenColors(){...}   // Get the screen color overwrite flag for the entire model

You can also get the individual overwrite flags for each Drawable.

public boolean getOverwriteFlagForDrawableMultiplyColors(int drawableIndex){...}   // Get the multiply color overwrite flag for the Drawable at the specified index
public boolean getOverwriteFlagForDrawableScreenColors(int drawableIndex){...}   // Get the screen color overwrite flag for the Drawable at the specified index

Multiply Color and Screen Color settings

The above describes the setting method with CubismRenderer.CubismTextureColor an argument, but there is also a method that can set RGBA directly. (Input value 0.0–1.0)

public void setMultiplyColor(int drawableIndex, float r, float g, float b, float a){...}   // Multiply color setting
public void setScreenColor(int drawableIndex, float r, float g, float b, float a){...}   // Screen color setting

Obtain Multiply Color and Screen Color

Get the Multiply Color and Screen Color of each Drawable with the CubismTextureColor type.

CubismRenderer.CubismTextureColor getMultiplyColor(int drawableIndex){...}
CubismRenderer.CubismTextureColor getScreenColor(int drawableIndex){...}

The argument is the index of the Drawable.

Internal Processing of Cubism Java Framework

This is the Framework’s internal process for representing Multiply Color and Screen Color.
The process is as follows.

  1. Get Multiply Color and Screen Color of the model from Cubism Core Java
  2. Determine the acquired Multiply Color and Screen Color by the overwrite flag.
  3. Set the acquired Multiply Color and Screen Color to the shader program.
  4. Add Multiply Color and Screen Color when calculating texture color in the fragment shader.
Tips

Get the model’s Multiply Color and Screen Color from Cubism Core Java in RGBA, but A (transparency) is not set in the Cubism Editor.
Therefore, it is not used in the calculation of Multiply Color and Screen Color.

Get Multiply Color and Screen Color of the model from Cubism Core Java

Use the API of the CubismModel class in Cubism Core Java to obtain an array containing all Drawables of multiply and screen colors from the model.
The specified index of the array is accessed and its value is returned.

public float[] getDrawableMultiplyColor(int drawableIndex) {
    return model.getDrawableViews()[drawableIndex].getMultiplyColors();
}

public float[] getDrawableScreenColor(int drawableIndex) {
    return model.getDrawableViews()[drawableIndex].getScreenColors();
}

In Core Java, when a moc3 file is loaded, information on all Drawables is retrieved and held in a member array.
To set Multiply Color and Screen Color on the SDK side, set setOverwriteFlagForModelMultiplyColors() and setOverwriteFlagForScreenColors() to true and then override the member arrays with setMultiplyColor() and setScreenColor().
To set multiply and screen colors for a specific Drawable, set setOverwriteFlagForDrawableMultiplyColors() and setOverwriteFlagForDrawableScreenColors() to true and perform the same operation.

Tips

When the above process is performed, all subsequent Drawable colors will be set to the overwritten color information.
If you want to use the model’s original color settings again, you must add a separate process.

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