Crate wgpu_3dgs_viewer

Crate wgpu_3dgs_viewer 

Source
Expand description

§3D Gaussian Splatting Viewer

…written in Rust using wgpu.

Crates.io Docs.rs Coverage License

Cover.gif

§Overview

[!WARNING]

This library is under active development, breaking API changes between versions may occur frequently.

Use at your own risk.

This library displays 3D Gaussian Splatting models with wgpu. It includes a ready‑to‑use pipeline and modular pieces you can swap out.

  • Rendering pipeline
    • Preprocess: cull off‑screen points and set up indirect draw data.
    • Sort and draw: sort by depth and draw the Gaussians.
    • Modes: Gaussians may be displayed as splat, ellipse, or point.
    • Transforms: apply model or per-Gaussian transforms.
  • Abstraction for renderer and buffers
    • Viewer: one type that manages the buffers and pipelines.
    • Low-level access: preprocessor, sorter, renderer, and their buffers can be used separately.
    • Supports PLY and SPZ file formats.
    • GPU buffer allows for compressed and uncompressed formats.
  • Optional features
    • Multi-model: render many models with custom draw orders.
    • Selection: viewport selection (e.g. rectangle, brush) that marks Gaussians for editing.
  • Shaders
    • WGSL shaders packaged with WESL, you can extend or replace them.

§Usage

You may read the documentation of the following types for more details:

  • Viewer: Manages buffers and renders a model.
    • Preprocessor: Culls Gaussians and fills indirect args and depths.
    • RadixSorter: Sorts Gaussians by depth on the GPU.
    • Renderer: Draws Gaussians with the selected display mode.
  • MultiModelViewer: Viewer equivalent for multiple models. Requires multi-model feature.
  • selection: Select Gaussians based on viewport interactions, e.g. rectangle or brush. Requires selection feature.

[!TIP]

The design principles of this crate are to provide modularity and flexibility to the end user of the API, which means exposing low-level WebGPU APIs. However, this means that you have to take care of your code when accessing low-level components. You risk breaking things at run-time if you don’t handle them properly.

If you do not want to take the risk, consider using the higher-level wrappers and avoid any instances of passing wgpu types into functions.

§Simple Viewer

You can use Viewer to render a single 3D Gaussian Splatting model:

use wgpu_3dgs_viewer as gs;
use wgpu_3dgs_viewer::core::glam::UVec2;

// Setup wgpu...

// Read the Gaussians from the .ply file
let gaussians = gs::core::Gaussians::read_from_file(model_path, gs::core::GaussiansSource::Ply)
    .expect("gaussians");

// Create the camera
let camera = gs::Camera::new(0.1..1e4, 60f32.to_radians());

// Create the viewer
let mut viewer = gs::Viewer::new(&device, config.view_formats[0], &gaussians).expect("viewer");

// Setup camera parameters...

// Update the viewer's camera buffer
viewer.update_camera(
    &queue,
    &camera,
    UVec2::new(config.width, config.height),
);

// Create wgpu command encoder...

// Render the model
viewer.render(&mut encoder, &texture_view);

§Examples

See the examples directory for usage examples.

§Dependencies

This crate depends on the following crates:

wgpu-3dgs-viewerwgpuglamwesl
0.628.00.300.3
0.527.00.300.2
0.426.00.300.2
0.325.00.30N/A
0.1 - 0.224.00.29N/A

§Acknowledgements

This crate uses modified code from KeKsBoTer’s wgpu_sort.

References are also taken from other 3D Gaussian splatting renderer implemntations, including antimatter15’s splat, KeKsBoTer’s web-splat, and Aras’ Unity Gaussian Splatting.

Re-exports§

pub use wgpu_3dgs_core as core;
pub use wgpu_3dgs_editor as editor;

Modules§

selection
Selection of Gaussians via viewport interactions.
shader
Shader modules for the wesl::CodegenPkg wgpu-3dgs-viewer.

Structs§

Camera
A camera.
CameraBuffer
The camera buffer.
CameraPod
The POD representation of camera.
GaussiansDepthBuffer
The Gaussians depth storage buffer.
IndirectArgsBuffer
The indirect args storage buffer for Renderer.
IndirectIndicesBuffer
The indirect indices storage buffer for Renderer.
MultiModelViewer
The 3D Gaussian splatting viewer for multiple models.
MultiModelViewerBindGroups
The bind groups for MultiModelViewer.
MultiModelViewerGaussianBuffers
The buffers for Viewer related to the Guassian model.
MultiModelViewerModel
The model of the MultiModelViewer.
MultiModelViewerWorldBuffers
The buffers for Viewer related to the world.
Preprocessor
Preprocessor to preprocess the Gaussians.
RadixSortIndirectArgsBuffer
The dispatch indirect args storage buffer for RadixSorter.
RadixSorter
Radix sorter for sorting Gaussians based on their depth (i.e. clipped z value).
Renderer
A renderer for Gaussians.
Viewer
The 3D Gaussian splatting viewer.
ViewerCreateOptions
The options for creating a Viewer using Viewer::new_with_options.

Enums§

MultiModelViewerAccessError
The error type for accessing model in MultiModelViewer.
PreprocessorCreateError
The error type for Preprocessor::new.
RendererCreateError
The error type for Renderer::new.
ViewerCreateError
The error type for Viewer::new.

Traits§

CameraTrait
A camera trait.

Type Aliases§

DefaultGaussianPod
The default viewer GaussianPod type.
RadixSorterBindGroups