LittleJS 1.28.0

PostProcess

LittleJS Post Processing Plugin

  • Supports shadertoy style post processing shaders
  • call new PostProcessPlugin() to setup post processing
  • can be enabled to pass other canvases through a final shader
  • iResolution is the canvas backing store, so it grows with canvasPixelRatio like shadertoy does. Effects that use it only for uv (p/iResolution.xy) are unaffected, but ones that set a feature size from it, like scan lines, get finer as the ratio rises. Divide by getCanvasPixelRatio() to pin them.

Classes

Functions

Members

Functions

postProcessBloom(threshold, strength, size, includeMainCanvas) → PostProcessPluginpostProcess.js:363

Set up post processing with a bloom effect, so bright colors and lights glow

threshold number|string optional, default 0.6

Brightness where the glow starts, 0 is everything and 1 is only pure white

strength number|string optional, default 1

How much glow to add

size number optional, default 6

How far the glow spreads in pixels

includeMainCanvas boolean optional, default false

Glow the 2D canvas too, off by default so HUD text stays crisp (a HUD drawn with WebGL in gameRenderPost glows either way, draw it with useWebGL=false)

postProcessBloom(); // in gameInit, after any Render3DPlugin
postProcessBloomShader(threshold, strength, size) → stringpostProcess.js:346

Shader code for a bloom effect, the bright parts of the image blurred back over it

  • Pass it to PostProcessPlugin, or edit the string to build an effect on top of it
threshold number|string optional, default 0.6

Brightness where the glow starts, 0 is everything and 1 is only pure white

strength number|string optional, default 1

How much glow to add

size number optional, default 6

How far the glow spreads in pixels, which also sets how many samples it takes, so a number and not a value's name

postProcessChromatic(strength) → stringpostProcess.js:523

Split red and blue apart toward the edges, like a cheap lens; put it before what shades the picture

strength number|string optional, default 0.005

How far apart at the edge, as a part of the screen

postProcessCurve(strength) → stringpostProcess.js:508

Bend the picture like the bulged glass of an old TV, black past the corners; put it first

strength number|string optional, default 0.1

How much it bends

postProcessDepthOfField(focus, range, blur) → stringpostProcess.js:585

Keep what is a distance from the camera sharp and blur what is nearer or farther, as a camera lens does; needs render3D.depthTexture on, and blurs 3D only, 2D draws having no depth; put it first

  • What is in focus stays sharp at its edges: a blur in front of or behind it leaves out what is in focus
focus number|string optional, default 10

Distance from the camera, along its view, that is sharpest, in world units

range number|string optional, default 4

How deep the sharp part is; the blur grows over as far again past it

blur number|string optional, default 8

Widest blur in pixels, at most 32

render3D.depthTexture = true;
new PostProcessPlugin(postProcessEffects(postProcessDepthOfField(10, 4, 8)));
postProcessEffects(…effects) → stringpostProcess.js:411

Join effects into one post process shader, in the order given, for PostProcessPlugin or setShaderCode

  • Each effect is a piece of shader code on c, the pixel's color, and uv, where it is on the screen from 0 to 1; your own code is a piece too, a line of GLSL or many, dropped in where you put it
  • Put the ones that bend the picture or sample it first: postProcessCurve, postProcessChromatic, postProcessGlow
…effects string

The pieces, from the effect functions or your own code

Returns
  • Shadertoy style mainImage code
new PostProcessPlugin(postProcessEffects(
postProcessScanlines(.5), postProcessVignette(), 'c.rgb *= vec3(1, .9, .8);'));
postProcessGlow(threshold, strength, size) → stringpostProcess.js:429

Bright parts glow, the bloom as an effect to join with others; postProcessBloom sets up bloom on its own

threshold number|string optional, default 0.6

Brightness where the glow starts, 0 is everything and 1 is only pure white

strength number|string optional, default 1

How much glow to add

size number optional, default 6

How far the glow spreads in pixels, which also sets how many samples it takes, so a number and not a value's name

postProcessNoise(strength, size) → stringpostProcess.js:481

Static noise over the picture, changing every frame

strength number|string optional, default 0.1

How bright the static is

size number|string optional, default 2

Size of a speck in pixels

postProcessOutline(color, thickness, threshold) → stringpostProcess.js:603

Draw lines where the 3D depth jumps, around objects and along their creases; needs render3D.depthTexture on

color Color optional

The lines' color, its alpha how strong they are

thickness number|string optional, default 1

How wide the lines are in pixels

threshold number|string optional, default 0.02

How big a jump makes a line, as a part of the distance, lower draws more

postProcessScanlines(strength, spacing) → stringpostProcess.js:468

Scan lines across the screen, like an old TV

strength number|string optional, default 0.5

How dark the lines are, and how bright between them

spacing number|string optional, default 6

Pixels from one line to the next

postProcessTiltShift(focus, size, blur) → stringpostProcess.js:564

Keep a band across the screen sharp and blur the picture above and below it, as a tilt shift lens does, which makes a scene look like a small model; it reads only the screen, so it works in 2D and 3D; put it first

focus number|string optional, default 0.5

Height of the middle of the sharp band, 0 the bottom of the screen and 1 the top

size number|string optional, default 0.25

Height of the sharp band, as a part of the screen

blur number|string optional, default 8

Widest blur in pixels, reached half the screen past the band, at most 32

new PostProcessPlugin(postProcessEffects(postProcessTiltShift(.4, .2, 10), postProcessVignette(.5)));
postProcessTV(settings) → stringpostProcess.js:632

The look of an old TV, as one effect to use alone or join with others: static noise, scan lines, a soft glow and a vignette, and a bulged screen when curve is set; any setting at 0 leaves that part out

settings Object optional
noise number|string optional

Static noise strength

scanlines number|string optional

Scan line strength

scanlineSpacing number|string optional

Pixels from one scan line to the next

glow number|string optional

Soft glow strength

vignette number|string optional

Vignette strength

curve number|string optional

How much the screen bulges, 0 by default for flat

new PostProcessPlugin(postProcessEffects(postProcessTV({scanlines: .4, curve: .1})));
postProcessVignette(strength, falloff) → stringpostProcess.js:495

Darken toward the edges and corners

strength number|string optional, default 1

How dark the corners get, 1 is black

falloff number|string optional, default 3

How far in it reaches, low darkens most of the screen, high only the corners

Members

Global Post Process plugin object