# \[Advanced]Effect Layer Blending

If you have ever used image editing software you may be familiar with color blending between image layers. Several common color blending techniques have been added to blend LED layers together. Layers defined in the configuration are ordered top to bottom.

If there are 3 layers defined, the bottom layer is first blended with the middle layer. The resultant layer is then blended with the top. The bottom layer will never be blended with anything even if a blending mode is specified.

Layer blending is always evaluated from the bottom up.

Since values cannot exceed 100% brightness and 0% darkness, they are clamped to this range as a floating-point number ( 0.0 - 1.0 )

<table><thead><tr><th width="156">Blending Mode</th><th width="385">Description</th><th>Formula</th></tr></thead><tbody><tr><td><strong><code>bottom</code></strong></td><td><strong>bottom</strong>:No blending; uses the color from the bottom layer.</td><td>—</td></tr><tr><td><strong><code>top</code></strong></td><td><strong>top</strong>:No blending; uses the color from the top layer.</td><td>—</td></tr><tr><td><strong><code>add</code></strong></td><td><strong>add</strong>:Color channels (Red, Green, and Blue) are added together, resulting in brighter channels.</td><td>top + bottom</td></tr><tr><td><strong><code>subtract</code></strong></td><td><strong>subtract</strong>:The top layer is subtracted from the bottom layer, darkening similar colors.</td><td>bottom - top</td></tr><tr><td><strong><code>subtract_b</code></strong></td><td><strong>subtract_b</strong>:The bottom layer is subtracted from the top layer, darkening similar colors.</td><td>top - bottom</td></tr><tr><td><strong><code>difference</code></strong></td><td><strong>difference</strong>:The darker of the layers is subtracted from the brighter one.</td><td></td></tr><tr><td><strong><code>average</code></strong></td><td><strong>average:</strong>The average of the color channels is taken.</td><td>(top + bottom) / 2</td></tr><tr><td><strong><code>multiply</code></strong></td><td><strong>multiply:</strong>The channels are multiplied together, useful for darkening colors.</td><td>top * bottom</td></tr><tr><td><strong><code>divide</code></strong></td><td><strong>divide:</strong>The channels are divided, often brightening colors toward white.</td><td>top / bottom</td></tr><tr><td><strong><code>divide_inv</code></strong></td><td><strong>divide_inv:</strong>Similar to divide, but the bottom layer is divided by the top.</td><td>bottom / top</td></tr><tr><td><strong><code>screen</code></strong></td><td><strong>screen:</strong>Values are inverted, multiplied, and inverted again, resulting in brighter colors.</td><td>1 - (1 - top) * (1 - bottom)</td></tr><tr><td><strong><code>lighten</code></strong></td><td><strong>lighten:</strong>The brighter of the color channels is used.</td><td>brighter of (top, bottom)</td></tr><tr><td><strong><code>darken</code></strong></td><td><strong>darken:</strong>The darker of the color channels is used.</td><td>darker of (top, bottom)</td></tr><tr><td><strong><code>overlay</code></strong></td><td><strong>overlay:</strong>Overlay combines multiply and screen, enhancing contrast.</td><td>2 * top * bottom if top > 0.5, else 1 - 2 * (1 - top) * (1 - bottom)</td></tr></tbody></table>

## Sample Configurations

### das Blinkenlights

In the event of critical error, all LED strips breath red in unison to provide a visible indicator of an error condition with the printer. This effect is disabled during normal operation and only starts when the MCU enters a shutdown state (currently not supported).

```
[led_effect critical_error]
leds:
    neopixel:tool_lights
    neopixel:bed_lights
layers:
    strobe         1  1.5   add        (1.0,  1.0, 1.0)
    breathing      2  0     difference (0.95, 0.0, 0.0)
    static         1  0     top        (1.0,  0.0, 0.0)
autostart:                             false
frame_rate:                            24
run_on_error:                          true
```

### Bed Idle with Temperature

```
[led_effect bed_effects]
leds:
    neopixel:bed_lights
autostart:                          true
frame_rate:                         24
heater:                             heater_bed
layers:
    heater  50 0 add    (1,1,0),(1,0,0)
    static  0  0 top    (1,0,0)
```

### Brightness Controlled By Potentiometer

This is an example of how to combine the Analog Pin effect with layer blending so it controls the brightness of the lights. One could connect a potentiometer to a thermistor port and use the voltage reading from that pin to determine the amount of color to subtract from the base layers. The potentiometer would need to be wired so that when it is turned "down" the voltage on the analog pin is on full output and when it is turned up it is on minimum output. This way, when the potentiometer is "down", the color (1.0, 1.0, 1.0) (Full white) is being subtracted from the colors of the layer, resulting in (0.0, 0.0, 0.0) (Full Black). The effect rate and cutoff would need to be tuned to the specific potentiometer and board combination.

```
[led_effect bed_effects]
leds:
    neopixel:bed_lights
autostart:                          true
frame_rate:                         24
analog_pin:                         ar52
layers:
    analogpin 10 0 subtract    (1,1,1)
    static    0  0 top         (1,1,1)
```

### Progress Bar

Using a single strip of LEDs, print progress is displayed as a light blue line over a dark blue background

```
[led_effect progress_bar]
leds:
    neopixel:progress_lights
autostart:                          true
frame_rate:                         24
layers:
    progress  -1  0 add         ( 0, 0,   1),( 0, 0.1, 0.6)
    static     0  0 top         ( 0, 0, 0.1)
```
