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
  • НаукаНаука

Комментарии • 113

  • @DaFluffyPotato
    @DaFluffyPotato  2 года назад +50

    get the code for the green things found on the ground here:
    github.com/DaFluffyPotato/pygame-grass

    • @masternobody1896
      @masternobody1896 2 года назад

      finally you are voice is fun to hear

    • @masternobody1896
      @masternobody1896 2 года назад

      bro go back to unity. python is not good

    • @kyoujinko
      @kyoujinko 2 года назад

      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.

    • @Nitr0h
      @Nitr0h 2 года назад +3

      @@masternobody1896 What made you feel the need to say that? It's his channel he does what he wants to do.

    • @metgaming9545
      @metgaming9545 Год назад

      @@Nitr0h did he ever do unity???

  • @TriBread1
    @TriBread1 2 года назад +106

    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.

  • @johnburton7156
    @johnburton7156 2 года назад +155

    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.

    • @carlosmspk
      @carlosmspk 2 года назад +9

      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

    • @historyrogue5056
      @historyrogue5056 2 года назад

      me too I want to start doing rather than learning

    • @historyrogue5056
      @historyrogue5056 2 года назад

      @@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

    • @carlosmspk
      @carlosmspk 2 года назад +6

      @@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!

    • @historyrogue5056
      @historyrogue5056 2 года назад +1

      @@carlosmspk Thanks for the tip Uncle

  • @mahyellaw
    @mahyellaw 2 года назад +49

    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

  • @DoomSkullYT
    @DoomSkullYT 2 года назад +38

    idk why the csgo cache reference made me laugh so much

    • @nickbubuioc
      @nickbubuioc 2 года назад +3

      Same here rofl , the good old memories

  • @jonaspetty8767
    @jonaspetty8767 2 года назад +4

    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.

  • @WvyyFPS
    @WvyyFPS 2 года назад

    dude this is so cool! Your videos always impress, keep killing it man!

  • @Pyrografpl
    @Pyrografpl Год назад +1

    Wow thank you :) The are some channels about pygame, but yours is unique. You explain indepth concepts not only code.

  • @salma-amlas
    @salma-amlas 11 месяцев назад

    impressive! i just heard some concepts for the first time. i'm off to do more research on tile system and caching. thank you

  • @Skeffles
    @Skeffles 2 года назад

    Brilliant explanation to this. It's super interesting and cool to hear about!

  • @machinze_edits
    @machinze_edits 2 года назад +8

    My friend:- Hey do ya know who has mastered pygame
    Me:- A potato is a pygame legend
    Love you dafluffypotato 👍🏻👍🏻

  • @unpleasentterrarian8475
    @unpleasentterrarian8475 2 года назад +6

    my computer trying to run minecraft at 30 fps while watching this video
    computer: do what now? nahhh

    • @johnburton7156
      @johnburton7156 2 года назад +1

      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.

  • @simonfarre4907
    @simonfarre4907 2 года назад +19

    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?

    • @DaFluffyPotato
      @DaFluffyPotato  2 года назад +14

      It’s software rendering on one core of the CPU through SDL.

    • @qixsphere.1600
      @qixsphere.1600 2 года назад +1

      Pygame uses SDL. SDL is an abstraction of rendering APIs unified into one.

    • @Liam-pf7ih
      @Liam-pf7ih 2 года назад +2

      umm, dude, its extremely low res pixel art, no need for GPU

    • @simonfarre4907
      @simonfarre4907 2 года назад +14

      @@Liam-pf7ih This is a highly parallelizable problem and because it ran so smooth I assumed it was rendered using a GPU.

    • @krux02
      @krux02 2 года назад +2

      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.

  • @marshallwages5035
    @marshallwages5035 2 года назад +1

    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.

  • @PeritoProducciones
    @PeritoProducciones 2 года назад +1

    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!

  • @pawlack
    @pawlack 2 года назад +5

    Next video - how I fixed and optimized CP2077 with python an pygame :)

  • @naitfis7237
    @naitfis7237 2 года назад

    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?

    • @jiangyi
      @jiangyi 2 года назад

      You can use something like pydroid3

  • @elijahbrown1437
    @elijahbrown1437 2 года назад

    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.

    • @DaFluffyPotato
      @DaFluffyPotato  2 года назад +3

      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.

  • @jackt9266
    @jackt9266 2 года назад +2

    This system in your next game jam relating to farming sims

  • @grapeswithnuts7643
    @grapeswithnuts7643 2 года назад +1

    amazing, i can finally touch grass without going outside

  • @kunsterman
    @kunsterman Год назад +2

    When was it so satisfying to put grass on the floor?

  • @jasondelong83
    @jasondelong83 10 месяцев назад

    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.

  • @Fireblats
    @Fireblats 2 года назад +9

    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

    • @farpurple
      @farpurple Год назад

      PyInstaller

    • @overratedprogrammer
      @overratedprogrammer Год назад +2

      Once I went AutoPy2Exe I never had to worry about anything

    • @Fireblats
      @Fireblats Год назад +2

      @@overratedprogrammer NECRONOMICON +3 int | +9 str
      year old comment joke aside...
      I'll check it out, thank you!

  • @hopokter780
    @hopokter780 2 года назад

    Great video

  • @falxie_
    @falxie_ 2 года назад

    This is incredibly impressive

  • @jbkhan1135
    @jbkhan1135 2 года назад

    dude that is amazing!

  • @Kevroa1
    @Kevroa1 2 года назад

    Have you considered using a quad tree for mapping the grass blades instead of your current system?

    • @DaFluffyPotato
      @DaFluffyPotato  2 года назад

      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.

  • @Fullrusher
    @Fullrusher 2 года назад +11

    I'm still struggling to learn pygame much less python lol fuck dude your a god at this , I love this language and engine

    • @zitronekoma30
      @zitronekoma30 2 года назад

      I can teach you if you want me to

  • @levijeske5164
    @levijeske5164 2 года назад +1

    Nice Video

  • @WashingtonFernandes
    @WashingtonFernandes 2 года назад +2

    gosh if i had a company i would want you as my employee xD

  • @smellyfrog2463
    @smellyfrog2463 2 года назад +3

    potat has blessed us with another very informative video

  • @smuthiahkarthik6509
    @smuthiahkarthik6509 2 года назад

    This video is greatr dude...

  • @electricimpulsetoprogramming
    @electricimpulsetoprogramming 2 года назад

    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?

    • @justsomeguy6545
      @justsomeguy6545 2 года назад

      I guess if you only moved the visual screen locally on their host device then mabey

    • @jackr.o.a.1759
      @jackr.o.a.1759 2 года назад

      @@justsomeguy6545 aka client side

  • @RPGAuthority
    @RPGAuthority 2 года назад +4

    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.

  • @user-jp3ug5od9b
    @user-jp3ug5od9b 2 года назад

    How intriguing..

  • @eboatwright_
    @eboatwright_ 2 года назад

    Super cool! :D

  • @MrKohlenstoff
    @MrKohlenstoff 2 года назад +4

    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. :)

    • @MrKohlenstoff
      @MrKohlenstoff 2 года назад

      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?

    • @DaFluffyPotato
      @DaFluffyPotato  2 года назад +1

      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.

    • @DaFluffyPotato
      @DaFluffyPotato  2 года назад +1

      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.

  • @basicallybrand
    @basicallybrand 2 года назад

    you are a pygame god

  • @Thawney
    @Thawney 2 года назад

    holy heck, all with just pygame WHAT

  • @shinyduck5324
    @shinyduck5324 2 года назад

    this is just cool :o

  • @crusaderanimation6967
    @crusaderanimation6967 2 года назад

    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.

  • @va9if
    @va9if 2 года назад

    thinking what if you were using a game engine - hope that devs will make a bit more unity performant pls

  • @user-zu1ix3yq2w
    @user-zu1ix3yq2w 2 года назад

    Hashmaps are underutilized. Take an anagram solver for example.

  • @CXZIO
    @CXZIO 2 года назад +2

  • @williamist
    @williamist Год назад

    it has been about a year. wonder if the source code will be released

  • @am5049
    @am5049 2 года назад

    You madman

  • @poggestfrog
    @poggestfrog 2 года назад

    As a stupid idiot I naturally thought the title was "I slammed 40k blades into grass with Pythons" LMAO

  • @Discosn8ke
    @Discosn8ke 2 года назад

    Thought warhammee. Im a dumbass. great vid.

  • @bencurtis777
    @bencurtis777 2 года назад

    Amaze balls!

  • @epycx
    @epycx 2 года назад

    Finally, I can touch grass

  • @ricj9594
    @ricj9594 2 года назад

    Só beautiful

  • @ilovedatfruitybooty9546
    @ilovedatfruitybooty9546 2 года назад +2

    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!!

    • @DaFluffyPotato
      @DaFluffyPotato  2 года назад +2

      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.

    • @ilovedatfruitybooty9546
      @ilovedatfruitybooty9546 2 года назад +1

      @@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?

    • @DaFluffyPotato
      @DaFluffyPotato  2 года назад +2

      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.

    • @jackbrowns469
      @jackbrowns469 2 года назад +2

      @@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.

    • @imadulting
      @imadulting 2 года назад

      @@DaFluffyPotato I mean, depends on the industry, if you are going into game dev certainly not.

  • @yssstuff2769
    @yssstuff2769 2 года назад +2

    cool... im stupid

  • @calebgilbertyt
    @calebgilbertyt 2 года назад +1

    how are you so smart? It's unreal!?!

    • @electricimpulsetoprogramming
      @electricimpulsetoprogramming 2 года назад +1

      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).

    • @Arcangel0723
      @Arcangel0723 2 года назад +5

      it is not unreal... it is pygaame!

  • @dandymcgee
    @dandymcgee 2 года назад +1

    Noice

  • @neonbeats9087
    @neonbeats9087 2 года назад

    Le fish

  • @corviscape
    @corviscape 2 года назад +2

    That's a lot of grass

  • @GGK1000
    @GGK1000 2 года назад

    That's hardcore

  • @pixelb00m
    @pixelb00m 2 года назад

    Wait hol up I know this guy

  • @hirzanabqary
    @hirzanabqary 2 года назад +3

    only 40000 blades of grass? omg pygame is so slow smh

  • @bity-bite
    @bity-bite 2 года назад

    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#.

    • @tah3460
      @tah3460 2 года назад +4

      C# is nowhere near as fast as C or C++...

    • @ralfwright
      @ralfwright 2 года назад +1

      Yeah idk where he gets "C# is faster" from. C++ is definitely faster.

  • @nateymatey
    @nateymatey 2 года назад +2

    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.

    • @TypicalPythonCoder
      @TypicalPythonCoder 3 месяца назад

      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

  • @tylerhunt7162
    @tylerhunt7162 2 года назад

    gt

  • @konradd8545
    @konradd8545 2 года назад

    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 🙂

  • @kevinpurrington3077
    @kevinpurrington3077 2 года назад +1