Skip to content

SouthEndMusic/-NumbaShader

Repository files navigation

NumbaShader

About

This repository contains an implementation of shaders using Numba for CUDA GPUs. The 3D shaders use the concept of ray marching.

This is simply a hobby project, I make no claims about the robustness or efficiency of this code.

Examples

Examples of animations

Example stills

Contents

The folder NumbaShader3D contains:

  • The script shader_example_general.py which gives a short introduction on how a shader could be constructed using numba.cuda,
  • The script Shader_setupy.py which contains classes for a 3D camera model and viewing the shader output interactively with OpenCV,
  • The script Shader_tools.py which contains functions for computing the path of a ray trough a scene, based on intersections, reflections and refractions, as well as a simple method for creating depth of field.

the folder Fractals_on_text contains:

  • The script Poisson_2D.py for numerically solving the Poisson equation with either homogeneous Neumann or homogeneous Dirichlet boundary conditions,
  • several attempts at wrapping sections of the Mandelbrot set around letters in the notebooks Text_to_fractal.ipynb and Text_to_fractal_2.ipynb.

The main folder contains some more examples of 3D shaders:

  • The script Cube_grid.py contains an implementation for intersecting rays with a grid of cubes defined by 3D boolean array. Furthermore there are functions to define the Menger sponge or some text in the form of such a cube grid,
  • The script Game_of_life_3D.py also uses the cube grid implementation, but applies to the cube grid a 3D version of the Game of Life algorithm to create animations as seen in the second animation linked to below,
  • The script Menger_sponge.py implements the first animation linked to below with a sphere in the Menger sponge,
  • The script Menger_sponge.py uses the 3D shader to visualize the Mandelbulb, see the third animation linked to below,
  • The script N_body_fractal.py implements a shader to visualise the chaos arising from the N body problem, see the last animation linked to below.

Lastly the script Makevid.py contains a simple function to show and save animations as video files using OpenCV.