GLRE Mathematical and SDF Addons

website·Indexed 32 days ago

https://glre.dev

A 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.

Tokens
129.8K
Snippets
623
Records
833
Agent score
58%

What's inside GLRE

  1. Overview of TSL for real-time graphics

    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.
  2. 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)
    }
  3. 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.
  4. 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.
  5. 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.
  6. Perform Y-axis rotation on 3D and 4D vectors

    The rotateY functions 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).
  7. Generate signed random values for symmetric patterns

    Use srandom functions 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.
  8. Convert normalized depth to linear view space Z

    The depth2viewZ family 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.
  9. 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].
  10. 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.
  11. Perform X-axis rotation on 3D and 4D vectors

    The rotateX functions 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).
  12. 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. As s approaches 0, the distribution behaves like a Dirac delta function; as s approaches 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))