GLRE Mathematical and SDF Addons
website·Indexed 32 days ago
https://glre.devA collection of mathematical foundations and Signed Distance Function (SDF) primitives for graphics programming. Includes tools for signal processing, low-discrepancy sequence generation, and geometric computations for shapes such as capsules, cones, circles, dodecahedrons, octahedrons, and ellipsoids.
What's inside GLRE
- TSL is a TypeScript-based framework for creating real-time graphics, animations, image processing filters, and interactive special effects. It abstracts complex technical concepts and platform-specific setups, providing automatic memory management and browser optimization.
Introduction to the TSL Node System
The Node System is a TypeScript-based Domain Specific Language (DSL) that compiles to GPU shader code (GLSL and WGSL). It allows developers to use familiar TypeScript patterns and compile-time type safety to generate efficient GPU code.const fragment = () => { const position = builtin('position') const wave = sin(position.x.add(iTime)) const color = wave.mul(0.5).add(0.5) return vec4(color, color, color, 1.0) }Overview of Value Noise smoothing kernels
Value noise interpolates between random values at grid points using smoothing functions to avoid the sharp artifacts of linear interpolation. The implementation uses different polynomials based on the dimensionality of the noise to ensure organic-looking patterns:
- 1D Noise: Uses the smoothstep function $S(t) = 3t^2 - 2t^3$.
- 2D Noise: Uses cubic interpolation $S(t) = t^2(3 - 2t)$.
- 3D Noise: Uses quintic interpolation $Q(t) = t^3(6t^2 - 15t + 10)$ for smoother transitions.
Overview of TSL for visual programming
TSL is a tool that enables the creation of real-time graphics and stunning visual effects using JavaScript and TypeScript. It is designed to be accessible to those with general programming skills without requiring complex technical knowledge of graphics programming.Understand Fractional Brownian Motion (FBM) noise composition
Fractional Brownian Motion (FBM) creates complex organic patterns by accumulating multiple octaves of noise functions. Each successive layer adds finer detail by varying frequency and amplitude, maintaining a coherent structure across different scales. The mathematical formula is: FBM(x) = Σ (from i=0 to n-1) Ai * f(Fi * x), where Ai is the amplitude progression and Fi is the frequency progression.Perform Y-axis rotation on 3D and 4D vectors
TherotateYfunctions apply Y-axis rotation transformations to 3D and 4D vectors using a 4D rotation matrix. This operation rotates points in the XZ-plane while preserving the Y-coordinate, following the right-hand rule (positive angles rotate counterclockwise when viewed from the positive Y-axis).Generate signed random values for symmetric patterns
Usesrandomfunctions to generate random values in the range [-1, 1]. This is achieved by mapping standard random values [0, 1] using the formula:srandom(x) = 2 * random(x) - 1. This distribution is ideal for creating natural symmetric patterns and removing the positive bias found in standard random functions.Convert normalized depth to linear view space Z
Thedepth2viewZfamily of functions is used to reconstruct linear view space Z coordinates from normalized depth buffer values (ranging from 0 to 1). This is essential for reconstructing world positions from depth textures in camera projection systems.Generate fluid-like turbulence using Wavelet noise
Wavelet noise creates turbulent, swirling patterns by iteratively applying rotation matrices and sampling sine waves at multiple octaves. Unlike standard fractal noise, it uses rotational coupling and radial weighting to produce fluid-like vorticity. The output is normalized to a range of [-1, 1].Common applications for Ray-AABB intersection
Ray-AABB intersection testing is a fundamental operation used in several rendering and spatial techniques:
- Ray Tracing: Used for primary ray-scene intersection tests to find which objects are hit.
- Shadow Rays: Used for occlusion testing to determine if a point is in shadow by checking for intersections between the point and the light source.
- Frustum Culling: Used to test if a bounding box intersects the camera's view volume to avoid rendering off-screen objects.
- Spatial Traversal: Used to navigate acceleration structures like Octrees or grids efficiently.
Perform X-axis rotation on 3D and 4D vectors
TherotateXfunctions apply rotation transformations around the X-axis using a 4D rotation matrix. This operation rotates points in the YZ-plane while preserving the X-coordinate, following the right-hand rule (positive angles rotate counterclockwise when viewed from the positive X-axis).Implement the Gaussian normal distribution function
The
gaussian(d, s)function implements a fundamental normal distribution. It creates a bell-shaped curve with a maximum value of 1 at distance 0 and a smooth falloff with infinite tails. For multidimensional vectors, it calculates the distribution based on the squared magnitude of the vector.Parameters:
d(scalar or vector): The distance value.s(scalar, s > 0): The spread parameter controlling the distribution width. Assapproaches 0, the distribution behaves like a Dirac delta function; assapproaches infinity, it approaches a uniform distribution.
// Mathematical definition // scalar: gaussian(d, s) = e^(-d^2 / (2s^2)) // vector: gaussian(d, s) = e^(-|d|^2 / (2s^2))