1 unstable release
Uses new Rust 2024
| new 0.1.0 | Jan 22, 2026 |
|---|
#829 in Embedded development
Used in 3 crates
74KB
1.5K
SLoC
Rust IRMF Shader Slicer
Summary
IRMF (Infinite Resolution Materials Format) is a file format used to describe GLSL ES or WGSL shaders that define the materials in a 3D object with infinite resolution. IRMF eliminates the need for traditional software slicers, STL, and G-code files used in 3D printers.
I believe that IRMF shaders will some day revolutionize the 3D-printing industry.
See irmf.io for more details.
About the IRMF Shader Slicer
This Rust crate is a port of the Go IRMF Slicer and is a technology demonstration of how to embed an IRMF Slicer into the firmware of a 3D printer. Included in this repo is a standalone command-line version that demonstrates the usage of this crate.
The technology stack used is Rust and OpenGL or WebGPU.
This crate can be used by 3D printer hobbyists and manufacturers to natively support IRMF shaders in addition to G-Code or voxel slices.
The standalone command-line program irmf_slicer is a program that
slices an IRMF shader model into either STL files
or into voxel slices (with various output file formats).
For STL files, it outputs one STL file per material.
(Note that some STL files can become enormous, way larger than any online
service bureau currently supports. The resolution can be reduced to limit
the STL file sizes, but at the expense of detail loss.)
For voxel slices, irmf_slicer can write them out to ZIP files (one ZIP file per material).
These slices can then be fed to 3D printer software that accepts
voxel slices as input for printing (such as NanoDLP).
For resin printers using either the ChiTuBox or
AnyCubic slicer
(such as the Elegoo Mars),
the --dlp option will output the voxel slices to the .cbddlp file
format (which is identical to the .photon file format).
Once 3D printers support IRMF shader model files directly for printing, however, this standalone slicer will no longer be needed.
LYGIA support
As of 2022-10-27, support has been added for using the LYGIA Shader Library at: https://lygia.xyz !
This means that you can add lines to your IRMF shaders like this:
#include "lygia/math/decimation.glsl"
and the source will be retrieved from the LYGIA server.
Congratulations and thanks go to Patricio Gonzalez Vivo for making the LYGIA server available for anyone to use, and also for the amazing tool glslViewer!
Architecture
This project is organized as a Rust workspace to provide a lean core library suitable for embedding in firmware, while also offering a full-featured CLI tool.
irmf-slicer: The core rendering and slicing library. It is designed to be lean, performing no file I/O or networking. It useswgpufor hardware-accelerated offscreen rendering.irmf-slicer-cli: A standalone command-line tool for slicing IRMF models.irmf-include-resolver: A utility for resolving#includedirectives (e.g., from lygia.xyz or GitHub).irmf-output-stl: STL generation logic (using Marching Cubes).irmf-output-voxels: Shared voxel processing and support for Binvox, ZIP (PNG slices), Anycubic Photon (.cbddlp), and SVX formats.
Features
- Multi-Language Support: Full support for both GLSL and WGSL shaders.
- Hardware Acceleration: Uses
wgpufor fast, cross-platform GPU rendering (Vulkan, Metal, DX12, WebGPU). - Multiple Output Formats:
- STL: High-quality meshes generated via Marching Cubes.
- Binvox: Standard voxel format.
- ZIP: Archive of PNG slices, compatible with NanoDLP.
- DLP (.cbddlp): Compatible with Anycubic and ChiTuBox-based resin printers.
- SVX: Simple Voxel Format.
- Remote Includes: Automatic resolution of
#includedirectives fromlygia.xyzand GitHub. - Offscreen Rendering: No windowing system required for slicing (though a
--viewmode is available for debugging).
How it works
This slicer dicing up your model (the IRMF shader) into slices (planes) that are perpendicular (normal) to the Z (up) axis. The slices are very thin and when stacked together, represent your solid model.
Using the --zip option, the result is one ZIP file per model material
with all the slices in the root of the ZIP so as to be compatible
with NanoDLP. When using the --zip option, the resolution is set
to X: 65, Y: 60, Z: 30 microns (unless the --res option is used to
override this) in order to support the MCAST + Sylgard / 65 micron
option of NanoDLP.
Using the --dlp option, the result is one .cbddlp file per model material
that can be loaded into the ChiTuBox or
AnyCubic
slicer directly (.cbddlp is identical to the .photon file format).
Using the --stl option, the result is one STL file per model material.
Using the --binvox option, it will write one .binvox file per model material.
Usage (CLI)
Installation
After you have a recent version of Rust installed, run the following command in a terminal window:
$ cargo install --path irmf-slicer-cli
(Or $ cargo install irmf-slicer if you are installing from crates.io.)
Examples
To slice one or more .irmf files, just list them on the command line.
Slice a model into STL files:
irmf-slicer-cli --stl examples/001-sphere/sphere-1.irmf
Slice a model for a resin printer (DLP):
irmf-slicer-cli --dlp examples/001-sphere/sphere-1.irmf
View the slicing process in real-time:
irmf-slicer-cli --view --zip examples/002-cube/cube-1.irmf
The output files will be saved in the same directory as the original input IRMF files.
Usage (Library)
To use the IRMF slicer in your own Rust project, add the irmf-slicer crate to your Cargo.toml.
use irmf_slicer::{IrmfModel, WgpuRenderer, Slicer};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let data = std::fs::read("model.irmf")?;
let model = IrmfModel::new(&data)?;
let renderer = WgpuRenderer::new().await?;
let mut slicer = Slicer::new(model, renderer, 42.0, 42.0, 42.0);
slicer.prepare_render_z()?;
slicer.render_z_slices(1, |idx, z, radius, img| {
img.save(format!("slice_{:04}.png", idx))?;
Ok(())
})?;
Ok(())
}
License
Copyright 2019 Glenn M. Lewis. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Dependencies
~26–60MB
~1M SLoC