DEV Community

Cover image for Demystifying 3D Graphics: I Built a Mini-Renderer in Python
Aiden
Aiden

Posted on

Demystifying 3D Graphics: I Built a Mini-Renderer in Python

If you want to learn 3D graphics programming today, the learning curve is a cliff. You either spend months learning the intricacies of Vulkan/OpenGL in C++, or you use a massive engine like Unity where the actual graphics math is hidden behind a heavy user interface.

I wanted something different. I wanted a way to write basic Python, understand the math from first principles, and get immediate visual feedback.

So, I built Aiden3DRenderer, an open-source, real-time 3D function visualizer and GPU playground written in Python.

Visualizing Math with One Function:
The core philosophy of the project is that you shouldn't need a graphics background to build a 3D scene. If you can write a loop in Python, you can render a 3D surface.

Instead of messing with vertex buffers, you just write a function that returns a matrix of (x, y, z) tuples and use the @register_shape decorator. Here is how easy it is to generate a 3D Gaussian Hill:

import math
from aiden3drenderer import register_shape, Renderer3D, renderer_type

@register_shape("Gaussian Hill", is_animated=False, color=(220, 220, 220))
def gaussian_hill(grid_size=48, frame=0):
    matrix = []
    half = grid_size / 2
    for i in range(grid_size):
        row = []
        for j in range(grid_size):
            x = (i - half) / (grid_size / 6)
            y = (j - half) / (grid_size / 6)
            z = math.exp(-(x * x + y * y))
            row.append((x, z, y))
        matrix.append(row)
    return matrix

renderer = Renderer3D()
renderer.render_type = renderer_type.POLYGON_FILL
renderer.run()
Enter fullscreen mode Exit fullscreen mode

Writing Your First Shader in 5 Minutes:
One of the most intimidating parts of graphics programming is shaders. I built a headline feature that lets you write a small GLSL compute shader, plug it right into a Python script, and run it without any heavy boilerplate.

You just define your GLSL as a string:

#version 430
layout(local_size_x = 8, local_size_y = 8) in;
layout(std430, binding = 0) buffer pixels {
    vec4 data[];
};
uniform uint width;
uniform float time;

void main() {
    uint x = gl_GlobalInvocationID.x;
    uint y = gl_GlobalInvocationID.y;
    uint idx = y * width + x;
    float u = float(x) / float(width);
    data[idx] = vec4(u, 0.5 + 0.5 * sin(time + u * 10.0), 0.25, 1.0);
}
Enter fullscreen mode Exit fullscreen mode

And dispatch it directly from the Python engine using the CustomShader class.

Explore the Code:
Because the engine is built for education, the projection pipeline is implemented manually. You can read the source code and actually understand how 3D coordinates are mapped to a 2D screen. It also includes camera controls, OBJ loading, and a compact physics system.

If you are learning, tinkering, or teaching 3D math, I would love for you to try it out. You can check out the source code, see the gallery of animations, and read the full documentation on GitHub here:

GitHub logo AidenKielby / Aiden3DRenderer

A real-time 3D function visualizer with a plug-and-play GPU pipeline—write simple compute shaders to create custom effects without dealing with complex rendering internals.

PyPI Downloads PyPI version Python Versions Per Month License: MIT PyPI status GitHub stars Last commit

Aiden3DRenderer

Interactive 3D playground for learning math, Python, and GPU shaders from first principles.

No graphics background required. If you can write basic Python, you can build and understand 3D scenes here.

If this project teaches you something useful, please give it a star. It helps a ton and keeps this passion project growing.

A quick note

I built this because I wanted 3D graphics to feel less "mystical" and more hands-on So instead of hiding the pipeline behind a giant engine, this project keeps the core ideas visible: projection math, shape generation, shader logic, and simulation.

If you are learning, tinkering, or teaching with this repo, that is exactly what it was made for.

Who is this for?

  • Math/CS students who want to visualize 3D functions by writing one Python function.
  • Python learners who want a visual project with instant feedback instead of only terminal output.
  • Aspiring graphics developers

Top comments (0)