Skip to main content

Controlling Light-Shadow Color Transitions

MooaToon uses Ramp Map to represent the color transition from light to shadow:

Default Ramp + Single Light
Binarization Shadow Transition
image-20240808231641482
3Levels Ramp + Single Light
Shadow Transition now has 3 color levels
image-20240808230642858
3Levels Ramp + Multiple Lightsimage-20240808230839624

Ramp is a 1D lookup table (LUT), which stores user-defined Curves, represented as Color Curves in UE:

image-20240808221949108

By vertically arranging multiple Color Curves, a Curve Atlas texture can be created, with each Color Curve occupying one row of pixels:

image-20240808232600442

Starting from MooaToon 5.4, use Global Diffuse Color Ramp and Global Specular Color Ramp, by placing all Ramps in an Atlas, and specifying which Ramp to use in each material, achieving Multi-Light Ramp Lighting.

Choose Which Ramp to Use

First find Global Diffuse Color Ramp Atlas in Project Settings to browse all available Ramps:
Project Settings > Engine > MooaToon > Global Diffuse Color Ramp Atlas.

Then remember the index of the Ramp you want to use, for example, the index of CC_DiffuseColorRamp_012_3Levels2 is 12, then fill in the index into the Diffuse Color Ramp Index of the Toon material:

image-20240808233617823

Add New Ramps and Ramp Atlas

To avoid file conflicts, please do not directly modify the built-in Ramps or Ramp Atlas of MooaToon. Instead, directly add new Ramps and Ramp Atlas.

First, duplicate the current Global Diffuse Color Ramp (default is MooaToon-Project/Plugins/MooaToon/Content/Assets/DiffuseColorRamps/CA_GlobalDiffuseColorRampAtlas), then to your own directory.

Then set the duplicated RampAtlas file to Global Diffuse Color Ramp Atlas.

Now you can edit your own Ramp Atlas, you can directly create new Color Curves or copy built-in Ramps, then add them to the Ramp Atlas.

Detailed Explanation of Diffuse Color Ramp Channels 

PBR Lambertian DiffuseBinary Ramp Lighting3 Levels Ramp LightingSkin Ramp Lighting

The horizontal axis of the Diffuse Color Ramp represents the angle between the normal direction and the light direction (N dot L, abbreviated as NoL), where 0 is the backlit side and 1 is the frontlit side.

The Diffuse Color Offset input of the Toon Material is used to offset the light-dark boundary (NoL + DiffuseColorOffset), while AO is used to create fixed-position shadows (min(NoL, AO)).

The value of the RGB channel is Diffuse Color.  
The A channel is used to distinguish between light and dark areas, which means blending Base Color and Shadow Color, where 1 represents light (Base Color) and 0 represents dark (Shadow Color).

info

The final calculation order of Diffuse color is represented in pseudo code as follows:

1. DiffuseColorRampU = min(NoL + DiffuseColorRampUVOffset, AO, Shadow/*Ray Tracing Shadows / Virtual Shadow Maps / Hair Shadows*/)
2. DiffuseColorRamp = Sample GlobalDiffuseColorRampAtlas by DiffuseColorRampU
3. DiffuseColor = Blend ShadowColor and BaseColor with DiffuseColorRamp.a
4. Output = DiffuseColor * DiffuseColorRamp.rgb * Light Color

More examples are as follows:

image-20240809000548763+image-20240809000145398=image-20240809000224379
Ramp A: Binarized at 0.5Modify Base Color and Shadow ColorBinarization of 2 colors
image-20240809000516803+image-20240809000342424=image-20240809000354270
Ramp A: Slow transition from 1 to 0Modify Base Color and Shadow ColorSlow transition of 2 colors
image-20240809003756931+image-20240809003808154=image-20240809003817990
Ramp RGB: Gradient of 3 colors
Ramp A: Slow transition from 1 to 0
Base Color = Shadow ColorGradient of 3 colors
image-20240809001134948+image-20240809001148472=image-20240809001201077
Ramp A: Gradient of 4 color levelsModify Shadow ColorStaggered gradient of 2 colors
image-20240809003210503+image-20240809003223017=image-20240809003233104
Ramp RGB: Gradient of 3 colors
Ramp A: Gradient of 4 color levels
Base Color = Shadow ColorStaggered gradient of 3 colors
image-20240809003308273=image-20240809003320512
Ramp remains unchangedModify Shadow ColorStaggered gradient of 3 colors in multiply blending mode with Shadow Color
image-20240809002055336=image-20240809002024305
Sample Noise MapNoise Map sampling result
image-20240809001134948+image-20240809002256651=image-20240809002310226
Ramp A: Gradient of 4 color levelsNoise Map as Diffuse Ramp OffsetDiffuse Ramp A channel is offset,
Meaning the position of the light-shadow boundary is offset
image-20240809002215913=image-20240809002226413
Ramp remains unchangedNoise Map as AO- Areas where Noise is less than 1 gradually transition to shadows,
- No offset at the light-shadow boundary,
- Can create soft shadow transitions