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

Port a GLSL shader

Put a GLSL fragment shader in the effects folder and use it as an effect, then add typed params, fix converter errors or port it to TSL by hand.

View as Markdown
On this page

Diorama draws with the three.js WebGPURenderer, so its shaders are TSL nodes. @dioramajs/glsl converts GLSL written for ShaderMaterial, Shadertoy or The Book of Shaders into TSL at build time and turns the file into an effect. The converter runs in Node; the browser gets only the generated TSL. This guide ports rgb-shift, a channel split driven by scroll speed with noise and grain.

Add the plugin

Install the package and add its Vite plugin next to the Diorama plugin. With both, every .frag file in the effects folder is an effect, named after the file.

Terminal window
npm install @dioramajs/glsl
Terminal window
pnpm add @dioramajs/glsl
Terminal window
yarn add @dioramajs/glsl
Terminal window
bun add @dioramajs/glsl
vite.config.ts
import {
function glsl(options?: GlslPluginOptions): Plugin

Vite plugin that turns GLSL files into TSL shaders and effects on import.

glsl
} from '@dioramajs/glsl/vite'
import {
function diorama(options?: DioramaPluginOptions): Plugin

Vite plugin, plugins: [diorama()].

diorama
} from '@dioramajs/diorama/vite'
export default {
plugins: Plugin<any>[]
plugins
: [
function diorama(options?: DioramaPluginOptions): Plugin

Vite plugin, plugins: [diorama()].

diorama
(),
function glsl(options?: GlslPluginOptions): Plugin

Vite plugin that turns GLSL files into TSL shaders and effects on import.

glsl
()] }
astro.config.mjs
import { glsl } from '@dioramajs/glsl/vite'
import diorama from '@dioramajs/diorama/astro'
export default {
integrations: [diorama()],
vite: { plugins: [glsl()] },
}
nuxt.config.ts
import { glsl } from '@dioramajs/glsl/vite'
export default defineNuxtConfig({
modules: ['@dioramajs/diorama/nuxt'],
vite: { plugins: [glsl()] },
})

Next.js builds with webpack or Turbopack, which use the loader instead of the Vite plugin. See Next.js and the CLI.

A page without a build converts its shaders ahead of time with the CLI. See Next.js and the CLI.

Add the import types to tsconfig.json, so TypeScript knows the ?shader, ?effect and ?entry imports used below.

tsconfig.json
{
"compilerOptions": {
"types": ["vite/client", "@dioramajs/glsl/client"]
}
}

Copy the shader

Save the GLSL as it is in the effects folder. src/effects/rgb-shift.frag becomes the effect rgb-shift; names are the file name in kebab case, so rgb_shift.frag gives the same name.

src/effects/rgb-shift.frag
uniform sampler2D uTexture;
uniform float uTime;
uniform float uVelocity;
uniform float uStrength; // @default 0.02
uniform float uGrain; // @default 0.06
varying vec2 vUv;
float hash(vec2 p) {
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),
mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
}
void main() {
float n = noise(vec2(vUv.y * 40.0, uTime * 4.0)) - 0.5;
vec2 shift = vec2(uStrength * uVelocity + n * 0.004 * abs(uVelocity), 0.0);
vec4 base = texture2D(uTexture, vUv);
float r = texture2D(uTexture, vUv + shift).r;
float b = texture2D(uTexture, vUv - shift).b;
float grain = (hash(vUv * 500.0 + uTime) - 0.5) * uGrain;
gl_FragColor = vec4(vec3(r, base.g, b) + grain, base.a);
}

Put the effect on an image like any other.

index.html
<img
src="/cover.jpg"
data-dio="rgb-shift"
data-dio-strength="0.04"
/>
Paper ridges at dusk

Live preview needs WebGPU or WebGL 2. A photo with the rgb-shift shader: scrolling the page fast splits its red and blue channels, at rest only the grain moves.

This example failed to draw.

Scroll this page fast to split the channels. The example uses the default strength of 0.02.
<img
src="/media/ridges.jpg"
width="800"
height="450"
data-dio="rgb-shift"
/>
uniform sampler2D uTexture;
uniform float uTime;
uniform float uVelocity;
uniform float uStrength; // @default 0.02
uniform float uGrain; // @default 0.06
varying vec2 vUv;
float hash(vec2 p) {
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),
mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
}
void main() {
float n = noise(vec2(vUv.y * 40.0, uTime * 4.0)) - 0.5;
vec2 shift = vec2(uStrength * uVelocity + n * 0.004 * abs(uVelocity), 0.0);
vec4 base = texture2D(uTexture, vUv);
float r = texture2D(uTexture, vUv + shift).r;
float b = texture2D(uTexture, vUv - shift).b;
float grain = (hash(vUv * 500.0 + uTime) - 0.5) * uGrain;
gl_FragColor = vec4(vec3(r, base.g, b) + grain, base.a);
}

Read the bindings

Uniforms bind by name. The plugin strips the u or u_ prefix, so uWaveSize and u_wave_size both read as waveSize, and binds a uniform to an input when the name and the type match. In development it prints one line per file on first load.

Terminal window
rgb-shift.frag: uTexture→media, uTime→input:time, uVelocity→input:velocity, uStrength→param:strength, uGrain→param:grain
Uniform name, typeGets
The sampler2D named texture, tex, map, image, diffuse, tDiffuse, tMap, iChannel0, or the only oneThe element’s picture, cropped like object-fit, with its masks
time, globalTime (float)Seconds that stand still off screen and under reduced motion
hoverTime (float)Seconds that run only under the pointer and while hover fades
mouse, pointer, cursor (vec2)Pointer in box UV, 0 to 1, y up
u_mouse (vec2), iMouse (vec4)Pointer in device pixels of the box
resolution, res (vec2), iResolution (vec3)Box size in device pixels
imageSize, planeSize, meshSize, quadSize, textureSize (vec2)Box size in CSS pixels
hover, hoverProgress (float)Hover, 0 to 1
progress, scrollProgress (float)Pass of the element through the viewport, 0 to 1
velocity, scrollVelocity (float)Scroll speed, -1 to 1, where 3000 px a second is 1
pin, pinProgress (float)Progress of a pinned section
vec3 or vec4 with color in the nameA color param
Any other float, int, bool, vec2 to vec4A param: uStrength is data-dio-strength

