I simulated 40K blades of realtime grass with Python
HTML-код
- Опубликовано: 31 май 2024
- I managed to render 40,000 blades of interactive grass in realtime using Python and Pygame. This video covers some important concepts and applications involving hashmaps/dictionaries and caching!
Patreon (get the code here!):
/ dafluffypotato
My Projects:
dafluffypotato.com/projects
Discord:
/ discord
Potato Tier Patrons:
Keill
Eivl
David Graey
Agent Effe
Miggy
Chris Birster
Levi Jeske
#gamedev #python #pygame - Наука
get the code for the green things found on the ground here:
github.com/DaFluffyPotato/pygame-grass
finally you are voice is fun to hear
bro go back to unity. python is not good
I have a question about making Python Games. What do you do in terms of releasing it? I am currently working on an RPG through Pygame, but making an exe file seems to be a problem as anti viruses have a complete break down in windows.
@@masternobody1896 What made you feel the need to say that? It's his channel he does what he wants to do.
@@Nitr0h did he ever do unity???
As a computer science major and gamer I can confirm that we will do anything to avoid going outside and touching grass. Even if that include simulating the grass itself.
I've never seen 2d grass simulated so beautifully! I can't believe that's all done in python either! I should spend more time playing with python. I've been spending lots of quality time with C lately. Mostly because I want to learn those "good programming practices" people speak about. I have learned some useful things but I spend more time learning then I do making anything.
C will always be superior, performance wise. You'd probably be able to increase the performance of this implementation by at least five fold if you used C++ (but probably the performance increase would be much bigger). It's just that Python is usually much easier to program and you can get reasonable results pretty fast (fast as in programming time, not execution time), so it makes for a good prototyping language as well as a fun pass time project kind of programming language
me too I want to start doing rather than learning
@@carlosmspk hey can we be friends? I want programmer friends if you are interested , maybe we can do some projects too :) I learned python basics and currently learning C
@@historyrogue5056 With all due respect, I'm not interested. But if you want programmer friends all you have to do is get in the right circles. There are plenty of Discord channels filled with wide communities of programmers eager to help. You sound like someone who's getting started, so I assume you're relatively young, which is a great sign if you're already getting into this stuff. If you go to university, you'll find tons of programmers for sure, and it becomes much more engaging talking with people who are accompanying you throughout the journey!
@@carlosmspk Thanks for the tip Uncle
fluffy's python skills are still too much for me to handle. my brain's slower than python at this point lmao. amazing vid as always man :D
idk why the csgo cache reference made me laugh so much
Same here rofl , the good old memories
I started studying pygame this week, I didn't understand anything you said, but I love what you did with the grass, I hope I can do something close to it in the future.
dude this is so cool! Your videos always impress, keep killing it man!
Wow thank you :) The are some channels about pygame, but yours is unique. You explain indepth concepts not only code.
impressive! i just heard some concepts for the first time. i'm off to do more research on tile system and caching. thank you
Brilliant explanation to this. It's super interesting and cool to hear about!
My friend:- Hey do ya know who has mastered pygame
Me:- A potato is a pygame legend
Love you dafluffypotato 👍🏻👍🏻
my computer trying to run minecraft at 30 fps while watching this video
computer: do what now? nahhh
It's not Minecraft that's the bottleneck (assuming avg settings) it's gotta be the modern web. Browsing the web takes up so much ram and your web browser constantly needs to access your graphics card for all the content displayed on webpages. Many websites are quite taxing. RUclips can be heavy. I notice a performance hit on my desktop when I game and have a browser open. My laptop battery can go forever without a browser open. When I surf the web it dies very quickly.
I would like to know how pygame renders this. Is it using OpenGL in the backend and instancing? It has to be right? It can't be a software renderer, right?
It’s software rendering on one core of the CPU through SDL.
Pygame uses SDL. SDL is an abstraction of rendering APIs unified into one.
umm, dude, its extremely low res pixel art, no need for GPU
@@Liam-pf7ih This is a highly parallelizable problem and because it ran so smooth I assumed it was rendered using a GPU.
Actually software rendering can be faster than hardware rendering. Especially when working with low resolutions and small objects like here. GPU rendering is fast when used correctly, but it can also be slow when used incorrectly.
Thats awesome im new to python and working on pygame. So needless to say, most of my time is spent angrily reading documents and tutorials. Cant wait until i get to a piont of fluency where im able to do cool stuff like this on my own.
Thanks dude, great video! I was using Godot, which is very fun and easy to use, but felt like I wasn't learning much about programming. That's why I switched to python and pygame. Keep up the good work!
Next video - how I fixed and optimized CP2077 with python an pygame :)
Hey Fluffy.. Is it possible to play the pygames on phone? I mean is it possible? Requires an APK? Or I have to Host the game someway and then im able to play on Chrome on my phone?
You can use something like pydroid3
To increase performance, you can have the grass "bundled" into groups and rendered together as a patch of grass. It would take some reworking but i bet you can double the performance. Been watching your vids for a long time, love your progress.
That doesn’t work because of wind. Any cached element needs to be unified in how wind affects it. If you have a grass patch unified by in wind effects, it’s effectively just a larger tile size. There wouldn’t be a difference in performance. If tiles within a patch can vary in how they’re affected by wind, then you still have to rebuild the entire patch’s image every frame.
This system in your next game jam relating to farming sims
amazing, i can finally touch grass without going outside
When was it so satisfying to put grass on the floor?
Instead of making a tile shaped brush, make a probability brush, where the center of the brush has the highest probability of logic/graphic updates. Then your brush will be a circle fade and force less calculations.
The problem with using python for game dev is that it's really hard to get a non python user to run your game. Actually compiling Python code into a .exe is a complete PITA
PyInstaller
Once I went AutoPy2Exe I never had to worry about anything
@@overratedprogrammer NECRONOMICON +3 int | +9 str
year old comment joke aside...
I'll check it out, thank you!
Great video
This is incredibly impressive
dude that is amazing!
Have you considered using a quad tree for mapping the grass blades instead of your current system?
A quad tree would only help with collisions. It would actually make wind slower and only provide a marginal benefit to collisions in certain circumstances. If implemented properly, you could get a small boost overall, but it’s not really worth the effort due to all the other details that go into that.
I'm still struggling to learn pygame much less python lol fuck dude your a god at this , I love this language and engine
I can teach you if you want me to
Nice Video
gosh if i had a company i would want you as my employee xD
potat has blessed us with another very informative video
This video is greatr dude...
In your video titled "Pygame Tutorial - Making a Platformer ep. 4: Camera Movement and Parallax Scrolling" in the description you wrote "The implementation of a camera is actually an illusion. Instead of moving a "camera", you just move everything on screen." My question is would it work if I had a multiplayer game?
I guess if you only moved the visual screen locally on their host device then mabey
@@justsomeguy6545 aka client side
well played sir, you are the reason i shelved shelfed? (whatever) unity and c# for python because I'm a complete beginner at coding and learning python is so much easier. and honestly in all my time in unity i just learned how to use there GUI and assets store. And C# is way to advance for me as a newbie anyway i cant understand the syntax well, i find python easy to read and i wrote my first app in python today (calculator lol). ok ill be real for a second i have pygame 2 installed but i haven't used it yet I'm still learning the python basics but I'm having so much more ' fun ' learning python i feel like I'm absorbing the information better. so what i can use unity and make a map and a few levels fast but from what I've learned from you i can use python to build AI (business and gaming), and even web apps. sure c# can aswell but i think anyone here reading this who is a noob like me knows c# is not as 'easy' as all the generic tutorials say, but let me end this by saying thanks for making content and inspiring me and others. i don't think how much you have changed my thinking on coding and game development as a whole. take care and stay breezy like that grass. much love from South Africa.
EDIT: 1am here and im baked sorry for the grammar.
How intriguing..
Super cool! :D
Got to admit, I still don't understand what exactly a "tile" is in this context. There doesn't appear to be much reusability when it comes to different patches of ground/grass. I assume these tiles are dynamically generated? How many different tiles do you have? How big are they? What's in them? Does every tile (let's say "square meter of land" in your game world) just have its own caching of 30 different wind states, and you only render the cached tile in case no local forces are applied? Which would mean that you probably couldn't have a huge world, since every single tile would linearly eat additional (V)RAM. But it's unclear to me how you'd make it reusable efficiently. So many questions. Say there was a big explosion sending a shock wave through the whole screen, so non-global forces affecting every tile. Would that thus cause a huge drop in the frame rate, since you wouldn't be able to render cached tiles, but had to render individual blades of grass instead?
Demo looks lovely btw. :)
I guess you could have a huge game world if there's another layer of optimization, where you always cache only roughly what's currently in view, and while the camera is moving you update this sliding frame of what's being cached, and regenerate those tiles that come into view that hadn't been cached before.
Am I getting this right, or am I misunderstanding the nature of tiles and caching going on here?
Tiles work similarly to my other videos about tiles. It allows for quick lookup. It’s also a layer at which images are cached. They’re dynamically generated.
Tile size can vary and the amount varies depending on settings (a tradeoff between visual uniqueness and smoothness for RAM). Many of the tiles will share the same cached images. Tiles will reuse blade layouts (from a pool of a specified amount).
You’re correct that the cached version only gets rendered if no local forces are applied. Since layouts are reused the RAM can be kept under 100MB for millions of blades of grass. The cached images do not scale linearly, but the position/rotation data for each blade does (although it’s small). So you can have massive worlds.
For an explosion, you could get away with using the wind functionality to affect all the tiles efficiently. The “wind” is for anything of large scale impact where the blade-to-blade detail isn’t as necessary.
you are a pygame god
holy heck, all with just pygame WHAT
this is just cool :o
Would suing numpy array instead of dictionary make it more beneficial ?
PS. I'm not experience programmer and more of a C++ guy than python guy.
thinking what if you were using a game engine - hope that devs will make a bit more unity performant pls
Hashmaps are underutilized. Take an anagram solver for example.
❤
it has been about a year. wonder if the source code will be released
It was
@@DaFluffyPotato interesting.
You madman
As a stupid idiot I naturally thought the title was "I slammed 40k blades into grass with Pythons" LMAO
Thought warhammee. Im a dumbass. great vid.
Amaze balls!
Finally, I can touch grass
Só beautiful
Hi DaFluffyPotato, I have a question. I'm curious as to why you use Python's Pygame instead of something lower level with other languages. Because if one of your main purpose is to learn from the experience, wouldn't a lower level library and language be a more suitable choice? Why are you so committed to Pygame? I'm just looking for an answer to this dilemma, because I've been having trouble deciding between using Pygame(which I'm already familiar with), or learning something lower level to better my understanding of low-level languages. Thank you so much DaFluffyPotato! Love you!!
Python is more likely to get you a job than C++. Lower level isn’t necessarily better. Also I can make games quicker with Python.
@@DaFluffyPotato Ah of course, hmm. That gives me a new perspective on things. Thank you! However, would you say that lower level languages improve your skills as a programmer in whole?
They can, but it goes the other way as well. I know C++, C, and Java (and many other languages). I just prefer to use Python. Knowing a variety of languages is good.
@@ilovedatfruitybooty9546 Learning C and C++ can give you more experience in programming but for game development, It really depends on you. Would you prioritise Performance over Everything else? If so then learn C++. If not then learning Java or C# is much better. For Java you can use libGDX and for C#, Use Monogame(XNA framework) or Raylib-cs. For C++ You can use SDL2 or SFML or Raylib. But for ease of development go for Pygame. Also Java and C# are very similar. If you want a less verbose language which has some better features than java, then learn kotlin but since it is fairly new. It doesn't have a large Community or vast amount libraries like Python.
@@DaFluffyPotato I mean, depends on the industry, if you are going into game dev certainly not.
cool... im stupid
how are you so smart? It's unreal!?!
Basically hard work and consistency, he studies and practice programming for a bunch of years and you can do the same you just have to start (now).
it is not unreal... it is pygaame!
Noice
Le fish
That's a lot of grass
That's hardcore
Wait hol up I know this guy
smilew
only 40000 blades of grass? omg pygame is so slow smh
Great video as always 😊. To be honest, I personally would use C#, instead of worrying about performance and having to deal with dynamic typing, C# is so fast that it outperforms C++ in some areas, and its syntax is pretty easy, a Python expert like you won't have a lot of trouble learning C#.
C# is nowhere near as fast as C or C++...
Yeah idk where he gets "C# is faster" from. C++ is definitely faster.
one hour intro, then self promotion of your patreon and not showing the 40k blades...
yeah no, disliked and gonna leave. realised im not that interested in seeing 40k grass blades.
1. The video itself is less than 7 minutes long
2. Every RUclipsr does it
3. Try the code yourself, he left it free
4. Don't watch it and leave the buttons blank
gt
Really interesting topic, but I really recommend you work on your presentation skills. And I don't mean visuals (they are ok), but the tone of voice, intonation, and general energy could be improved. Again, this is really interesting topic but I struggled to watch till the end. Just a friendly advice from somebody that seen a lot of YTs about coding 🙂
❤