An open source GPU renderer for Blender written in Python

GPU programming is becoming more and more accessible for programmers, and being a huge fan of Python, I wanted to test the limits of this. Could one write a performant renderer in Python? Also I’m lazy, and wanted to test some ideas for rendering algorithms in python.

So recently I came across this python package “Taichi” which basically let’s you translate Python code to run on the GPU. Pretty cool. My first try was to implement Peter Shirley’s “Ray Tracing in One Weekend” in this https://github.com/bsavery/ray-tracing-one-weekend-taichi. Which actually was quite fast for me to run. The language is a bit tricky to debug, but generally pretty simple once you wrap your head around the data fields (very similar to numpy).

Well, the next thing I thought was after translating the Ray Tracing in One Weekend, was “why not put this directly in blender”? Since it’s just Python code, you could have a whole render add-on in one codebase.

Here’s the result.
I’ll update this post as it moves forward, and this is a fairly early version that I wanted to share:


It will render Cycles scenes and use emissive materials for lights and all the other materials are treated as diffuse currently. There are some obvious artifacts with the geometry that I have to debug.

Currently the renderer is definitely slow. If I turn off updating each Frame it’s actually not bad, but there is zero optimization going on here. Some todos:

  • Optimizing the render loop
  • Adding Material Networks
  • Adding a BVH
  • Fixing polygon artifacts and misplaced geometry.
16 Likes

I should mention I very much appreciate feedback and input. If other’s want to contribute I would be very happy!

1 Like

Do you have an installable version? I would like to try it in Blender.

This is awesome, gonna try it out soon. Thanks for this. :grinning:

It is very good and great to start with your render system, please share more your progress and renderings and keep it up, thanks.

I am looking forward from this thread and it sounds like very interesting.

Happy blending and happy coding !

There should be install instructions in the readme just download the repo as a zip file using the “code” button in github

1 Like

what repo?
edit: oh this repo… :blush:

Oh sorry I forgot the link! https://github.com/bsavery/BlenderPythonRenderer

2 Likes

Man that’s so cool ! Any idea what those black artifacts on the BMW could be ?

Possibly numerical precision, though I’m not sure. Also the tire transform seems off clearly. You can see this in the rear tail light too. I haven’t had time to really debug that yet.

This is one downside to this Taichi framework, because it translates Python code via LLVM into something that can run on the GPU. So debugging it is a bit more difficult as you really have to look at the translated code.

1 Like

You linked the previous repo not the actual Blender renderer one.

Do you feel like Taichi framework also can be useful or be used for mesh processing in Blender?

I added a link to the top.

With regards to mesh processing. Absolutely. Take a look at the render/mesh.py file in the repo to look at how I read the blender mesh into a numpy array and then copy to a taichi field on the gpu. You’d just replace the “kernel” for taichi with some different code to manipulate the mesh.

5 Likes

Thanks, that is a super useful reply.

2 Likes

There is this free time why not change the api of your own prorender to hip, library to rays4.1, add more advanced material nodes.

1 Like

This is awesome, thx for spending the time on it. Look forward to updates.

Thanks for the kind words. I will after the holiday!

1 Like

Indeed it was a numerical precision issue. In particular me being lazy about it.

I’m going to focus on optimization in the next few days, then can improve the material / lighting quality.

3 Likes