vUv and its usual spellings (vUV, v_uv, vTexCoord, vTextureCoord) are the box UV after the uv functions of other effects on the element. A param without // @default starts at 0 with a GLSL_PARAM_DEFAULT warning. uOpacity and uAlpha stay plain params, since the picture already follows the CSS opacity of the element.

Steer it with pragmas

A comment after a uniform overrides its binding. A // @diorama line sets options for the whole file. The file wins over the plugin options and the CLI flags.

// @diorama name=swell stage=uv|color colorSpace=srgb|linear segments=64 bleed=40 animate=input|hover|visible
uniform float uStrength; // @default 0.02
uniform vec2 uCenter; // @default 0.5 0.5
uniform vec2 uMouse; // @input pointerNdc
uniform float uProgress; // @param reveal @default 0
uniform vec3 uTint; // @color #ff8800
uniform sampler2D uDisp; // @texture ./disp.png
uniform sampler2D uPic; // @media

@param reveal keeps a uniform named like an input as a param of your own, for a studio shader that tweens uProgress itself. @texture loads a second texture next to the shader. @media names the sampler that gets the element’s picture when the names do not tell.

The same line takes the options that decide where and how the effect runs: when (a media query, see Reduced motion), reducedMotion (static or off) and presence (fade or custom). Quote a media query with spaces.

// @diorama when=hover reducedMotion=off presence=custom
// @diorama when="(min-width: 768px)"

A value outside these fails the conversion with GLSL_PRAGMA.

Check the frames

The converter picks the frame policy from what the shader reads. uTime draws every frame while the element is on screen, uHoverTime or uHover only around hover, and anything else only on input. rgb-shift reads time and velocity, so the converter adds the note GLSL_ANIMATE: a shader that moves only under the pointer saves frames with uHoverTime in place of uTime. Here the grain is meant to move at rest, so the policy stays.

It also adds GLSL_SEMANTICS for uVelocity. Diorama’s velocity runs from -1 to 1, while a shader written for Lenis may expect pixels per frame; scale the uniform if the split looks too weak or too strong.

Add a glue file

A TypeScript file with the same name as the shader takes its place in the folder. Use it for typed params and for effect options that a pragma cannot set, such as a frame cap.

src/effects/rgb-shift.ts
import {
function glslEffect<
S extends ParamSpec,
const O extends ParamSpec = Empty
>(
shader: GlslSource<S>,
options?:
& GlslEffectOptions<MergeParams<S, O>>
& { readonly params?: O; }
& CheckParams<O>
): Effect<WidenSpec<MergeParams<S, O>>>

Wraps a GLSL stage pair as an effect. Bindings, params and varyings are checked up front and reported together as one EFFECT_DEFINITION.

@throws ― {EffectError} EFFECT_DEFINITION with every problem found.

glslEffect
} from '@dioramajs/glsl'
import
const shader: GlslShader<ParamSpec>
shader
from './rgb-shift.frag?shader'
export default
glslEffect<ParamSpec, U>(
shader: GlslSource<ParamSpec>,
options?:
| (
GlslEffectOptions<U>
& { readonly params?: U | undefined; }
& CheckParams<U>
)
| undefined
): Effect<WidenSpec<U>>
type U = {
readonly strength: 0.02;
readonly grain: 0.06;
}

Wraps a GLSL stage pair as an effect. Bindings, params and varyings are checked up front and reported together as one EFFECT_DEFINITION.

@throws ― {EffectError} EFFECT_DEFINITION with every problem found.

glslEffect
(
const shader: GlslShader<ParamSpec>
shader
, {
params?:
| (
{ readonly strength: 0.02; readonly grain: 0.06; }
& CheckSpec<
{ readonly strength: 0.02; readonly grain: 0.06; }
>
)
| undefined

Override the shader's pragma defaults. Their types become the param types.

params
: {
strength: 0.02
strength
: 0.02,
grain: 0.06
grain
: 0.06 },
// The grain moves at 24 frames a second; scroll frames run at full rate.
animate?:
| AnimatePolicy<
{ readonly strength: 0.02; readonly grain: 0.06; }
>
| undefined

Defaults to the update's answer when it returns a boolean, else to what the effect reads: time animates every visible frame, hoverTime while hovered or hover decays, neither means 'input'.

animate
: {
fps:
| number
| (
(
ctx: EffectContext<
{ readonly strength: 0.02; readonly grain: 0.06; }
>
) => number
)
fps
: 24 },
})

The params of the glue override the defaults of the shader, and the effect types in src/diorama.gen.d.ts now carry strength and grain as numbers. glslEffect takes the other options of effect() too: when, reducedMotion, presence, rebuild, bleed. uniforms rebinds a uniform by GLSL name, as a binding string such as 'input:hover' or as a function of the effect context.

src/effects/dissolve.ts
import {
function glslEffect<
S extends ParamSpec,
const O extends ParamSpec = Empty
>(
shader: GlslSource<S>,
options?:
& GlslEffectOptions<MergeParams<S, O>>
& { readonly params?: O; }
& CheckParams<O>
): Effect<WidenSpec<MergeParams<S, O>>>

Wraps a GLSL stage pair as an effect. Bindings, params and varyings are checked up front and reported together as one EFFECT_DEFINITION.

@throws ― {EffectError} EFFECT_DEFINITION with every problem found.

glslEffect
} from '@dioramajs/glsl'
import
const shader: GlslShader<ParamSpec>
shader
from './dissolve.frag?shader'
// A page transition fades the copy through
// u.presence; this shader draws it as a dissolve.
export default
glslEffect<ParamSpec, Empty>(
shader: GlslSource<ParamSpec>,
options?:
| (
GlslEffectOptions<Empty>
& { readonly params?: Empty | undefined; }
& CheckParams<Empty>
)
| undefined
): Effect<WidenSpec<Empty>>

