How I Created a Voxel Raycaster in Python...

preview_player
Показать описание

Voxel Space GitHub (by Sebastian Macke):

Comanche gameplay credit:

My microphone (affiliated):

Youtube growth tool (affiliated):
Рекомендации по теме
Комментарии
Автор

For performance you should rewrite it in Rust and then hand $5, 000 in cash to me immediately. This will surely improve your FPS

dungeonrobot
Автор

Cache Combine Distant Voxels: when more than one voxel looks like a single pixel.

ThankYouESM
Автор

- march along the ray not from left to right (fill columns first, helps with caching)
- use numba with forced inlining to improve the speed
- use a non linear LOD function
- use a custom array accessor for numpy arrays (unsafe but faster)

What i did for my python voxel engine is:
- used numbas prange() which is parallel processing. (This is very simple)
- rewrote it in nim with sdl2 and it was still 10x faster than the optimized python version.
- currently in the process of using compute shaders to speed it up (grahpics card => parallel processing)

if you get some headroom from optimizations, i would suggest adding a bilinear filter for the colormap and heightmap, which impoves the visual quality alot.

Bennet
Автор

Some Ideas on optimizing:
-Profile your code! If you don't know what's actually slowing down your program you'll probably spend huge amounts of time just optimizing small things that aren't actually the bottleneck of your program. And in the worst case you'll even slow down parts of your program.
-Make sure your using library calls correctly. My personal experience with python graphics is very limited, but it could be that the calls to functions drawing your image and presenting it are taking much longer then expected. In graphics programming generally when rendering the image try to keep calculation of the image and presentation seperate. Hand the rendering API only the finished image as memory operations are much more expensive than math operations.
-And lastly: If you're actually trying to get comparable speeds, you will need to use a faster language, like c/c++/rust. It may seem daunting at first, but in the end they are also just programming languages and thus more similar to python than not. Your rendering code for example could look nearly identical. And by using all the high level features provided by the standard libraries of these languages you don't have to be some kind of wizard to use them.

Well I'm interested to see what you'll code in the future!

Lexxaro
Автор

Dude I had a choice between 2 amazing youtubers and well looking I noticed you, ofc I have to click God bless your sorce code on a textured raycaster helped me so much. funny enough I've used that exact same voxel pixel renderer that your showing on the screen right now to make a doom clone deathmatch shooter that me and my bother love Amen man wish you well

The-python-guy
Автор

Pretty coool, I would suggest using numba to speed things up

FinFET
Автор

i think you could optimize it by using a different coding language and using parallel processing

poptre
Автор

bro was like 'refrain from mentioning parallel processing' but since you can separate and calculate all the verical lines independently of each other you can just use numba in parallel for one of the loops. You have to reorder your z and x loops though, so that you go first through each vertical line and then for it you go through each z distance. For the same resolution that you set and with render distance of 2000 I got like 700-800fps...

yovo
Автор

Also, this is coming from someone writing a Vulkan renderer for fun, so take this with a grain of salt, but OpenGL is not very hard to learn. Some of it doesn’t transfer great to Python, so if you really want it to go fast I’d honestly say moving to Kotlin (likely using LWJGL’s OpenGL bindings) would probably go reasonably well considering you know Python already.

electrobean
Автор

this reminds me of a spoonkid video, this is wonderful

coleslater
Автор

First of, what I don't see a lot of ppl mentionning here, is to try identify what truly makes your code slow down... Forget about implementing x or y blindly. Without knowing what kind of issue you are addressing (memory banwidth ? Too much computation ?) you are not going to make significant improvement.

So get a python profiler, learn a bit how pygame works (bc imho you may be calling its graphic api in an very unsufficiant maneer), and see which functions calls slow you down. Then, and only then try to think about optimization :
Is computing the square root too much ? Maybe try an approx.
Is blitting one pixel after another too expensive ? Maybe try to coerce chunk of colors together. etc etc..

Finally, when this repeated over and over, and you can't get much more, only then should you consider multiprocessing (which is a whole another beast on its own)

That's how I would do it. Have fun !!!

anzo.
Автор

Wow make this more popular get this guy to 1m subs

Bunn-yFnaf
Автор

you need to blow up i love your videos

ginodianna-hz
Автор

Just in case still too slow no matter what you do... have Javascript with JSON creating temp (buffer overwriting) PNG1 + PNG2 to do all the heavy lifting so it reads like MP4 streaming instead.

ThankYouESM
Автор

Avoid the use of floating point numbers altogether when rendering in gameplay by using dict() cache or memoization.

ThankYouESM
Автор

one optimization technique is to use c++

jasm_
Автор

Using a jit compiler should improve performance drastically

moldybot
Автор

you could try running it with pypy
its an alternative python implementation thats quite fast and very compatible with cpython code

axiomgd
Автор

Maybe use resize * 16 + PIL blur to create the height map

ThankYouESM
Автор

Try running it in pypy.
Pypy is just a python interpreter but is much faster than cpython.

Person-who-exists