Skip to content

Mandelbulb

Portalez Régis edited this page May 11, 2026 · 1 revision

Mandelbulb

Real-time 3D Mandelbulb fractal renderer. Distance-estimation raymarching on the GPU, output rendered via OpenTK (OpenGL 4) against a cudaSurfaceObject_t shared between CUDA and OpenGL. The window is interactive — rotate the camera with the mouse, change the light angle, etc.

Source: src/3.Maths/Mandelbulb/.

Key files:

  • Mandelbulb.cs — the device-side distance estimator and per-pixel shading kernels.
  • MathFunctions.csfloat3 vector math (normalize, cross, dot, etc.) all marked [Kernel].
  • TextureHelper.cs — registers an OpenGL texture for CUDA interop via cudaGraphicsGLRegisterImage.
  • Program.cs — OpenTK GameWindow plumbing and the main render loop.

What this sample showcases:

  • CUDA-OpenGL interop: cudaGraphicsResource_t + cudaGraphicsMapResources to give a CUDA kernel direct write access to an OpenGL texture without a CPU round-trip.
  • cudaSurfaceObject_t: bindless surface writes from inside the kernel.
  • Heavy use of float3 arithmetic: shows that user-defined [Kernel] math helpers compose just like CUDA-side __device__ functions.

Requires an OpenGL 4-capable driver and a window manager (won't run headless on a server without an X server).

Clone this wiki locally