Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

reflection

PhotoAlso in3D and product

@dioramajs/media/reflectionSource

A soft reflection on a glossy floor under a product photo, without baking it into the image.

View as Markdown
On this page
  • The Blue Shore by Mara Ellison, a year of cyanotypes
  • Low Water by Ines Calder, notes from the tide line
  • Salt Garden, field notes

Live preview needs WebGPU or WebGL 2. Three books standing on a pale shelf, each with a soft reflection on the glossy surface below it.

This example failed to draw.

The reflection fades and blurs with distance. Move the sliders to change how far it reaches, how strong it is and the contact shadow.
Params of reflection

Usage

Put it on img, video. start() registers reflection, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.

To change its code, copy the source into your effects folder; the copy replaces the built-in.

Terminal window
npx @dioramajs/diorama add reflection
<div class="rf-shelf">
<ul class="rf-wall">
<li>
<img
src="/media/books/blue-shore.webp"
width="900"
height="1350"
data-dio="reflection"
data-dio-shadow="0.35"
/>
</li>
<li>
<img
src="/media/books/low-water.webp"
width="900"
height="1350"
data-dio="reflection"
data-dio-shadow="0.35"
/>
</li>
<li>
<img
src="/media/books/salt-garden.webp"
width="900"
height="1350"
data-dio="reflection"
data-dio-shadow="0.35"
/>
</li>
</ul>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('img', 'reflection', {
strength: 0.35,
reach: 0.45,
blur: 8,
gap: 0,
trim: true,
ripple: 0,
shadow: 0.35,
fps: 30,
})
import { start } from '@dioramajs/diorama'
import reflection from '@dioramajs/media/reflection'
const app = start()
app.attach('img', reflection({
strength: 0.35,
reach: 0.45,
blur: 8,
gap: 0,
trim: true,
ripple: 0,
shadow: 0.35,
fps: 30,
}))

Page transitions

Fades with the page transition. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
strengthdata-dio-strengthnumber0 to 10.35Opacity of the reflection at the base: 0 hides it and leaves only the shadow.
reachdata-dio-reachnumber0 to 10.45How far the reflection runs down, as a share of the element's height.
blurdata-dio-blurnumber0 to 40 px8Blur at the far end of the reflection, growing from sharp at the base: 0 is a mirror.At most low 0 by quality tier.
gapdata-dio-gapnumber-40 to 40 px0Space between the base and the reflection; negative pulls it up.
trimdata-dio-trimbooleantrueMirror at the lowest solid row of a transparent picture and at the drawn bottom under object-fit; false mirrors at the bottom of the box.
rippledata-dio-ripplenumber0 to 20 px0Sway of a water ripple in the reflection: 0 is a still floor.
shadowdata-dio-shadownumber0 to 10Darkness of a soft contact shadow under the base: 0 draws none.
fpsdata-dio-fpsnumber1 to 6030Frames a second the ripple draws at while visible.At most low 15 by quality tier.

Inputs and frames

It reads height, size, time and width . Draws at a steady rate while it is on screen and stops when it leaves. Once when it appears and on layout changes; with a ripple, at most fps a second while visible. None at rest. How a frame is decided.

Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. The ripple stands still; the reflection itself is not motion.

Runs on every device. The same as on desktop: the reflection does not react to input.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { reflection: { reducedMotion: 'off' } } })

Cost and quality

Download
1.9 KB min+gzip the first time a page uses it
GPU
Twelve texture reads per pixel of the reflection for the blur and eight for the shadow, only below the image.
Memory
The image as a texture; the element itself stays DOM.
Frames
Draws while on screen

It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.

TierWhat changes
lowNo blur, one texture read per pixel of the reflection; the ripple at most 15 frames a second.

Recipes

A product cutout on a glossy shelf

For e-commerce product shots, a transparent PNG or WebP gets a reflection below it without baking one into the image. Leave room under the image with a margin: the reflection draws below the element’s box and never shifts the layout.

<img
src="/shop/speaker.png"
data-dio="reflection"
data-dio-shadow="0.35"
style="margin-bottom: 160px"
/>

A phone mockup on dark glass

A lower strength, a short reach and a little blur read as dark glass.

<img
src="/app/phone.png"
data-dio="reflection"
data-dio-strength="0.25"
data-dio-reach="0.3"
data-dio-blur="4"
/>

A photo over still water

On a full photo the bottom edge is mirrored; ripple adds a gentle wave, as over water.

<img
src="/stays/boathouse.avif"
data-dio="reflection"
data-dio-strength="0.6"
data-dio-reach="0.6"
data-dio-ripple="6"
/>

Notes

The reflection takes no clicks and adds nothing to the page layout; give the image room below with a margin. Under reduced motion the ripple stands still.