Wraps a GLSL stage pair as an effect. Bindings, params and varyings are checked up front and reported together as one EFFECT_DEFINITION.

@throws ― {EffectError} EFFECT_DEFINITION with every problem found.

glslEffect
(
const shader: GlslShader<ParamSpec>
shader
, {
presence?: "fade" | "custom" | undefined

Page transitions. 'fade' (default) multiplies the copy's alpha by u.presence. With 'custom' the effect reads u.presence or input.presence itself.

presence
: 'custom',
GlslEffectOptions<Empty>.uniforms?: {
readonly [uniform: string]: Binding
| ((ctx: EffectContext<Empty>) => Node);
}
| undefined

Binding overrides, keyed by GLSL uniform name.

uniforms
: {
uPresence: (
ctx: EffectContext<Empty>
) => UniformNode<"float">
uPresence
: (
ctx: EffectContext<Empty>
ctx
) =>
ctx: EffectContext<Empty>
ctx
.
EffectContext<Empty>.u: Uniforms<Empty>

Input uniforms and one uniform per live param, for TSL graphs.

u
.
InputUniforms.presence: UniformNode<"float">

1 at rest, 0..1 while the copy enters or leaves a page.

presence
},
})

Fix what the converter reports

All errors of one file come together, each with the file, the line, the column and a one-line hint. In Vite they show in the error overlay. The development server checks every shader in the project at start and on save, so a broken shader on a distant page shows up at once.

CodeWhat happenedWhat to do
GLSL_SYNTAXInvalid syntax, or a name that starts with _Fix the line; if the GLSL is valid, port that function by hand
GLSL_NO_ENTRYNo main or mainImageBring a library file in with #include, not with an import
GLSL_INCLUDEThe file is missing, includes itself, or is a three.js #include <chunk>Use a path relative to the file or a package; paste three.js chunks as text
GLSL_ARRAYAn arrayUnroll it into variables or port the function by hand
GLSL_INOUTAn out or inout parameterReturn a value or a struct
GLSL_EARLY_RETURNreturn inside a loopMove the condition into the loop or use break
GLSL_GLOBAL_STATEA global variable that changesMake it local to main or a function parameter
GLSL_SAMPLERIt is not clear which sampler is the picture, or texelFetch reads itAdd // @media; read the picture with texture()
GLSL_VERTEXcameraPosition, gl_PointSize or no gl_Position writeKeep the vertex shader to moving the plane
GLSL_UNKNOWN_IDENTIFIERA name declared nowhere, such as iFrame or iDateDeclare a uniform or remove the Shadertoy input
GLSL_UNKNOWN_FUNCTIONA function neither in the shader nor in TSLCheck the similar names in the message, or supply it from TypeScript
GLSL_PRAGMAA // @diorama line has a bad when, reducedMotion or presenceUse a listed value; quote a media query with spaces

Some GLSL turns into code that three.js r187 runs wrong without a word: a local changed later, an early return inside if, a write to a parameter’s component, mat2 from four numbers, integer division. The converter rewrites these itself and lists each fix as a note in the CLI output.

Supply one function from TypeScript

When one function does not convert, leave its prototype in the GLSL and give the body in TSL. The rest stays GLSL.

src/effects/mist.frag
float noise(vec2 p); // the body comes from TypeScript
void main() {
gl_FragColor = vec4(vec3(noise(vUv * 8.0)), 1.0);
}
src/effects/mist.ts
import {
function glslEffect<
S extends ParamSpec,
const O extends ParamSpec = Empty
>(
shader: GlslSource<S>,
options?:
& GlslEffectOptions<MergeParams<S, O>>
& { readonly params?: O; }
& CheckParams<O>
): Effect<WidenSpec<MergeParams<S, O>>>

Wraps a GLSL stage pair as an effect. Bindings, params and varyings are checked up front and reported together as one EFFECT_DEFINITION.

@throws ― {EffectError} EFFECT_DEFINITION with every problem found.

glslEffect
} from '@dioramajs/glsl'
import {
const dot: (
x: FloatVector,
y: FloatVector
) => Node<"float">
dot
,
const fract: UnaryFloatVecFunction
fract
,
const sin: UnaryFloatVecFunction
sin
,
const vec2: Vec2Function
vec2
} from 'three/tsl'
import type {
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
const Node: {
new <TNodeType>(nodeType?: TNodeType | null): Node<TNodeType>;
new (nodeType?: string | null): Node;
captureStackTrace: boolean;
}
Node
} from 'three/webgpu'
import
const shader: GlslShader<ParamSpec>
shader
from './mist.frag?shader'
// Type the arguments as the prototype declares them.
const
const noise: (p: Node<"vec2">) => Node<"float">
noise
= (
p: Node<"vec2">
p
:
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
Node
<'vec2'>) =>
function fract(x: FloatOrNumber): Node<"float"> (+3 overloads)
fract
(
function sin(x: FloatOrNumber): Node<"float"> (+3 overloads)
sin
(
function dot(x: FloatVector, y: FloatVector): Node<"float">
dot
(
p: Node<"vec2">
p
,
function vec2(x?: number, y?: number): ConstNode<
"vec2",
Vector2
> (+4 overloads)
vec2
(12.9898, 78.233))).
mul: (
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+7 overloads)
mul
(43758.5453))
export default
glslEffect<ParamSpec, Empty>(
shader: GlslSource<ParamSpec>,
options?:
| (
GlslEffectOptions<Empty>
& { readonly params?: Empty | undefined; }
& CheckParams<Empty>
)
| undefined
): Effect<WidenSpec<Empty>>

Wraps a GLSL stage pair as an effect. Bindings, params and varyings are checked up front and reported together as one EFFECT_DEFINITION.

@throws ― {EffectError} EFFECT_DEFINITION with every problem found.

glslEffect
(
const shader: GlslShader<ParamSpec>
shader
, {
GlslEffectOptions<Empty>.functions?: {
readonly [name: string]: ShaderFunction;
}
| undefined

Bodies for GLSL prototypes, written in TSL.

functions
: {
noise: (p: Node<"vec2">) => Node<"float">
noise
} })

