Spark 3D Gaussian Splatting Renderer

repository·main·Indexed 25 days ago

https://github.com/sparkjsdev/spark

An advanced 3D Gaussian Splatting renderer for THREE.js (v0.179.0+) that enables high-performance, dynamic splat objects in WebGL2 scenes. It supports multiple viewpoints, real-time editing, and various file formats including .PLY, .SPZ, .SPLAT, .KSPLAT, and .SOG. The library includes SparkRenderer for scene management, SplatMesh for loading splats, and SparkControls for FPS and pointer-based navigation.

Tokens
37.9K
Snippets
71
Records
223
Agent score
86%

What's inside @sparkjsdev/spark

  1. Overview of Spark 2.0 Features

    main

    Spark 2.0 is designed for rendering massive 3D Gaussian Splat (3DGS) worlds on any device via several key technologies:

    • LoD Splat Trees: Uses tiny-lod (on-demand) or bhatt-lod (pre-processing) algorithms to create hierarchical representations of splats.
    • Composite LoD Worlds: Supports rendering multiple splat objects simultaneously by traversing trees jointly to maximize screen-space splat size.
    • .RAD File Format: An extensible format for storing precomputed LoD trees that supports streaming via HTTP Range requests.
    • Shared Splat Paging: Implements a shared LRU "splat page table" with a fixed GPU memory pool (default 16M splats) to manage memory across multiple objects.
    • ExtSplats Encoding: A high-precision 32-byte/splat encoding using float32 center coordinates to prevent quantization artifacts in large scenes.
    • Multiple Viewpoints: Supports multiple independent SparkRenderer instances, each with its own viewpoint and shader effects.
  2. Overview of Spark features

    main

    Spark is a dynamic 3DGS renderer designed for THREE.js and WebGL2. Key capabilities include:

    • Pipeline Integration: Fuses splat and mesh-based objects within the THREE.js rendering pipeline.
    • Portability: Targets 98%+ WebGL2 support, working across desktop, mobile, and WebXR.
    • Performance: Optimized for fast rendering even on low-powered mobile devices.
    • Multi-Object Rendering: Renders multiple splat objects together with correct occlusion sorting.
    • Format Support: Supports major splat file formats including .PLY (including compressed), .SPZ, .SPLAT, and .KSPLAT.
    • Dynamic Control: Supports real-time color editing, displacement, skeletal animation, and simultaneous multiple viewpoints.
    • GPU Programmability: Includes a shader graph system for dynamic splat creation and editing via Dynos.
  3. Overview of Spark 3D Gaussian Splatting renderer

    main

    Spark is an advanced 3D Gaussian Splatting renderer designed for integration with THREE.js. It allows developers to render high-quality splats within a standard 3D scene alongside other meshes.

    Key capabilities include:

    • Seamless Integration: Works with existing THREE.js scenes, meshes, and other splats.
    • Performance: Optimized for fast rendering across all devices.
    • Programmability: Supports programmable dynamic splat effects.
    • Wide Format Support: Compatible with .ply, .sogs (Self-Organizing Gaussians), .spz, .splat, and .ksplat formats.
  4. Overview of Dyno shaders

    main

    The dyno shader graph system allows you to create custom computation graphs using JavaScript (and optionally GLSL) that are compiled to GLSL and run on the GPU. It uses TypeScript to ensure type safety and static validation of the GPU computation graph.

    Key concepts:

    • Dyno blocks: Function blocks with multiple typed inputs and outputs.
    • DynoVal<T>: Values passed between blocks, where T is a DynoType representing a GLSL type.
    • GLSL Integration: You can compose existing dyno functions or write raw GLSL code. Note that regular JavaScript operators (like +) cannot be used inside a dyno graph; you must use dyno helper functions (e.g., dyno.add(x, y)).
  5. Splat budget recommendations for performance tuning

    main

    To maintain 60+ FPS, consider the following recommended splat budgets based on the target hardware:

    • Quest 3: 1 million splats or less (avoid high concentration in small areas).
    • Android phone: 1-2 million splats.
    • iPhone: 1-3 million splats.
    • Computer: 1-5 million splats (up to 10-20+ million on high-end desktops).

    Note that high concentrations of splats in a small area (e.g., 500K splats from a Trellis object at a small screen scale) can bottleneck the GPU's rendering and blending capabilities even if the total count is below the budget.

  6. Integrate 3D Gaussian Splatting into THREE.js with Spark

    main

    Spark allows you to add 3D Gaussian Splatting (3DGS) to your existing THREE.js scenes. By creating SplatMesh objects, you can render splats alongside traditional triangle-based meshes using your standard render(scene, camera) call.

    SplatMesh objects derive from THREE.Object3D, meaning they can be translated, rotated, placed anywhere in the scene hierarchy, and animated by adjusting their values each frame. You can instantiate a SplatMesh using a url parameter pointing to a splat file or by creating splats individually.

  7. Blend multiple SDF shapes in SplatEdit

    main

    When adding multiple SplatEditSdf shapes to a SplatEdit, their values are blended using an exponential "softmax" function. This blending is commutative, meaning the order of addition does not matter.

    To control the appearance of the transitions:

    • Increase SplatEdit.sdfSmooth to control the scale of blending between different SDF shapes.
    • Increase SplatEdit.softEdge to control the scale of the soft inside-outside boundaries of each shape.

    Displacement (XYZ) is blended in the same way as RGBA, allowing for complex, smooth deformations like rippling effects.

  8. Initialize and use the SparkRenderer

    main

    Spark uses a SparkRenderer object within your THREE.Scene to perform Gaussian Splat rendering. To use it, create an instance of SparkRenderer and add it to your scene (typically at the root). This object allows you to control rendering parameters like Level-of-Detail (LoD).

    Note: Your THREE.WebGLRenderer should be created with antialias: false to maximize performance, as WebGL anti-aliasing does not improve Gaussian Splatting results.

    const spark = new SparkRenderer({
      renderer: myThreeJsWebGlRenderer,
    });
    const scene = new THREE.Scene();
    scene.add(spark);
  9. Develop and contribute to Spark

    main

    To build Spark from source, you must have Rust installed on your machine. Follow these steps to build the WASM components and run the local development server:

    ```shell
    npm install
    npm run build:wasm
    npm run dev

    After running npm run dev, the examples will be available at http://localhost:8080/.

  10. Load auto-detectable splat formats (.ply, .spz, .sog, .rad)

    main

    Spark can automatically detect and load .ply (including compressed SuperSplat/gsplat variants and plain point clouds) and .spz (Niantic compressed format) based on file contents. You can instantiate a SplatMesh directly using a URL pointing to these files.

    // Load and create SplatMesh in one go
    const splats = new SplatMesh({ url: "./butterfly.ply" });
    scene.add(splats);
    
    // Auto-detection works even without file extensions
    scene.add(new SplatMesh({ url: "plyBin/0123456789abcdef" }));
    scene.add(new SplatMesh({ url: "spzBin/fedcba9876543210" }));
  11. Use the Dyno Standard Library convention

    main

    The Spark dyno system provides a standard library of Dyno blocks covering GLSL ES 3.0 functions. You can use two different syntaxes for these functions:

    1. PascalCase Classes: Using the new keyword with the class name.
    2. camelCase Helpers: Using ergonomic helper functions that internally instantiate the corresponding class.

    Both approaches are functionally equivalent.