@threlte/extras

<ImageMaterial>

Adapted from drei’s <Image> component, with additional color processing extras.

A shader-based image material component with auto-cover (similar to css/background: cover).

Images from Wikipedia. Carousel originally by Cyd Stumpel.

Example

<script lang="ts">
  import { DoubleSide } from 'three'
  import { ImageMaterial } from '@threlte/extras'
</script>

<T.Mesh>
  <T.PlaneGeometry />
  <ImageMaterial
    transparent
    side={DoubleSide}
    url="KlimtDieJungfrau.jpg"
    radius={0.1}
    zoom={1.1}
  />
<T.Mesh>

<ImageMaterial> can also be used with instanced or batched meshes.

Color processing effects

The <ImageMaterial /> component offers a range of properties for dynamic color processing.

The properties brightness, contrast, hue, saturation, and lightness adjust the image’s initial values additively. To decrease brightness, for instance, you would use a negative value, while a positive value would increase it. The hue shift is the only exception, its values range from 0 to 1, representing a complete cycle around the color wheel. Notably, values 0 and 1 are equivalent, indicating the same hue position.

For the monochrome effect, specify your preferred tint using the monochromeColor property, and control the effect’s intensity with monochromeStrength. Setting this strength to 0 disables the effect entirely, while a value of 1 applies it fully, rendering the image in varying shades of a single color.

Advanced color processing with a texture

The colorProcessingTexture property enables advanced color processing by allowing you to specify a texture that changes the strength and pattern of color effects. It can be used to create dynamic, animated effects as well as static ones that target only specified image areas.

Each texture channel controls a different color processing effect:

  • Red for hue
  • Green for saturation,
  • Blue for lightness
  • Alpha for transparency.

Red, green and blue channels are applied multiplicatively to the values of hue, saturation and lightness.

The alpha channel acts differently, providing a flexible alpha override mechanism, that uses a range of values for dynamic image reveal effect. With changing the alphaThreshold property, areas with alpha values approaching 1 are revealed first, followed by regions with values tending towards 0.

To further control this effect, the alphaSmoothing property allows for a gradual fade-in effect within a specified range. For instance, with an alphaThreshold of 0.5 and an alphaSmoothing set to 0.15, alpha values spanning from 0.5 to 0.65 will smoothly transition into visibility.

Enable “color processing with a texture” in the example on top of this page to see the effect applying RGBA color processing texture can have.

Alpha image used in the example. The lighter values towards the center are revealed first.

Order of processing effects

  1. Alpha override
  2. Brightness
  3. Contrast
  4. Hue, Saturation, Lightness
  5. Monochrome
  6. Negative

Component Signature

<ImageMaterial> extends <T.ShaderMaterial> and supports all its props, slot props, bindings and events.

Props

name
type
required
default
description

alphaSmoothing
number
no
0

alphaThreshold
number
no
0

brightness
number
no
0
Modifies brightness. Recommended range from -1 to 1.

color
THREE.ColorRepresentation
no
white

colorProcessingTexture
THREE.Texture | THREE.VideoTexture
no
Sets a texture used to adjust the strength and the pattern of color processing effects. Each channel of the texture is responsible for a different color processing function. R - hue, G - saturation, B - lightness, A - alpha.

contrast
number
no
0
Modifies contrast. Recommended range from -1 to 1.

hue
number
no
0
Modifies hue. Range from 0 to 1.

lightness
number
no
0
Modifies lightness. Recommended range from -1 to 1.

monochromeColor
THREE.ColorRepresentation
no
#535970
Sets a monochrome tint the image is converted to.

monochromeStrength
number
no
0
Sets the strength of monochrome effect. Range from 0 to 1.

negative
boolean
no
false
Enables/disables negative effect.

opacity
number
no
1

radius
number
no
0

saturation
number
no
0
Modifies saturation. Recommended range from -1 to 1.

side
THREE.Side
no
THREE.FrontSide

toneMapped
boolean
no
true

transparent
boolean
no
false

zoom
number
no
1