Port it by hand

A hand port is an ordinary effect file, and it is the way to go when you want to change the shader in TypeScript from now on. Map each GLSL construct to TSL; the imports come from three/tsl.

GLSLTSL
a + b, a * b, -aa.add(b), a.mul(b), a.negate()
1.0 - xx.oneMinus()
float x = 1.0; x += y;const x = float(1).toVar(); x.addAssign(y)
float lum = dot(c.rgb, w);const lum = dot(c.rgb, w).toConst() when c changes later
c ? a : bselect(c, a, b)
if (c) { ... } else { ... }If(c, () => { ... }).Else(() => { ... }) inside Fn
for (int i = 0; i < n; i++) { ... }Loop({ start: 0, end: n, type: 'int' }, ({ i }) => { ... })
discard;Discard() inside Fn(() => { ... })()
texture2D(uTexture, uv)sample(uv) in surface.color; sample(clamp(uv, 0, 1)) for the edge
gl_FragColor = c;Return c from surface.color
gl_Position = ...Return the position from surface.position
uniform float uTime;u.time; params are u.<name>
varying float vWave; written in .vertconst vWave = varying(expr)

sample() returns linear color, while ShaderMaterial math usually runs on raw sRGB values. For a pixel-exact match, convert around the math with sRGBTransferOETF and sRGBTransferEOTF, as the port below does.

src/effects/rgb-shift.ts
import {
function effect(
setup: EffectSetup<Empty>
): Effect<Empty> (+2 overloads)

Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its registry key (the file name when a build plugin finds it).

export default effect({ strength: 1 }, ({ surface, u }) => { ... })

effect
} from '@dioramajs/diorama'
import {
const abs: UnaryNumVecFunction
abs
,
const clamp: Clamp
clamp
,
const dot: (
x: FloatVector,
y: FloatVector
) => Node<"float">
dot
,
function Fn<TReturn>(
jsFunc: (builder: NodeBuilder) => TReturn,
layout?: Layout | string
): FnNode<[], TReturn> (+2 overloads)
Fn
,
const floor: UnaryFloatVecFunction
floor
,
const fract: UnaryFloatVecFunction
fract
,
const mix: Mix
mix
,
const sRGBTransferEOTF: (color: Node) => Node
sRGBTransferEOTF
,
const sRGBTransferOETF: (color: Node) => Node
sRGBTransferOETF
,
const vec2: Vec2Function
vec2
,
const vec3: Vec3Function
vec3
,
const vec4: Vec4Function
vec4
,
} from 'three/tsl'
import type {
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
const Node: {
new <TNodeType>(nodeType?: TNodeType | null): Node<TNodeType>;
new (nodeType?: string | null): Node;
captureStackTrace: boolean;
}
Node
} from 'three/webgpu'
const
const hash: (p: Node<"vec2">) => Node<"float">
hash
= (
p: Node<"vec2">
p
:
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
Node
<'vec2'>):
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
Node
<'float'> => {
const
const q: Node<"vec2">
q
=
function fract(x: Vec2): Node<"vec2"> (+3 overloads)
fract
(
p: Node<"vec2">
p
.
mul: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+6 overloads)
mul
(
function vec2(x?: number, y?: number): ConstNode<
"vec2",
Vector2
> (+4 overloads)
vec2
(123.34, 456.21)))
const
const r: Node<"vec2">
r
=
const q: Node<"vec2">
q
.
add: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+3 overloads)
add
(
function dot(x: FloatVector, y: FloatVector): Node<"float">
dot
(
const q: Node<"vec2">
q
,
const q: Node<"vec2">
q
.
add: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+3 overloads)
add
(45.32)))
return
function fract(x: FloatOrNumber): Node<"float"> (+3 overloads)
fract
(
const r: Node<"vec2">
r
.
Swizzle1From1<"float">.x: Node<"float">
x
.
mul: (
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+7 overloads)
mul
(
const r: Node<"vec2">
r
.
Swizzle1From2<"float">.y: Node<"float">
y
))
}
const
const noise: (p: Node<"vec2">) => Node<"float">
noise
= (
p: Node<"vec2">
p
:
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
Node
<'vec2'>):
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
Node
<'float'> => {
const
const i: Node<"vec2">
i
=
function floor(x: Vec2): Node<"vec2"> (+3 overloads)
floor
(
p: Node<"vec2">
p
)
const
const f: Node<"vec2">
f
=
function fract(x: Vec2): Node<"vec2"> (+3 overloads)
fract
(
p: Node<"vec2">
p
)
const
const u: Node<"vec2">
u
=
const f: Node<"vec2">
f
.
mul: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+6 overloads)
mul
(
const f: Node<"vec2">
f
).
mul: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+6 overloads)
mul
(
const f: Node<"vec2">
f
.
mul: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+6 overloads)
mul
(-2).
add: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+3 overloads)
add
(3))
return
function mix(
a: FloatOrNumber,
b: FloatOrNumber,
t: FloatOrNumber
): Node<"float"> (+3 overloads)
mix
(
function mix(
a: FloatOrNumber,
b: FloatOrNumber,
t: FloatOrNumber
): Node<"float"> (+3 overloads)
mix
(
const hash: (p: Node<"vec2">) => Node<"float">
hash
(
const i: Node<"vec2">
i
),
const hash: (p: Node<"vec2">) => Node<"float">
hash
(
const i: Node<"vec2">
i
.
add: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+3 overloads)
add
(
function vec2(x?: number, y?: number): ConstNode<
"vec2",
Vector2
> (+4 overloads)
vec2
(1, 0))),
const u: Node<"vec2">
u
.
Swizzle1From1<"float">.x: Node<"float">
x
),
function mix(
a: FloatOrNumber,
b: FloatOrNumber,
t: FloatOrNumber
): Node<"float"> (+3 overloads)
mix
(
const hash: (p: Node<"vec2">) => Node<"float">
hash
(
const i: Node<"vec2">
i
.
add: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+3 overloads)
add
(
function vec2(x?: number, y?: number): ConstNode<
"vec2",
Vector2
> (+4 overloads)
vec2
(0, 1))),
const hash: (p: Node<"vec2">) => Node<"float">
hash
(
const i: Node<"vec2">
i
.
add: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+3 overloads)
add
(
function vec2(x?: number, y?: number): ConstNode<
"vec2",
Vector2
> (+4 overloads)
vec2
(1, 1))),
const u: Node<"vec2">
u
.
Swizzle1From1<"float">.x: Node<"float">
x
),
const u: Node<"vec2">
u
.
Swizzle1From2<"float">.y: Node<"float">
y
,
)
}
export default
effect<P>(
params: P & CheckSpec<P>,
setup: EffectSetup<ColorsIn<P>>
): Effect<WidenSpec<P>> (+2 overloads)
type P = {
readonly strength: 0.02;
readonly grain: 0.06;
}

Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its registry key (the file name when a build plugin finds it).

