Material Properties
Material Properties

Material Properties

Base Color

The Base Color defines the main color of the Stencil Lights or Shadows effect.

Each Blend Mode will use the Base Color differently, but you can generally expect the final color to be a lightening or a darkening effect tinted with the Base Color. The alpha channel is ignored, except for some advanced blending modes under “Alpha Blending”. The intensity of the effect is usually set by the brightness of the Base Color.

image

Use Vertex Color?

Enable this option to use the vertex color of each rendered mesh as the base color for the effect.

For performance, we suggest using the least number of materials in your scene. If you have several different colors, performance can be improved by using the vertex color option and encoding the color information in the mesh, so you can have a single material rendering all stencil effects in your scene.

đź’ˇ
Tip: Vertex Colors with ProBuilder

If you are using ProBuilder (not included with Stencil Lights and Shadows) you can easily change mesh vertex colors using the “Vertex Colors Editor” tool. This is very useful to quickly iterate the visuals of multiple objects.

For more information, visit https://unity.com/features/probuilder

image

Show Volume

“Show Volume” enables rendering of the volume of the mesh in addition to the main effect. The rendered volume always uses the same blend mode as the main effect,

You can customize the color that is used as the base color for the volume rendering. Enable “Advanced Volume Color” for more option on how to control the color of the volume effect.

image

Strength

“Strength” controls the intensity of the volume color in comparison to the Base color.

Case
Description
Strength = 0
Keeps the same color as the Base Color
Strength > 0
Increases the intensity of the effect (lights get lighter, shadows get darker)
Strength < 0
Decreases the intensity of the effect (lights get darker, shadows get lighter)
image

Advanced Volume Colors

Advanced Volume Color provides different modes for adjusting the color of the volume, usually using the base color of the effect as a starting point for the calculation. For formulas, each color channel (RGB) is calculated independently.

  • Result = the final RGB color that will be used for the volume effect
  • Base Color = the RGB of the Base Color of the Stencil Lights and Shadows (the main effect)
  • Volume Color = the RGB provided as operand in the show volume option

Blend Modes

Basic Blend Modes

Blend modes affect how the final color of the effect will be rendered. There are two basic blend modes, which were designed to be simple to use:

Both “Light” and “Shadow” blend modes are commutative, which means that when stacked on top of themselves the result is independent of rendering order, resulting in no z-fighting. This property is not true for some of the advanced blend modes, as noted below.

Mode
Description
Light
Lightens the surrounding geometry with its intensity defined by the base color, creating the impression of a stylized light. This is the exact same effect as the Advanced Blending mode named “Screen”, which is also known as “Soft Additive”.
Shadow
Darkens the surrounding geometry with its intensity defined by the base color, creating the impression of a stylized shadow. This is the exact same effect as the Advanced Blending mode named “Multiply”.

image

Advanced Blend Modes

There are sixteen advanced blend modes, divided into six different categories.

*Difference is slightly different from the conventional Difference blend mode found in traditional image editing software. It does NOT take the absolute value of the difference. As a result, this blending mode is non-commutative, which differs from the conventional implementation.

Formulas are described using the following notation:

  • Result = the final RGB color that will be rendered
  • Base = the RGB of the Base Color of the Stencil Lights and Shadows
  • Alpha = the alpha channel of the Base Color of the Stencil Lights and Shadows
  • Background = the RGB color of the background behind the Stencil Lights and Shadows
  • 1 = (1,1,1) = White
  • 0 = (0,0,0) = Black

Colors cannot have values below zero or above one (they will be clamped accordingly). Divisions by zero result in undetermined behavior and should be avoided.

Color channels (R, G, B) are calculated independently to produce the result color. The blend mode specified applies both to the main effect of Stencil Lights and Shadows and to the effect rendered by the “Show Volume” option.

Category
Broad Description
Normal
No blending
Lighten
Final color is lighter than original
Darken
Final color is darker than original
Hybrid
Darkens or lightens
Inversion
Inverts colors and/or creates stylized effects
Alpha Blending
Uses the alpha channel to blend

image

Non-Commutativity [NC]

Blend modes that are non-commutative require more caution when used.

When overlapping two meshes with the same blending mode that in non-commutative, the result will be dependent on draw order. This can result in image artifacts “popping in and out” and z-fighting, which is often undesirable.

To mitigate this, you can either:

  • Ensure that no Stencil Lights and Shadows overlap.
  • Or use different materials for each Stencil Lights and Shadows, each with a distinct Render Queue value (this can be done in the Material Inspector itself)

image

Advanced Blend Modes

NameCommutativityCategoryFormula
Non-Commutative [NC]
Normal
RESULT = BASE
Commutative
Lighten
RESULT = MAX (BASE, BACKGROUND)
Commutative
Lighten
RESULT = 1 - (1-BASE) * (1-BACKGROUND)
Non-Commutative [NC]
Lighten
RESULT = BACKGROUND / (1-BASE)
Commutative
Lighten
RESULT = BASE + BACKGROUND
Commutative
Darken
RESULT = MIN (BASE, BACKGROUND)
Commutative
Darken
RESULT = BASE * BACKGROUND
Non-Commutative [NC]
Darken
RESULT = 1 - (1-BACKGROUND) / BASE
Commutative
Darken
RESULT = BACKGROUND + BASE - 1
Commutative
Hybrid
RESULT = 2 * BASE * BACKGROUND
Non-Commutative [NC]
Inversion
RESULT = BASE - BACKGROUND
Non-Commutative [NC]
Inversion
RESULT = BASE + BACKGROUND – 2 * BASE * BACKGROUND
Non-Commutative [NC]
Inversion
RESULT = BACKGROUND - BASE
Non-Commutative [NC]
Inversion
RESULT = BACKGROUND / BASE
Non-Commutative [NC]
Alpha Blending
RESULT = (BASE * ALPHA) + (BACKGROUND * (1-ALPHA))
Non-Commutative [NC]
Alpha Blending
RESULT = BASE + BACKGROUND * (1-ALPHA)