Basic examples

Basic examples that set up a two-dimensional rendering environment within the 3D WebGL framework, and then illustrate basic rendering techniques like rendering from a texture, pixel operations like blurring, and random noise.

Example 1: "Hello GPU"

Set up an HTML Canvas for webGLM rendering, and render a simple coordinate-dependent image.

Example 2: "1D texture"

Use a one-dimensional texture as a colormap. Eventually, we will also render to texture to store rendering and simulation data between frames.

Example 3: "Use two textures"

Basic example loading two different colormaps as textures. Using multiple textures is important for rendering more complex systems, which may require more state than a single red-green-blue texture can store.

Example 4: "Pixel blur"

Vertical blur by averaging nearyby pixel values. This example demonstrate basic recursive/iterated computation on an image.

Example 5: "Separable Gaussian blur"

We can compute larger Gaussian blurs quickly by blurring first horizontally and vertically.

Example 6: "Multi-color blur"

For simulations, different colors might represent different quantities. This Gaussian blur kernel treats each color channel separately, blurring them by different amounts.

Example 7: "Noise"

Stochastic simulations and animations require a source of noise. This kernel approximates uniform pseudorandom number generation, in a fast ad-hoc way that is suitable for visualizations (not not guaranteed to be random enough for other uses).

Example 8: "Spatiotemporal noise"

This example combines driving noise with repeated Gaussian blurs to create a spatiotemporal noise effect.

Example 11: "Bitops"

WebGL doesn't explicitly support unsigned integer types and bit operations. However, most reasonable hardware and WebGL implementations should implicitly store color texture data as 8-bit integers. This kernel accesses this color data as if it were uint8, even though it is technically a float.

Image processing examples

These examples demonstrate basic image processing: color adjustments and blur/sharpen.

Example 15: "Load image"

This example loads an image resource, copies it to a texture, and displays it on screen.

Example 16: "Linear hue rotation"

This example demonstrates hue rotation as an optimize linear transformation using hue and chroma.

Example 17: "Image blur"

Apply iterated Guassian blur to image data.

Example 17b: "Unsharp mask"

Apply iterated unsharp mask to image data.

Example 19: "Brightness and contrast"

Adjust brightness and contrast of image based on mouse location.

Example 19: "Hue and saturation"

Adjust hue and saturation of image based on mouse location.

Technical experiments

These examples test a couple of technical tricks that might be useful in rendering.

Example 25: "Gaussian noise"

Convert uniform random numbers to Gaussian random numbers with mean and variance specified by the mouse location.

Example 21: "Recursive mipmaps"

Mipmaps are successively downsampled copies of a texture that are used to avoid aliasing. The are usually computed once, with a program is initialized. However, if we are rendering to texture data, and then want to use that data as a texture to color 3D objected, we may want to updates mipmaps. Rather than update all texture resolutions at once, however, we successively downsample on each iteration. meaning that lower-resolution mipmaps are updated later.

Example 25: "Statistical mipmaps"

Texture mipmaps compute the average texture color over a region, by downsampling. What if we'd like the average statistics, like mean and variance, over a given region?

Example 25: "Hello particles"

Particle systems are useful in many-body simulations. This example uses texture data for particle location, and also renders each particle differently based on an offset into a texture.

Example 13: "Julia set"

Track the mouse location and render a Julia set using video feedback.

Psychedelic

These examples are "Just for fun"

Example 9: "Quadratic feedback"

Quadratic video feedback example of iterated conformal maps which can be used to render Julia set fractals.

Example 10: "Logarithmic feedback"

Iterated logarithmic video feedback. The logarithmic map can be used to approximate the coordinate mapping from visual cortex to retinal (or "subjective") coordinates, which explains why some visual hallucinations take on a tunnel appearance. (Ermentrout GB, Cowan JD. A mathematical theory of visual hallucination patterns. Biological cybernetics. 1979 Oct 1;34(3):137-50.)

Example 18: "Psychedelic filter"

Applies a combination of blues, sharpening, and hue rotations for a psychedelic image effect.

Example 14: "Complex arithmetic"

Interpret length-2 vectors as complex numbers using a collection of macros. More sophisticated video feedback example.

Example 17: "Quasicrystal 1"

An infinitely-zooming quasicrystal visualization with Shepard tone accompaniment, black and white.

Example 17: "Quasicrystal 2"

An infinitely-zooming quasicrystal visualization with Shepard tone accompaniment, color.

Neural field simulations

Using only 8-bit color data to store state values means that these neural field simulations are only approximate. Some dynamical behaviors won't appear at parameters quite qhere the theory predicts. However, most qualitative behaviors are preserved.

Example 1: "Wilson-Cowan equations"

Spiral wave emerge in a Wilson-Cowan neural field model. The lack of platform-specified rounding in WebGL means that these patteerns to not appear correcrtly on all devices (see example 2).

Example 2: "Platform independent rounding"

Spiral wave emerge in a Wilson-Cowan neural field model. Additional macros enforce a platform-independent rounding rule, allowing for consistent behavior across devices.

Example 3: "Center-surround"

Center surround "mexican hat" style coupling leads to the emergence of striped patterns in a Wilson-Cowan system.

Example 4: "Flicker"

Turing patterns induced in a Wilson-Cowan system by periodic forcing. (Rule M, Stoffregen M, Ermentrout B. A model for the origin and properties of flicker-induced geometric phosphenes. PLoS computational biology. 2011 Sep 29;7(9):e1002158.)

Example 5: "Retinotopic map"

Use the logarithmic map to approximate how a Wilson-Cowan pattern forming system might appear in subjective coordinates, if the emergent waves were to occur in visual cortex. (Ermentrout GB, Cowan JD. A mathematical theory of visual hallucination patterns. Biological cybernetics. 1979 Oct 1;34(3):137-50.)

Example 9: "16-bit precision"

Use two color components, with 8-bits each, to implement 16-bit fixed-point storage of simulation states. This leads to a slightly more accurate numerical integration.

Example 10: "Fullscreen"

Full-screen test of a logarithmically-mapped Wilson-Cowan pattern forming system.

Example 11: "Psychedelic"

Full-screen test of a logarithmically-mapped Wilson-Cowan pattern forming system. Additional noise and hue rotation effects are added. This is purely a visual demonstration.