0.14.6
Initialize a WebGL target with effects.
(kamposConfig)
import { Kampos, effects} from 'kampos';
const target = document.querySelector('#canvas');
const hueSat = effects.hueSaturation();
const kampos = new Kampos({target, effects: [hueSat]});
Initializes a Kampos instance. This is called inside the constructor, but can be called again after effects have changed or after Kampos#destroy.
boolean
:
success whether initializing of the context and program were successful
Set the source config.
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap | kamposSource))
const media = document.querySelector('#video');
kampos.setSource(media);
Initialize a ticker instance for batching animation of multiple Kampos instances.
Type: Object
(HTMLCanvasElement)
(Array<effectConfig>)
(planeConfig)
(Ticker?)
(boolean?)
(function?)
: function to run before each draw call. If it returns
false
kampos#draw
will not be called.
(function?)
: function to run after each draw call.
(function?)
(function?)
(function?)
Type: Object
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
(number)
(number)
(boolean?)
: whether to resample the source on each draw call
Type: Object
Type: Object
Type: Object
Type: Object
Type: Object
(string)
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap)?)
Exposes the u_resolution
uniform for use inside fragment shaders.
resolutionUtility
:
resolution({width: 1600, height: 900})
Exposes the u_mouse
uniform for use inside fragment shaders.
Note that internally the y
coordinate is inverted to match the WebGL coordinate system.
mouseUtility
:
mouse({initial: {x: 0.5, y: 0.5}})
Exposes the circle
function to be used by effects.
This function takes a point, radius, and spread, and returns a value between 0 and 1.
circleUtility
:
circle()
Type: Object
mouse.resolution = {width: 854, height: 480};
Type: Object
mouse.position = {x: 0.4, y: 0.2};
Type: Object
float aspectRatio = u_resolution.x / u_resolution.y;
vec2 st_ = gl_FragCoord.xy / u_resolution;
float circle_ = circle(
vec2(st_.x * aspectRatio, st_.y),
vec2(u_mouse.x * aspectRatio, u_mouse.y),
0.35,
0.1
);
brightnessContrastEffect
:
brightnessContrast({brightness: 1.5, contrast: 0.8})
hueSaturationEffect
:
hueSaturation({hue: 45, saturation: 1.3})
(Object?)
Name | Description |
---|---|
params.mode (
(default 'normal' )
|
blend mode to use |
params.color Array<number>
(default [0,0,0,1] )
|
Initial color to use when blending to a solid color |
blendEffect
:
blend('colorBurn')
alphaMaskEffect
:
alphaMask()
duotoneEffect
:
duotone({dark: [0.2, 0.11, 0.33, 1], light: [0.88, 0.78, 0.43, 1]})
(Object?)
Name | Description |
---|---|
params.wrap string?
|
wrapping method to use. Defaults to
displacement.CLAMP
.
|
params.scale {x: number, y: number}?
|
initial scale to use for x and y displacement. Defaults to
{x: 0.0, y: 0.0}
which means no displacement.
|
params.enableBlueChannel boolean?
|
enable blue channel for displacement intensity. Defaults to
false
.
|
(string)
: stretch the last value to the edge. This is the default behavior.
(string)
: discard values beyond the edge of the media - leaving a transparent pixel.
(string)
: continue rendering values from opposite direction when reaching the edge.
displacementEffect
:
displacement({wrap: displacement.DISCARD, scale: {x: 0.5, y: -0.5}})
(object)
Name | Description |
---|---|
params.noise string
|
3D noise implementation to use. |
params.output string?
|
how to output the
turbulenceValue
variable. Use
turbulence.COLOR
or
turbulence.ALPHA
for outputting to color or alpha correspondingly. Defaults to
turbulence.COLOR
.
|
params.frequency {x: number, y: number}
(default {x:0.0,y:0.0} )
|
initial frequencies to use for x and y axes. |
params.octaves number
(default 1 )
|
initial number of octaves to use for turbulence noise generation. |
params.isFractal boolean
(default false )
|
initial number of octaves to use for turbulence noise generation. |
params.time number
(default 0 )
|
initial time for controlling initial noise value. |
params.input string?
|
how to define
turbulenceSeed
. Defaults to
turbulence.FRAGCOORD_XY_TIME
.
|
turbulenceEffect
:
turbulence({noise: kampos.noise.simplex, output: turbulence.COLOR, octaves: 4, isFractal: true})
kaleidoscopeEffect
:
kaleidoscope({segments: 12})
Depends on the resolution
utility.
Depends on the mouse
utility.
(Object?)
Name | Description |
---|---|
params.radius number?
|
initial radius to use for circle of effect boundaries. Defaults to 0 which means no effect. |
params.wrap string?
|
wrapping method to use. Defaults to
deformation.CLAMP
.
|
params.deformation string?
|
deformation method to use within the radius. Defaults to
deformation.NONE
.
|
deformationEffect
:
deformation({radius: 0.1, wrap: deformation.CLAMP, deformation: deformation.TUNNEL})
(Object?)
Name | Description |
---|---|
params.offsetRed {x: number?, y: number?}?
|
initial offset to use for red channel offset. Defaults to
{x: 0.0, y: 0.0}
which means no offset.
|
params.offsetGreen {x: number?, y: number?}?
|
initial offset to use for green channel offset. Defaults to
{x: 0.0, y: 0.0}
which means no offset.
|
params.offsetBlue {x: number?, y: number?}?
|
initial offset to use for blue channel offset. Defaults to
{x: 0.0, y: 0.0}
which means no offset.
|
params.offsetInputR string?
|
code to use as input for the red offset. Defaults to
u_channelOffsetR
.
|
params.offsetInputG string?
|
code to use as input for the green offset. Defaults to
u_channelOffsetG
.
|
params.offsetInputB string?
|
code to use as input for the blue offset. Defaults to
u_channelOffsetB
.
|
channelSplitEffect
:
channelSplit({offsetRed: {x: 0.02, y: 0.0}})
(Object)
Name | Description |
---|---|
params.noise noise
|
2D noise implementation to use. |
params.time number
(default 0.0 )
|
initial time for controlling initial noise value. |
params.intensity number
(default 0.1 )
|
initial intensity to use. |
params.frequency number?
|
initial frequency to use . |
params.direction string
(default 'x' )
|
direction to apply the slit scan effect. |
params.offsetInput string?
|
code to use as input for adding offset. Defaults to empty. |
slitScanEffect
:
slitScan({intensity: 0.5, frequency: 3.0})
Type: Object
effect.brightness = 1.5;
effect.contrast = 0.9;
effect.contrastDisabled = true;
Type: Object
effect.hue = 45;
effect.saturation = 0.8;
Type: Object
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
: to use as backdrop
(boolean)
const img = new Image();
img.src = 'picture.png';
effect.color = [0.3, 0.55, 0.8, 1.0];
effect.image = img;
Multiplies alpha
value with values read from mask
media source.
Type: Object
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
(boolean)
(boolean)
const img = new Image();
img.src = 'picture.png';
effect.mask = img;
effect.disabled = true;
Type: Object
(boolean)
effect.light = [1.0, 1.0, 0.8];
effect.dark = [0.2, 0.6, 0.33];
Type: Object
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
(boolean)
(boolean)
const img = new Image();
img.src = 'disp.jpg';
effect.map = img;
effect.scale = {x: 0.4};
Generates a turbulence/fractal noise value stored into turbulenceValue
.
Depends on a noise(vec3 P)
function to be declared and injected via the noise
param, for example, simply supplying the perlinNoiseEffect.
Type: Object
effect.frequency = {x: 0.0065};
effect.octaves = 4;
effect.isFractal = true;
Type: Object
effect.segments = 8;
effect.offset = { x: 0.5, y: 0.5 };
effect.rotation = 45;
Type: Object
effect.disabled = true;
effect.radius = 0.253;
Type: Object
(boolean)
effect.offsetRed = { x: 0.1, y: 0.0 };
Type: Object
effect.intensity = 0.5;
effect.frequency = 3.5;
fadeTransitionEffect
:
fadeTransition()
(Object?)
displacementTransitionEffect
:
displacementTransition()
(Object?)
Name | Description |
---|---|
params.low number
(default 0.0 )
|
initial lower edge of intersection step |
params.high number
(default 0.01 )
|
initial higher edge of intersection step |
params.color Array<number>
(default [0,0,0,0] )
|
color to transition to if not transitioning to media |
params.textureEnabled boolean
(default true )
|
whether to enable transition to texture instead of color |
dissolveTransitionEffect
:
dissolveTransition()
Type: Object
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
: media source to transition into
(number)
: number between 0.0 and 1.0
(boolean)
effect.to = document.querySelector('#video-to');
effect.progress = 0.5;
Type: Object
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
: media source to transition into
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
: displacement map to use
(number)
: number between 0.0 and 1.0
(boolean)
const img = new Image();
img.src = 'disp.jpg';
effect.map = img;
effect.to = document.querySelector('#video-to');
effect.sourceScale = {x: 0.4};
effect.toScale = {x: 0.8};
Type: Object
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
: media source to transition into
((ArrayBufferView | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap))
: dissolve map to use
(Array<number>)
: a solid color to transition to with alpha channel, Array of 4 number in range [0.0, 1.0]
(number)
: lower edge of intersection step, in range [0.0, 1.0]
(number)
: higher edge of intersection step, in range [0.0, 1.0]
(number)
: number in range [0.0, 1.0]
(boolean)
: whether to enable transitioning to texture instead of color
(boolean)
const img = new Image();
img.src = 'dissolve.jpg';
effect.map = img;
effect.to = document.querySelector('#video-to');
effect.progress = 0.5;
Implementation of a 3D classic Perlin noise. Exposes a noise(vec3 P)
function for use inside fragment shaders.
Cellular noise ("Worley noise") in 3D in GLSL. Exposes a noise(vec3 P)
function for use inside fragment shaders.
Implementation of a 3D Simplex noise. Exposes a noise(vec3 v)
function for use inside fragment shaders.
Implementation of a 2D Simplex noise. Exposes a noise(vec2 v)
function for use inside fragment shaders.
Implementation of white noise with 3 seeds. Exposes a noise(vec3 seed)
function for use inside fragment shaders.
Type: Object