Gsdf
3D/2D CAD design package written in Go. GPU accelerated.
Install / Use
/learn @soypat/GsdfREADME
gsdf
gsdf is a CAD 3D design library for Go that uses SDFs for shape definition. Rendering can be done on GPU or CPU
for visualization or 3D printing file outputs. Quick jump to usage: bolt example.
All images and shapes in readme were generated using this library.
Requirements
Features
-
High test coverage (when GPU available, not the case in CI)
-
NEW!: Reusable GLSL code between shaders. See
glbuild/glsllib -
Extremely coherent API design.
-
UI for visualizing parts, rendered directly from shaders. See UI example by running
go run ./examples/ui-mandala -
Generate visualization for your parts as shaders.
-
GPU and CPU implementations for all shapes and operations. CPU implementations are actually faster for simple parts.
-
Include arbitrary buffers into GPU calculation. See
Shaderinterface. -
Heapless algorithms for everything. No usage of GC in happy path.
-
Heapless Octree triangle renderer. Is stupid fast.
- Design your part using one API, switch between CPU and GPU after design.
-
TinyGo supported for CPU evaluation :)
Package layout/structure
gsdf: Top level package defines exact SDFs primitives and operations for use on CPU or GPU workloads. Consumesglbuildinterfaces and logic to build shaders.glbuild: Automatic shader generation interfaces and logic.gleval: SDF evaluation interfaces and facilities, both CPU and GPU bound.glrender: Triangle rendering logic which consumes gleval. STL generation.forge: Engineering applications. Composed of subpackages.textsdfpackage for text generation.threadspackage for generating screw threads.
gsdfaux: High level helper functions to get users started up withgsdf. See examples.
Examples
Find examples under examples directory. Run on GPU with: -gpu flag.
Most 3D examples output two files:
example-name.glsl: Visualization shader that can be copy pasted into shadertoy to visualize the part, or rendered within your editor with an extension such as the Shader Toy Visual Studio Code extension.example-name.stl: Triangle model file used in 3D printing software such as Cura. Can be visualized online in sites such as View STL.
Output and timings for
- CPU: 12th Gen Intel i5-12400F (12) @ 4.400GHz
- GPU: AMD ATI Radeon RX 6800
npt-flange - 9× GPU speedup
This was converted from the original sdf library example.
GPU rendering in 1 second. 0.4M triangles
time go run ./examples/npt-flange -resdiv 400 -gpu
using GPU ᵍᵒᵗᵗᵃ ᵍᵒ ᶠᵃˢᵗ
compute invocation size 1024
instantiating evaluation SDF took 115.587024ms
wrote nptflange.glsl in 97.829µs
evaluated SDF 46148621 times and rendered 423852 triangles in 1.103100086s with 95.7 percent evaluations omitted
wrote nptflange.stl in 710.038498ms
finished npt-flange example
go run ./examples/npt-flange -resdiv 400 -gpu 1,01s user 1,10s system 95% cpu 2,217 total
CPU rendering in 9 seconds. 0.4M triangles
time go run ./examples/npt-flange -resdiv 400
using CPU
instantiating evaluation SDF took 14.173µs
wrote nptflange.glsl in 73.155µs
evaluated SDF 46147934 times and rendered 423852 triangles in 8.482344469s with 95.7 percent evaluations omitted
wrote nptflange.stl in 703.931017ms
finished npt-flange example
go run ./examples/npt-flange -resdiv 400 9,01s user 0,82s system 103% cpu 9,481 total
fibonacci-showerhead - 40× GPU speedup
Note that the amount of triangles is very similar to the NPT flange example, but the speedup is much more notable due to the complexity of the part.
GPU rendering in 0.87 seconds. 0.3M triangles
time go run ./examples/fibonacci-showerhead -resdiv 350 -gpu
using GPU ᵍᵒᵗᵗᵃ ᵍᵒ ᶠᵃˢᵗ
compute invocation size 1024
instantiating evaluation SDF took 108.241558ms
wrote showerhead.glsl in 581.351µs
evaluated SDF 14646305 times and rendered 309872 triangles in 768.731027ms with 89.08 percent evaluations omitted
wrote showerhead.stl in 509.470328ms
showerhead example done
go run ./examples/fibonacci-showerhead -resdiv 350 -gpu 0,87s user 0,69s system 94% cpu 1,646 total
CPU rendering in 36 seconds. 0.3M triangles
time go run ./examples/fibonacci-showerhead -resdiv 350
using CPU
instantiating evaluation SDF took 27.757µs
wrote showerhead.glsl in 507.155µs
evaluated SDF 14645989 times and rendered 309872 triangles in 35.794768353s with 89.08 percent evaluations omitted
wrote showerhead.stl in 499.13903ms
SDF caching omitted 21.62 percent of 14645989 SDF evaluations
showerhead example done
go run ./examples/fibonacci-showerhead -resdiv 350 36,16s user 0,76s system 100% cpu 36,591 total
More examples
Related Skills
xurl
353.1kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
wanwu
3.8kChina Unicom's Yuanjing Wanwu Agent Platform is an enterprise-grade, multi-tenant AI agent development platform. It helps users build applications such as intelligent agents, workflows, and rag, and also supports model management. The platform features a developer-friendly license, and we welcome all developers to build upon the platform.
