Each example is a single HTML file that imports the library as an ES
module from ../magic-pixels.js, a copy of the current build.
Run npm run build:examples once to create it, then serve this
folder with any static file server (a browser can't load an ES module over
file://) and open a demo, or read the source to see how it
uses the library.
The smallest scene: a box, a normal material, a perspective camera, a render loop.
A sun, a planet and a moon, orbiting through parent/child transforms
and empty Object3D pivots.
A hand-written GLSL vertex/fragment pair displaces and colors a sphere
from a time uniform.
Two cubes swing between the same orientations: one slerps its
quaternion, the other lerps Euler angles and wobbles.
The same box geometry stored as Float32Array and as
quantized 8/16 bit integers, side by side, rendering identically at a
third the vertex memory.
The same gradient texture with colorSpace: 'linear' and
colorSpace: 'srgb', showing why the GPU needs to know
which one a texture is.
Three transparent planes slide through each other and
always blend correctly however their draw order changes, and a
single-sided plane disappears for half of its spin.
A DirectionalLight circling like a low sun and a
PointLight orbiting with a glowing marker as its child,
read by a hand-written Lambert shader through the built-in light
uniforms.
A grid of createPbrMaterial() spheres sweeping roughness
and metalness, on a normal-mapped floor, under a circling sun and an
orbiting point light with an unlit marker.
loadGltf() loads the Khronos sample models, from a plain
box to a helmet with every PBR map and a multi-file Sponza, frames
them from their bounding box, and loads dropped files from memory
through the fetch option. Two entries pass a real
meshoptimizer/draco3d decoder to decode a
compressed model.
A PBR scene lit brighter than a display can show, rendered into a
floating point RenderTarget and tone mapped to the canvas
by a fullscreen pass, with a choice of curve and an exposure slider.
A Winamp-style trail effect: a noise curve is drawn into a render target, blurred and faded into a second one by a fullscreen pass, and drawn over again, with the two targets swapping roles every frame.
A scene drawn into a RenderTarget with
depth: 'texture', then shown as colour and depth side by
side, with the depth either raw or linearized back to distance.
An island with houses, roads and woods, drawn as a miniature: the terrain is a displaced plane, the sea a wave shader on top of the PBR material, and a depth-of-field pass blurs the top and bottom of the picture like a tilt-shift photo. Drag to orbit.