export default effect({ strength: 1 }, ({ surface, u }) => { ... })

effect
(
{
strength: 0.02
strength
: 0.02,
grain: 0.06
grain
: 0.06 },
({
surface: Surface

The shared GL copy of the element, created on first access.

surface
,
u: Uniforms<
ColorsIn<{ readonly strength: 0.02; readonly grain: 0.06; }>
>

Input uniforms and one uniform per live param, for TSL graphs.

u
}) => {
surface: Surface

The shared GL copy of the element, created on first access.

surface
.
Surface.color(
transform: (color: Node<"vec4">, input: SurfaceInput) => Node
): Off

Changes the colour. sample(uv) reads the element's media with crop and masks applied.

color
((
_: Node<"vec4">
_
, {
uv: Node<"vec2">

Box UV after all uv transforms.

uv
,
sample: (uv: Node<"vec2">) => Node<"vec4">

The element's media at box UV with crop, contain and radius masks applied; vec4(0) without media.

sample
}) =>
Fn<JoinNode<"vec4">>(
jsFunc: (builder: NodeBuilder) => JoinNode<"vec4">,
layout?: Layout | string
): FnNode<[], JoinNode<"vec4">> (+2 overloads)
Fn
(() => {
// The GLSL works on raw sRGB values.
const
const raw: (at: Node<"vec2">) => Node<"vec3">
raw
= (
at: Node<"vec2">
at
:
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
Node
<'vec2'>) =>
function sRGBTransferOETF(color: Node): Node
sRGBTransferOETF
(
sample: (uv: Node<"vec2">) => Node<"vec4">

The element's media at box UV with crop, contain and radius masks applied; vec4(0) without media.

sample
(
function clamp(
value: Vec2OrFloat,
low?: Vec2OrFloat,
high?: Vec2OrFloat
): Node<"vec2"> (+3 overloads)
clamp
(
at: Node<"vec2">
at
, 0, 1)).
Swizzle3From3<"float">.rgb: Node<"vec3">
rgb
) as
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
Node
<'vec3'>
const
const n: Node<"float">
n
=
const noise: (p: Node<"vec2">) => Node<"float">
noise
(
function vec2(
x: Scalar,
y: Scalar
): JoinNode<"vec2"> (+4 overloads)
vec2
(
uv: Node<"vec2">

Box UV after all uv transforms.

uv
.
Swizzle1From2<"float">.y: Node<"float">
y
.
mul: (
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+7 overloads)
mul
(40),
u: Uniforms<
ColorsIn<{ readonly strength: 0.02; readonly grain: 0.06; }>
>

Input uniforms and one uniform per live param, for TSL graphs.

u
.
InputUniforms.time: UniformNode<"float">

Seconds that advance only while visible. Frozen under reduced motion.

time
.
mul: (
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+7 overloads)
mul
(4))).
NumExtensions<"float">.sub: AddSubMulDivNumberVecNumExtensions
(
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+3 overloads)
sub
(0.5)
const
const jitter: Node<"float">
jitter
=
const n: Node<"float">
n
.
mul: (
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+7 overloads)
mul
(0.004).
mul: (
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+7 overloads)
mul
(
function abs(x: FloatOrNumber): Node<"float"> (+11 overloads)
abs
(
u: Uniforms<
ColorsIn<{ readonly strength: 0.02; readonly grain: 0.06; }>
>

Input uniforms and one uniform per live param, for TSL graphs.

u
.
InputUniforms.velocity: UniformNode<"float">

Scroll velocity in -1..1 (3000 px/s is 1), positive scrolling down. 0 under reduced motion.

velocity
))
const
const shift: JoinNode<"vec2">
shift
=
function vec2(
x: Scalar,
y: Scalar
): JoinNode<"vec2"> (+4 overloads)
vec2
(
u: Uniforms<
ColorsIn<{ readonly strength: 0.02; readonly grain: 0.06; }>
>

Input uniforms and one uniform per live param, for TSL graphs.

u
.
strength: UniformNode<"float">
strength
.
mul: (
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+7 overloads)
mul
(
u: Uniforms<
ColorsIn<{ readonly strength: 0.02; readonly grain: 0.06; }>
>

Input uniforms and one uniform per live param, for TSL graphs.

u
.
InputUniforms.velocity: UniformNode<"float">

Scroll velocity in -1..1 (3000 px/s is 1), positive scrolling down. 0 under reduced motion.

velocity
).
NumExtensions<"float">.add: AddSubMulDivNumberVecNumExtensions
(
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+3 overloads)
add
(
const jitter: Node<"float">
jitter
), 0)
const
const grain: Node<"float">
grain
=
const hash: (p: Node<"vec2">) => Node<"float">
hash
(
uv: Node<"vec2">

Box UV after all uv transforms.

uv
.
mul: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+6 overloads)
mul
(500).
add: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+3 overloads)
add
(
u: Uniforms<
ColorsIn<{ readonly strength: 0.02; readonly grain: 0.06; }>
>

Input uniforms and one uniform per live param, for TSL graphs.

u
.
InputUniforms.time: UniformNode<"float">

Seconds that advance only while visible. Frozen under reduced motion.

time
))
.
NumExtensions<"float">.sub: AddSubMulDivNumberVecNumExtensions
(
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+3 overloads)
sub
(0.5)
.
mul: (
b: NumberParameterForNumType<"float">,
...params: NumberParameterForNumType<"float">[]
) => Node<"float"> (+7 overloads)
mul
(
u: Uniforms<
ColorsIn<{ readonly strength: 0.02; readonly grain: 0.06; }>
>

Input uniforms and one uniform per live param, for TSL graphs.

u
.
grain: UniformNode<"float">
grain
)
const
const r: Node<"float">
r
=
const raw: (at: Node<"vec2">) => Node<"vec3">
raw
(
uv: Node<"vec2">

Box UV after all uv transforms.

uv
.
add: (
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+3 overloads)
add
(
const shift: JoinNode<"vec2">
shift
)).
Swizzle1From1<"float">.r: Node<"float">
r
const
const b: Node<"float">
b
=
const raw: (at: Node<"vec2">) => Node<"vec3">
raw
(
uv: Node<"vec2">

Box UV after all uv transforms.

uv
.
NumVec2Extensions<"float">.sub: AddSubMulDivNumberVecVec2Extensions
(
b: Vec2OrLessOrNumberParameterForNumType<"float">,
...params: Vec2OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec2"> (+2 overloads)
sub
(
const shift: JoinNode<"vec2">
shift
)).
Swizzle1From3<"float">.b: Node<"float">
b
const
const rgb: Node<"vec3">
rgb
=
function vec3(
x: Scalar,
y: Scalar,
z: Scalar
): JoinNode<"vec3"> (+6 overloads)
vec3
(
const r: Node<"float">
r
,
const raw: (at: Node<"vec2">) => Node<"vec3">
raw
(
uv: Node<"vec2">

Box UV after all uv transforms.

uv
).
Swizzle1From2<"float">.g: Node<"float">
g
,
const b: Node<"float">
b
).
add: (
b: Vec3OrLessOrNumberParameterForNumType<"float">,
...params: Vec3OrLessOrNumberParameterForNumType<"float">[]
) => Node<"vec3"> (+2 overloads)
add
(
const grain: Node<"float">
grain
)
return
function vec4(
xyz:
| Node<"vec3">
| Node<"color">
| Vector3
| Color
| Node<"vec4">,
w: Scalar
): JoinNode<"vec4"> (+10 overloads)
vec4
(
function sRGBTransferEOTF(color: Node): Node
sRGBTransferEOTF
(
const rgb: Node<"vec3">
rgb
) as
type Node<TNodeType = unknown> = NodeClass<NodeClassEventMap>
& NodeElements
& (unknown extends TNodeType ? {} : NodeExtensions<TNodeType>)
& NodeExtras[TNodeType & string]
& { __TypeScript_NODE_TYPE__: TNodeType; }
Node
<'vec3'>,
sample: (uv: Node<"vec2">) => Node<"vec4">

The element's media at box UV with crop, contain and radius masks applied; vec4(0) without media.

sample
(
uv: Node<"vec2">

Box UV after all uv transforms.

uv
).
Swizzle1From4<"float">.a: Node<"float">
a
)
})(),
)
},
)

