I need to complete a project for the Software Engineering class and I was thinking that I can write my own render engine in Python. I have no idea how to do it, but I was always keen to look under the hood of this process.
It could be an extremely basic and super slow engine but at a bare minimum, it should be able to render provided model (say in obj format) with some basic lighting and material.
It’s feasible for a junior/mid-level programmer to complete this task in a couple of months? How hard would be to substitute a procedural sphere used in the examples with real geometry? Do you have other cool resources regarding this topic? What could be potential blockers for finalizing the project?
This is definitely possible and there have been a few developers out there who have embarked on this journey. While there are some game engines for python and other libraries, a few have decided to try out pure* python renderers.
This should be pretty doable, though a Python-only version will be pretty slow. If you decide to try it, think hard about:
memory layout – can you do this without creating and destroying lots of temporary objects, which is a big perf drain
limiting state – can you set it up without having to pass around lots of big heavy weight objects (ie, do you really need a class for points, or can you do it with a tuple, that sort of thing)
You can and should happily cheat on the side problems: if you’re wrting a raytracer, concentrate on raytracing and don’t get bogged down in writing your own graphics file read-write code; use libraries for that sort of thing
I am not concerned about the speed or memory consumption (at least at this point). The goal is to build something simple and understand how rendering works on the lowest level, where the magic of pure math happening
I get some progress, the render of the background image 4x2 pixels without any geometry, and even at this first step there are a lot of things that I need to understand (how camera and ray casting is working)
hello!
yes, it’s possible but as it was previously said it will be pretty slow.
I would probably stick with just spheres. Rendering a complete OBJ model would take forever.
I also made my own raytracer in Python for a class, you can see it here:
With multi-threading it takes like 17 seconds to render an image. I made a short animation like 8 seconds long and took like 5 days to render haha, but I did it in a computer in a lab from my university remotely so it wasn’t a problem at all. But I think using multi-threads would take like a day maximum.
And I have been writing a tutorial on how to make a Raytracer in Python. It’s in Spanish, but maybe you can read it using Google Chrome with translate activated, the images and code are in English: