Subtractive color mixing for Kotlin and Compose

Standard RGB interpolation mixes light channels linearly, so complementary pairs such as yellow and blue pass through neutral gray. Vibrance converts sRGB colors into a latent space of real-world paint pigment concentrations, mixes those concentrations, and converts the result back to sRGB.

Latent pigment space
Models Phthalo Blue (Green Shade), Quinacridone Magenta, Hansa Yellow, and Titanium White concentrations plus an RGB remainder so every input sRGB color round-trips accurately.
Kotlin Multiplatform
Runs on Android, JVM, iOS, macOS, JS, and Wasm. The core module has zero UI dependencies and supports allocation-free mixing in tight loops.
Compose shaders
Provides vertical, horizontal, linear, radial, and sweep gradient modifiers and brushes backed by runtime shaders with triangle-noise dithering.

Interactive gradient

Choose start and end colors or select a preset below. Both canvases are rendered directly in JavaScript using a port of the Vibrance neural pigment model and shader dithering pass.

Geometry
Presets
Vibrance 50%: #1F9397
Standard sRGB 50%: #808080

Static gradient examples

Representative color pairs across linear, radial, and sweep geometries. Each example pairs Vibrance with standard sRGB interpolation for the same endpoints.

Yellow to Blue

#FFFF00 → #0000FF · Linear

Vibrance
Standard sRGB

Hansa Yellow and Phthalo Blue transition through green and teal instead of collapsing to neutral gray at the midpoint.

Yellow to Red

#FFFF00 → #FF0000 · Linear

Vibrance
Standard sRGB

Pigment interpolation preserves chroma through warm cadmium-like oranges rather than dimming in the middle of the ramp.

White to Blue

#FFFFFF → #0000FF · Linear

Vibrance
Standard sRGB

Diluting Phthalo Blue with Titanium White produces cool cerulean tints instead of a chalky periwinkle ramp.

Cyan to Magenta

#00FFFF → #FF00FF · Linear

Vibrance
Standard sRGB

Subtractive mixing routes Cyan and Quinacridone Magenta through saturated cobalt and violet tones rather than pale lavender.

Magenta to Yellow

#FF00FF → #FFFF00 · Radial

Vibrance
Standard sRGB

Radial falloff from Quinacridone Magenta to Hansa Yellow moves through scarlet and orange instead of salmon pink.

Yellow to Blue

#FFFF00 → #0000FF · Sweep

Vibrance
Standard sRGB

Angular interpolation around the center point preserves hue progression across the full 360° sweep.

Using Vibrance in Kotlin

Vibrance is published on Maven Central as two artifacts: vibrance for standalone color mixing and vibrance-compose for Jetpack Compose and Compose Multiplatform integration.

1. Add the dependencies

Add vibrance for core sRGB and latent pigment mixing, and vibrance-compose if you are rendering gradients in Compose.

Android API requirement: vibrance-compose modifiers and brushes require Android API level 33+ (RuntimeShader). Desktop, iOS, macOS, JS, and Wasm targets use Skia RuntimeEffect. The core vibrance module has no minimum API restriction.

build.gradle.kts
dependencies {
    // Core pigment mixing (Android, JVM, iOS, macOS, JS, Wasm)
    implementation("dev.romainguy:vibrance:0.4.0")

    // Compose modifiers, brushes, and Color extensions
    implementation("dev.romainguy:vibrance-compose:0.4.0")
}

2. Mix colors with the core library

Create an instance of Vibrance to mix sRGB channels in the 0.0f..1.0f range. Note that Vibrance reuses internal scratch buffers and is not thread-safe; keep one instance per thread.

Upscaling an sRGB color into the latent space runs a small neural network and is the main cost of a mix. When interpolating between the same pair of colors repeatedly (such as during an animation) precompute both 6-float latent arrays once with colorToLatentColor and interpolate them with latentColorsMix. You can also pass your own FloatArray buffers to avoid allocations.

ColorMixing.kt
import dev.romainguy.vibrance.Vibrance

val vibrance = Vibrance()

// Direct one-off mix between Yellow (1, 1, 0) and Blue (0, 0, 1)
val mixed: FloatArray = vibrance.colorsMix(
    srcR = 1.0f, srcG = 1.0f, srcB = 0.0f,
    dstR = 0.0f, dstG = 0.0f, dstB = 1.0f,
    amount = 0.25f
)

// Repeated interpolation: precompute 6-float latent colors once
val latentYellow = FloatArray(6)
val latentBlue = FloatArray(6)
vibrance.colorToLatentColor(1.0f, 1.0f, 0.0f, latentYellow)
vibrance.colorToLatentColor(0.0f, 0.0f, 1.0f, latentBlue)

// Reuse an output FloatArray(3) for allocation-free per-frame mixing
val outRgb = FloatArray(3)
vibrance.latentColorsMix(latentYellow, latentBlue, amount = 0.25f, color = outRgb)

3. Apply gradient modifiers in Compose

vibrance-compose provides draw modifiers that render pigment-mixed gradients directly on a composable without extra wrapper boxes:

  • Modifier.verticalPigmentsGradient
  • Modifier.horizontalPigmentsGradient
  • Modifier.linearPigmentsGradient
  • Modifier.radialPigmentsGradient
  • Modifier.sweepPigmentsGradient

All gradient types except sweep support TileMode.Clamp, TileMode.Repeated, TileMode.Mirror, and TileMode.Decal.

GradientModifiersExample.kt
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import dev.romainguy.vibrance.compose.horizontalPigmentsGradient
import dev.romainguy.vibrance.compose.verticalPigmentsGradient

Box(
    Modifier
        .fillMaxSize()
        .verticalPigmentsGradient(
            startColor = Color.Yellow,
            endColor = Color.Blue
        )
)

Box(
    Modifier
        .fillMaxWidth()
        .height(120.dp)
        .horizontalPigmentsGradient(
            startColor = Color.Yellow,
            endColor = Color.Red
        )
)

4. Use brushes and Compose Color extensions

Matching Brush factory methods—Brush.verticalPigmentsGradient, Brush.horizontalPigmentsGradient, Brush.linearPigmentsGradient, Brush.radialPigmentsGradient, and Brush.sweepPigmentsGradient—work anywhere Compose accepts a Brush, including shapes, borders, Canvas draw calls, and TextStyle.

The module also adds extension functions on Vibrance that accept and return Compose Color instances directly, converting non-sRGB inputs automatically.

BrushesAndColorsExample.kt
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import dev.romainguy.vibrance.Vibrance
import dev.romainguy.vibrance.compose.colorsMix
import dev.romainguy.vibrance.compose.horizontalPigmentsGradient

Text(
    text = "Pigment-mixed text gradient",
    style = MaterialTheme.typography.headlineMedium.copy(
        brush = Brush.horizontalPigmentsGradient(Color.Cyan, Color.Magenta)
    )
)

// Compose Color extension on Vibrance
val vibrance = Vibrance()
val green: Color = vibrance.colorsMix(Color.Yellow, Color.Blue, amount = 0.25f)