A source layer's pixel values push the input image around in different places.
Also known as: DisplacementMapDisplacement mapping
Moves in browsers that support WebGPU
This device could not render the demo — showing a still
Code reflects the control values
React
// Renders only in browsers with WebGPU.
// /samples/… are this site’s sample files — point them at your own image or video.
import {
Shader,
DisplacementMap,
ImageTexture,
SimplexNoise,
} from 'shaders/react'
export default function ShaderEffect() {
return (
<Shader style={{ width: '100%', height: 320 }} disableTelemetry>
<ImageTexture
objectFit="cover"
url="/samples/poster.jpg" />
<SimplexNoise
id="displacement-source"
visible={false} />
<DisplacementMap
amount={0.08}
source="displacement-source" />
</Shader>
)
}
Vue
<!-- Renders only in browsers with WebGPU. -->
<!-- /samples/… are this site’s sample files — point them at your own image or video. -->
<script setup lang="ts">
import {
Shader,
DisplacementMap,
ImageTexture,
SimplexNoise
} from 'shaders/vue'
</script>
<template>
<Shader style="width: 100%; height: 320px" :disable-telemetry="true">
<ImageTexture
object-fit="cover"
url="/samples/poster.jpg"/>
<SimplexNoise
id="displacement-source"
:visible="false"/>
<DisplacementMap
:amount="0.08"
source="displacement-source"/>
</Shader>
</template>
Svelte
<!-- Renders only in browsers with WebGPU. -->
<!-- /samples/… are this site’s sample files — point them at your own image or video. -->
<script>
import {
Shader,
DisplacementMap,
ImageTexture,
SimplexNoise,
} from 'shaders/svelte'
</script>
<Shader style="width: 100%; height: 320px" disableTelemetry>
<ImageTexture
objectFit="cover"
url="/samples/poster.jpg" />
<SimplexNoise
id="displacement-source"
visible={false} />
<DisplacementMap
amount={0.08}
source="displacement-source" />
</Shader>
Solid
// Renders only in browsers with WebGPU.
// /samples/… are this site’s sample files — point them at your own image or video.
import {
Shader,
DisplacementMap,
ImageTexture,
SimplexNoise,
} from 'shaders/solid'
export default function ShaderEffect() {
return (
<Shader style={{ width: '100%', height: '320px' }} disableTelemetry>
<ImageTexture
objectFit="cover"
url="/samples/poster.jpg" />
<SimplexNoise
id="displacement-source"
visible={false} />
<DisplacementMap
amount={0.08}
source="displacement-source" />
</Shader>
)
}
JavaScript
// Renders only in browsers with WebGPU.
// /samples/… are this site’s sample files — point them at your own image or video.
// expects <canvas id="canvas" style="width:100%;height:320px"></canvas> on the page
import { createShader } from 'shaders/js'
const shader = await createShader(document.getElementById("canvas"), {
components: [
{
type: 'ImageTexture',
props: {
objectFit: 'cover',
url: '/samples/poster.jpg',
},
},
{
type: 'SimplexNoise',
id: 'displacement-source',
props: {
visible: false,
},
},
{
type: 'DisplacementMap',
props: {
amount: 0.08,
source: 'displacement-source',
},
}
]
}, { disableTelemetry: true })
Props · DisplacementMap
Changes apply to the demo above and to the code tabs. Descriptions come from the library registry (MIT).
Name
Value
Default
Range / options
Description
sourceSource Layer
Set in code
—
The layer whose pixels drive the displacement — its red/green (or luminance) push the content around
amountAmount
0.3
0 – 1 (step 0.01)
Overall displacement strength
channelModeChannels
twoAxis
twoAxis · directional
How the source drives the push — red→X / green→Y, or luminance along a fixed angle
angleAngle
0
0 – 360 (step 1)
Push direction in degrees (used by the Luminance channel mode)
edgesEdges
mirror
stretch · transparent · mirror · wrap
How to handle edges when distortion pushes content out of bounds
Every component also takes blendMode · opacity · visible · maskSource/maskType · boundingBox · id
Like placing an uneven transparent sheet over a picture, a map layer's colors push different parts of the input by different amounts.
Choose the map with `source` and set the overall displacement with `amount`. `channelMode` uses red and green to push horizontally and vertically, or luminance to push along one direction; `angle` sets that direction.
Both the content to distort and a map layer are needed for a visible change. With no source selected, the image can pass through unchanged. Set boundary behavior with `edges`, and pair it with `WaveDistortion` or `FlowField` for rippling or fluid-like movement.
When to use
Use it for water or heat refraction, paper-like texture, and localized image movement. Avoid it when no displacement map is selected or when copy must stay crisp.