hash and noise are plain TypeScript functions that build nodes, so they need no Fn. Long expressions inside fract(...) can lose their type in the three.js typings; a named variable in between fixes that. To start from the converter’s output instead, run the CLI on the file and read the .frag.js it writes.

Port a vertex shader

A .vert next to a .frag with the same name is part of the same effect, with the params of both. The vertex shader moves the plane of the element: its matrices are identity, x and y are fractions of the box from -0.5 to 0.5, and z is in CSS pixels, so an amplitude of 30 lifts the plane 30 pixels toward the viewer.

src/effects/swell.vert
// @diorama animate=hover segments=64
uniform float uTime;
uniform float uHover;
uniform float uAmplitude; // @default 30
uniform float uFrequency; // @default 8
varying vec2 vUv;
varying float vWave;
void main() {
vUv = uv;
vec3 pos = position;
float wave = sin(pos.x * uFrequency + uTime * 2.0) * cos(pos.y * uFrequency * 0.5 + uTime);
pos.z += wave * uAmplitude * uHover;
vWave = wave * uHover;
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
}
src/effects/swell.frag
uniform sampler2D uTexture;
uniform float uShade; // @default 0.4
varying vec2 vUv;
varying float vWave;
void main() {
vec2 uv = vUv + vec2(0.0, vWave * 0.02);
vec4 color = texture2D(uTexture, uv);
color.rgb *= 1.0 - vWave * uShade;
gl_FragColor = color;
}

animate=hover keeps frames to hover even though the shader reads uTime. A shader that needs a real projection or depth gives wrong results with identity matrices, and the converter cannot detect that.

Know the stages

The converter sorts each shader into a stage, and the stage decides how it stacks with other effects on the element.

  • uv: the shader reads the picture once at bent coordinates, as its last statement. It becomes a surface.uv() function and adds to the other effects.
  • color: everything else. The shader sets the whole color and does not see the color of earlier effects, as in the original GLSL, so list it first in data-dio.
  • position: a vertex shader.

gl_FragCoord, iResolution and iMouse are in device pixels of the element’s box, counted from its bottom left corner, not of the screen. Output color matches ShaderMaterial by default, since the shader gets raw sRGB values and its result is encoded back. For a shader written for the linear pipeline of three.js, add // @diorama colorSpace=linear.

Next.js and the CLI

Next.js reads .frag imports through the webpack loader @dioramajs/glsl/loader. With webpack the mode goes in the import query, as in Vite; Turbopack matches rules by path, so the mode goes in the file name. withDiorama does not pick up shaders from the effects folder, so give each shader a glue file there.

next.config.mjs
import { withDiorama } from '@dioramajs/diorama/next'
export default withDiorama({
webpack(config) {
config.module.rules.push({
test: /\.(frag|vert|glsl)$/,
resourceQuery: /^\?(shader|effect|entry)$/,
use: [{ loader: '@dioramajs/glsl/loader' }],
})
return config
},
turbopack: {
rules: {
'*.shader.frag': {
loaders: [
{
loader: '@dioramajs/glsl/loader',
options: { mode: 'shader' },
},
],
as: '*.js',
},
},
},
})

