Global env context struct. This updates every frame and includes input data, time data, and more.
3d triangle patch evaulation with barycentric coordinates.
Returns a [-1, 1] position for a given index.
Returns 3 values: distance to closest cell, random value of closest cell, distance to closest edge.
Creates a quaternion from an angle and axis.
Rotates a vector by a quaternion and returns the rotated vector.
Returns the conjugate of the input quaternion.
The conjugate of a quaternion number is a quaternion with the same magnitudes but with the sign of the imaginary parts changed
Returns the inverse of the input quaternion.
Generates a quaternion that rotates from one direction to another via the shortest path.
Generates lookAt quaternion.
Smooth interpolation between two quaternions.
Converts quaternion to matrix.
Returns the intersection of two SDFs = max(a, b)
Returns the union of two SDFs = min(a, b)
Smoothly joins two SDFs using blending distance k
Blends between two SDFs using interpolation
Carve out the interior of an SDF
Poorly returns the closest point on the surface of an SDF This is an inaccurate method
See: https://iquilezles.org/articles/distfunctions/ Infinitely repeats an SDF with space in between. This returns an updated position
Example:
sdf::sphere(sdf::repeat(p, 100.xyz), 0.xyz, 50.0);
See: https://iquilezles.org/articles/distfunctions/ Repeats an SDF with space in between upto the limit. This returns an updated position
Example:
sdf::sphere(sdf::repeatLimited(p, 100, 10.xyz), 0.xyz, 50.0);
Provides space related utilities like z-order curves and quadtrees.
Saves the current time with a key of name
Returns the difference in milliseconds between a start with the same key
This returns a decimal resolution time in milliseconds since the page started. Useful for measuring time differences
This uses performance.now() under the hood: The performance.now() method returns a high resolution timestamp in milliseconds. It represents the time elapsed since Performance.timeOrigin
Returns the underlying cpu buffer as a typed array.
[!NOTE] This is considerably faster than using the raw index [] operator.
[!NOTE] If the buffer contents are structured (atomic, or a struct), this will return a normal array
let buf = buffer<uint>();
let data = buf.getData();
for (let i = 0; i < data.length; i += 4) {
// Do something with data[i]
}
Moves and zooms the camera to fit the given size. (centers the camera in the viewport)
Delta between the previous frame's time and this frame (in seconds
Current time in seconds from the start of the renderer
Canvas size in pixels
Current frame index
Mouse/touch screen input state for this frame
Keyboard input state for this frame
Controllable camera (Hold right click and use WASD to move)
Use external values from the host JavaScript environment.
Send values to the host JavaScript environment.
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Is key down this frame
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
Key pressed, triggered once until released
2D vector that encodes the arrow keys and WASD aligned with the screen (e.g. up arrow = (0, -1))
Current mouse position relative to canvas in pixels ((0, 0) is the top left
Current mouse position mapped from 0-1 in canvas space ((0, 0) is the top left while (1, 1) is the bottom right
Caches the mouse position relative to canvas in pixels when any mouse button is pressed (resets after subsequent presses
Caches the mouse position mapped from 0-1 in canvas space when any mouse button is pressed (resets after subsequent presses
If dragging, this will be the delta between the start and current mouse position
If dragging, this will be the delta between the mouse position last frame and the current mouse position
If dragging, this will be the delta between the start and current mouse position
If dragging, this will be the delta between the mouse position last frame and the current mouse position
Mouse button pressed state for buttons 0-3 (left, middle, right)
If currently dragging
Accumulated mouse wheel movement for this frame in the range of -1 to 1
Rate of change
Is the mouse focused within the screen
Interpolated world position (available in fragment, and vertex)
Interpolated normal (fragment), Source mesh normal (vertex)
Interpolated tangent (fragment), Source mesh tangent (vertex)
Interpolated bitangent (fragment), Source mesh bitangent (vertex)
Vertex shader output position
UV channel 0 input (available in fragment, and vertex)
Screen position in pixels (available in fragment, and vertex)
Interpolated vertex color (available in fragment, and vertex)
Group ID (available in compute)
Group size (available in compute)
Global id (groupId * groupSize + localId) (available in compute)
Local id (available in compute)
Instance index (available in fragment, and vertex)
Vertex index (available in vertex)
Vertex output position
Vertex output normal
Vertex output tangent
Vertex output bitangent
UV channel 0 output
Pixel color output
Returns the underlying cpu buffer as a typed array.
Note that this is considerably faster than using the raw index [] operator.
let tex = texture2d<float4>();
let data = tex.getData();
for (let i = 0; i < data.length; i += 4) {
let r = data[i];
let g = data[i + 1];
let b = data[i + 2];
let a = data[i + 3];
// Do something with the pixel
}
Release the texture
Creates a new buffer.
let buf = buffer<float>(100);
Returns the derivative of the input value with respect to the window-space x coordinate.
Returns the derivative of the input value with respect to the window-space y coordinate.
Gets the unencoded version of an encoded Uniform Resource Identifier (URI).
Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI).
Discards the current fragment.
A discard statement converts the invocation into a helper invocation and throws away the fragment. The discard statement must only be used in a fragment shader stage.
Normal:
drawAdvanced({
mesh: mesh::box(0.xyz, 100.xyz),
vertex: shader {
// ...
},
fragment: shader {
// ...
},
});
Instancing:
drawAdvanced({
mesh: mesh::box(0.xyz, 100.xyz),
vertex: shader {
in.instanceIndex;
},
fragment: shader {
// ...
},
instances: 100,
});
Indirect:
let mesh = mesh::box(0.xyz, 100.xyz);
let indirectBuffer = buffer<uint>(5);
indirectBuffer[0] = uint(m.getTriangles().len()); // indexCount
indirectBuffer[1] = 1; // instanceCount
indirectBuffer[2] = 0; // firstIndex
indirectBuffer[3] = 0; // vertexOffset
indirectBuffer[4] = 0; // firstInstance
drawAdvanced({
mesh: mesh::box(0.xyz, 100.xyz),
vertex: shader {
// ...
},
fragment: shader {
// ...
},
indirect: indirectBuffer,
});
Attachments:
let mesh = mesh::box(0.xyz, 100.xyz);
let color = texture2d<float4>(100.xy);
let normal = texture2d<float3>(100.xy);
let depth = texture2d<float>(100.xy, "depth");
drawAdvanced({
mesh: mesh,
vertex: shader {
// ...
},
fragment: shader {
out.attachment0 = float4(1, 0, 0, 1);
out.attachment1 = float3(0, 0, 1);
},
depth: depth, // Override depth buffer
attachments: [color, normal],
});
Encodes a text string as a valid Uniform Resource Identifier (URI)
Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
Computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.
Flushes (executes) all queued compute or draw calls
Determines whether a supplied number is finite.
Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).
Converts a string to a floating-point number.
Converts a string to an integer.
Prints a set of value(s) to the console. Values will be converted to strings before printing.
Returns a deterministic (same seed = same output) random float between 0-1
Note: See the noise package for more advanced random functions
Returns a deterministic (same seed = same output) random float between 0-1
Note: See the noise package for more advanced random functions
Returns a deterministic (same seed = same output) random float between 0-1
Note: See the noise package for more advanced random functions
Uses Super Sampling Anti Aliasing to smooth out the image.
Displays a single value in the stats panel at the top right
Display a graph of a numeric value over time
Executes a storage barrier synchronization function that affects memory and atomic operations in the workgroup address space.
Computes a new string in which hexadecimal escape sequences are replaced with the character that it represents.
Executes a control barrier synchronization function that affects memory and atomic operations in the workgroup address space.