Image2Shadertoy is a Python script that converts a 2D image into a Shadertoy-compatible GLSL shader using Gaussian splatting. It trains a set of 2D Gaussians to approximate the input image and generates a compact Shadertoy shader that renders the image in real-time on the GPU. The script is optimized for performance and memory efficiency, supporting both small and large Gaussian counts through a hybrid rendering approach (vectorized for small counts, tiled for large counts).
This tool is ideal for artists, developers, and researchers interested in procedural image rendering, shader programming, or Gaussian splatting techniques.
- Gaussian Splatting: Represents an image as a collection of 2D Gaussians with RGB colors, positions, scales, anisotropy, and rotations.
- Shadertoy Output: Generates optimized GLSL code for Shadertoy, packing Gaussian parameters into
uvec3arrays for efficient rendering. - Hybrid Rendering: Uses vectorized rendering for small Gaussian counts (<500) and tile-based culling for larger counts to balance speed and memory.
- Training Pipeline: Trains Gaussians in multiple stages, adding more Gaussians based on reconstruction error and pruning low-contribution ones.
- Command-Line Interface: Flexible inputs for image paths, output files, initial Gaussian count, and iterations.
- Regularization: Includes sparsity, sigma, and anisotropy regularization to ensure compact and visually accurate results.
- Python: 3.8 or higher
- PyTorch: GPU support recommended (CUDA-compatible GPU)
- Dependencies: Listed in
requirements.txt
- Clone the Repository:
git clone https://github.com/yourusername/Image2Shadertoy.git cd Image2Shadertoy
- Run the example command to confirm it works:
python Image2Shadertoy.py -i neo.png -n 32- Check that
result.pngandresult.shadertoyare generated correctly. - Upload
result.shadertoyto Shadertoy to verify it rendersneo.pngaccurately.
Input: neo.png |
Output: result.png |
|---|---|
![]() |
![]() |
- Here you can see the example running on a shadertoy.