Without a bundler, convert ahead of time. The CLI writes rgb-shift.frag.js and rgb-shift.frag.d.ts next to the file and prints the bindings and diagnostics; --check only reports and exits with 1 on an error or a stale .js, for CI.

Terminal window
npx diorama-glsl src/effects/*.frag --check
Terminal window
pnpm exec diorama-glsl src/effects/*.frag --check
Terminal window
yarn diorama-glsl src/effects/*.frag --check
Terminal window
bunx diorama-glsl src/effects/*.frag --check

Other flags: --out-dir writes elsewhere and keeps the folder layout, --watch converts on save, --json prints the result with line counts and fixes, --bind uMouse=input:pointerNdc and --default uStrength=1 set bindings and defaults from the command line.

Use a shader inside your own effect

shaderNode() turns a fragment shader into a vec4 node for a material you build, and applyShader() adds a shader to the element’s picture from your own setup. Both take the effect context and the same uniforms, textures, functions and colorSpace options as glslEffect. applyShader() returns a function that removes the shader again.

src/effects/poster.ts
import {
function applyShader<P extends ParamSpec>(
ctx: EffectContext<P>,
shader: GlslSource,
options?: ApplyOptions
): Off

Adds a shader to the surface from a custom effect's setup. Call the result to remove it.

applyShader
,
function shaderNode<P extends ParamSpec>(
ctx: EffectContext<P>,
shader: GlslShader,
options?: ApplyOptions & { readonly uv?: Node<"vec2">; }
): Node<"vec4">

The fragment shader as a vec4 node for a custom material. The element's image is texture(map, coverUV(uv)) times the box mask.

@throws ― {EffectError} EFFECT_SETUP when a shader uniform is bound to a missing param.

shaderNode
} from '@dioramajs/glsl'
import {
function effect(
setup: EffectSetup<Empty>
): Effect<Empty> (+2 overloads)

Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its registry key (the file name when a build plugin finds it).

export default effect({ strength: 1 }, ({ surface, u }) => { ... })

effect
} from '@dioramajs/diorama'
import {
class Mesh<
TGeometry extends BufferGeometry = BufferGeometry<
NormalBufferAttributes,
BufferGeometryEventMap
>,
TMaterial extends Material
| Material[] = Material<...>
| Material<...>[],
TEventMap extends Object3DEventMap = Object3DEventMap
>

Class representing triangular

https://en.wikipedia.org/wiki/Polygon_mesh polygon mesh

based objects.

@remarks ― Also serves as a base for other classes such as THREE.SkinnedMesh SkinnedMesh, THREE.InstancedMesh InstancedMesh.

@example

const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({
color: 0xffff00
});
const Mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

@see ― https://threejs.org/docs/index.html#api/en/objects/Mesh Official Documentation

@see ― https://github.com/mrdoob/three.js/blob/master/src/objects/Mesh.js Source

Mesh
,
class MeshBasicNodeMaterial

Node material version of

MeshBasicMaterial

.

MeshBasicNodeMaterial
,
class PlaneGeometry

A class for generating plane geometries.

@example

const geometry = new THREE.PlaneGeometry(1, 1);
const material = new THREE.MeshBasicMaterial({
color: 0xffff00,
side: THREE.DoubleSide
});
const plane = new THREE.Mesh(geometry, material);
scene.add(plane);

@see ― https://threejs.org/docs/index.html#api/en/geometries/PlaneGeometry Official Documentation

@see ― https://github.com/mrdoob/three.js/blob/master/src/geometries/PlaneGeometry.js Source

PlaneGeometry
,
} from 'three/webgpu'
import
const grain: GlslShader<ParamSpec>
grain
from './grain.frag?shader'
import
const tint: GlslShader<ParamSpec>
tint
from './tint.frag?shader'
export default
effect<P>(
params: P & CheckSpec<P>,
options: EffectOptions<ColorsIn<P>>,
setup: EffectSetup<ColorsIn<P>>
): Effect<WidenSpec<P>> (+2 overloads)
type P = {
readonly strength: 0.5;
}

Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its registry key (the file name when a build plugin finds it).

export default effect({ strength: 1 }, ({ surface, u }) => { ... })

effect
({
strength: 0.5
strength
: 0.5 }, {
media?: boolean | "optional" | undefined

Needs the or as a texture. Implies on: 'img, video', ready before setup. 'optional' reads it when the element is one and runs without it on other elements.

media
: true }, (
ctx: EffectContext<
ColorsIn<{ readonly strength: 0.5; }>
>
ctx
) => {
const
const material: MeshBasicNodeMaterial
material
= new
new MeshBasicNodeMaterial(
parameters?: MeshBasicNodeMaterialParameters
): MeshBasicNodeMaterial

Constructs a new mesh basic node material.

@param ― parameters - The configuration parameter.

MeshBasicNodeMaterial
({
transparent?: boolean | undefined

Defines whether this material is transparent. This has an effect on rendering as transparent objects need special treatment and are rendered after non-transparent objects.

When set to true, the extent to which the material is transparent is controlled by

Material#opacity

.

@default ― false

transparent
: true })
const material: MeshBasicNodeMaterial
material
.
NodeMaterialNodeProperties.colorNode:
| Node<"vec2">
| Node<"vec4">
| Node<"float">
| Node<"vec3">
| Node<"color">
| null

The diffuse color of node materials is by default inferred from the color and map properties. This node property allows to overwrite the default and define the diffuse color with a node instead.

material.colorNode = color( 0xff0000 ); // define red color

If you don't want to overwrite the diffuse color but modify the existing values instead, use

materialColor

.

material.colorNode = materialColor.mul( color( 0xff0000 ) ); // give diffuse colors a red tint

@default ― null

colorNode
=
shaderNode<ColorsIn<{ readonly strength: 0.5; }>>(
ctx: EffectContext<ColorsIn<{ readonly strength: 0.5; }>>,
shader: GlslShader,
options?: ApplyOptions & { readonly uv?: Node<"vec2">; }
): Node<"vec4">

The fragment shader as a vec4 node for a custom material. The element's image is texture(map, coverUV(uv)) times the box mask.

@throws ― {EffectError} EFFECT_SETUP when a shader uniform is bound to a missing param.

shaderNode
(
ctx: EffectContext<
ColorsIn<{ readonly strength: 0.5; }>
>
ctx
,
const grain: GlslShader<ParamSpec>
grain
, {
uniforms?:
| {
readonly [uniform: string]: Binding
| ((ctx: EffectContext<ParamSpec>) => Node);
}
| undefined

Binding overrides, keyed by GLSL uniform name.

uniforms
: {
uGrain: "param:strength"
uGrain
: 'param:strength' },
})
ctx: EffectContext<
ColorsIn<{ readonly strength: 0.5; }>
>
ctx
.
EffectContext<
ColorsIn<{ readonly strength: 0.5; }>
>.place<
Mesh<PlaneGeometry, MeshBasicNodeMaterial, Object3DEventMap>
>(
object: Mesh<
PlaneGeometry,
MeshBasicNodeMaterial,
Object3DEventMap
>,
options?: PlaceOptions
): Mesh<PlaneGeometry, MeshBasicNodeMaterial, Object3DEventMap>

Glues an object to the box so it follows layout and pose. Disposed with the instance.

place
(new
new Mesh<
PlaneGeometry,
MeshBasicNodeMaterial,
Object3DEventMap
>(
geometry?: PlaneGeometry | undefined,
material?: MeshBasicNodeMaterial | undefined
): Mesh<PlaneGeometry, MeshBasicNodeMaterial, Object3DEventMap>

Create a new instance of

Mesh

@param ― geometry An instance of THREE.BufferGeometry BufferGeometry. Default THREE.BufferGeometry new THREE.BufferGeometry().

@param ― material A single or an array of THREE.Material Material. Default THREE.MeshBasicMaterial new THREE.MeshBasicMaterial().

Mesh
(new
new PlaneGeometry(
width?: number,
height?: number,
widthSegments?: number,
heightSegments?: number
): PlaneGeometry

Create a new instance of

PlaneGeometry

@param ― width Width along the X axis. Expects a Float. Default 1

@param ― height Height along the Y axis. Expects a Float. Default 1

@param ― widthSegments Number of segmented faces along the width of the sides. Expects a Integer. Default 1

@param ― heightSegments Number of segmented faces along the height of the sides. Expects a Integer. Default 1

PlaneGeometry
(1, 1),
const material: MeshBasicNodeMaterial
material
))
applyShader<ColorsIn<{ readonly strength: 0.5; }>>(
ctx: EffectContext<ColorsIn<{ readonly strength: 0.5; }>>,
shader: GlslSource,
options?: ApplyOptions
): Off

Adds a shader to the surface from a custom effect's setup. Call the result to remove it.

applyShader
(
ctx: EffectContext<
ColorsIn<{ readonly strength: 0.5; }>
>
ctx
,
const tint: GlslShader<ParamSpec>
tint
)
})

The whole port

The converter path is two files: the shader as it was, with two @default pragmas, and an optional glue file.

src/effects/rgb-shift.ts
import {
function glslEffect<
S extends ParamSpec,
const O extends ParamSpec = Empty
>(
shader: GlslSource<S>,
options?:
& GlslEffectOptions<MergeParams<S, O>>
& { readonly params?: O; }
& CheckParams<O>
): Effect<WidenSpec<MergeParams<S, O>>>

Wraps a GLSL stage pair as an effect. Bindings, params and varyings are checked up front and reported together as one EFFECT_DEFINITION.

@throws ― {EffectError} EFFECT_DEFINITION with every problem found.

glslEffect
} from '@dioramajs/glsl'
import
const shader: GlslShader<ParamSpec>
shader
from './rgb-shift.frag?shader'
export default
glslEffect<ParamSpec, U>(
shader: GlslSource<ParamSpec>,
options?:
| (
GlslEffectOptions<U>
& { readonly params?: U | undefined; }
& CheckParams<U>
)
| undefined
): Effect<WidenSpec<U>>
type U = {
readonly strength: 0.02;
readonly grain: 0.06;
}

Wraps a GLSL stage pair as an effect. Bindings, params and varyings are checked up front and reported together as one EFFECT_DEFINITION.

@throws ― {EffectError} EFFECT_DEFINITION with every problem found.

glslEffect
(
const shader: GlslShader<ParamSpec>
shader
, {
params?:
| (
{ readonly strength: 0.02; readonly grain: 0.06; }
& CheckSpec<
{ readonly strength: 0.02; readonly grain: 0.06; }
>
)
| undefined

Override the shader's pragma defaults. Their types become the param types.

params
: {
strength: 0.02
strength
: 0.02,
grain: 0.06
grain
: 0.06 },
animate?:
| AnimatePolicy<
{ readonly strength: 0.02; readonly grain: 0.06; }
>
| undefined

Defaults to the update's answer when it returns a boolean, else to what the effect reads: time animates every visible frame, hoverTime while hovered or hover decays, neither means 'input'.

animate
: {
fps:
| number
| (
(
ctx: EffectContext<
{ readonly strength: 0.02; readonly grain: 0.06; }
>
) => number
)
fps
: 24 },
})
vite.config.ts
import {
function glsl(options?: GlslPluginOptions): Plugin

Vite plugin that turns GLSL files into TSL shaders and effects on import.

glsl
} from '@dioramajs/glsl/vite'
import {
function diorama(options?: DioramaPluginOptions): Plugin

Vite plugin, plugins: [diorama()].

diorama
} from '@dioramajs/diorama/vite'
export default {
plugins: Plugin<any>[]
plugins
: [
function diorama(options?: DioramaPluginOptions): Plugin

Vite plugin, plugins: [diorama()].

diorama
(),
function glsl(options?: GlslPluginOptions): Plugin

Vite plugin that turns GLSL files into TSL shaders and effects on import.

glsl
()] }