GitXplorerGitXplorer
m

minishader-experiment

public
1 stars
1 forks
1 issues

Commits

List of commits on branch master.
Verified
78a574f842717cc300e4b0392ceed08416e0c3a1

Merge pull request #4 from mdboom/build-system

mmdboom committed 5 years ago
Unverified
130dc5fec88688ca8fab3e4b7a9691cf609c2eea

added dist for demo

hhamilton committed 5 years ago
Unverified
6878f680f641c484c9e8b31c293bcf3b2152077a

updated README.md

hhamilton committed 5 years ago
Unverified
aeae8ce81f5f4403fd64e77d375e1e5ee1173b54

.8 scaling for now

hhamilton committed 5 years ago
Unverified
4bbab043ac26521e4302cd995e5280afb5d4a11d

tests

hhamilton committed 5 years ago
Unverified
a538d0ffe047a25e024f805e26593254680602e5

decoder -> decompress-frame

hhamilton committed 5 years ago

README

The README file for this repository.

Minishader

The goal of minishader is to effortlessly create timelapse data maps in a way that is easy to pull into the browser.

This is also an experiment with doing the last mile of data shading in the browser. Rather than sending fully-colorized PNGs, we send a the pixel bin values and do the color mapping in Javascript. This cuts down on the amount of data required to send to the browser, and also should make choosing a color map and transfer function at runtime without doing that computation at runtime on a server.

File format

All values are big-endian.

The format supports 7 bits -- 127 different values. Experimentally, this appears to be plenty for dynamic range for the kinds of visualizations we doing here.

Header

  • Uint32: nframes
  • Uint32: height
  • Uint32: width

Index

  • nframes x Uint32: byte offsets to the start of each frame

Frame

  • Zeros are run length encoded. All other values are included verbatim. For each one-byte value, if the high bit is 0, the number is the run of 0 pixels. If the high bit is 1, the it is a single pixel with value x & 0x7f.

Compression

Experimentally, this format compresses quite well with gzip or brotli compression, but that isn't implemented here yet.

Javascript client API

MS.minishader(arguments)

Creates a new canvas element according to an arguments object with the following keys:

  • target (string, required) a string representing the css selector that represents the parent DOM element
  • data (ArrayBuffer, required) a data object, as returned by MS.loadBinary.
  • width (integer, optional, default 800) the desired width of the map.
  • height (integer, optional, default 800) the desired height of the map.
  • onDraw (function, optional) a callback fired when the minishader frame updates, eg (frame) => { document.getElementById('frame').innerHTMNL = frame }
  • startAtFrame (integer, optional, default 0) which frame to start on in instantiation.
  • colorMap (array, optional, default MS.inferno) an array that specifies the color map. See MS.colorMaps for some readily-available ones.

The MS.minishader object has the following functions attached to it:

  • .start() starts the frame animation.
  • .stop() stops the animation.
  • .goToFrame(f) moves the map to frame f. Throws an error if f > total number of frames - 1.
  • .nextFrame() increments the frame by one, and loops to beginning if you're incrementing past the last (useful when the animation is paused)
  • .previousFrame() decrements the frame by one and loops to the end if you're incrementing past the first (useful when the animation is paused)

MS.loadBinary(path)

Returns a promise that loads the minishader binary format outputted with encoder.py, meant to be used directly with MS.minishader as such:

MS.loadBinary('cube.bin')
    .then(({data, nframes, width, height}) => {
        const slider = document.getElementById('frame-slider')
        const clock = document.getElementById('clock')
        const animatedMap = MS.minishader({
            target: '.main-container',
            background: 'bg.png',
            data,
            width,
            height,
            colorMap: MS.colorMaps.viridis,
            totalFrames: nframes,
        })
        animatedMap.start()
    })

MS.colorMaps

Various color maps to be used with MS.minishader. (WIP)